This project is an open-source system designed to control multiple 12V PWM fans based on temperature readings from DS18B20 sensors. It uses an ESP32 microcontroller and supports MQTT over Wi-Fi to report sensor data and fan speeds. The system ensures continuous operation even when Wi-Fi or MQTT connections fail.
- Fan Control: Adjusts fan speed based on temperature ranges.
- Temperature Monitoring: Supports multiple DS18B20 sensors on a single pin.
- MQTT Integration: Reports fan speed and temperature data over MQTT.
- Fail-Safe Operation: Maintains functionality if Wi-Fi or MQTT connectivity is lost.
- Configurable Parameters: User-configurable temperature thresholds, PWM frequency, and more.
Important
This sketch is not compatible with ESP8266 due to the use of the ESP32-specific LEDC API for PWM control. The ESP8266 is not suitable for fans requiring high PWM frequencies above 1kHz, as it lacks support for higher PWM rates.
This project is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0).
- ESP32 Microcontroller
- DS18B20 Temperature Sensors (1 or more)
- 12V PWM Fans (used Arctic S12038-4K requiring 25kHZ PWM frequency)
- 12V Power Supply
- Resistors and jumper wires for connections
- Arduino IDE
- ESP32 Board Manager (Version 3.0.7)
- Arduino Libraries:
WiFi
PubSubClient
OneWire
DallasTemperature
- Clone or download this repository.
- Open the provided
.ino
file in the Arduino IDE. - Install the required libraries from the Arduino Library Manager.
- Configure the following user variables in the
USER CONFIGURATION SECTION
:- Wi-Fi credentials (
ssid
andpassword
) - MQTT broker information (
mqtt_server
,mqtt_port
, etc.) - Number of sensors and fans (
NUM_SENSORS
,NUM_FANS
) - Temperature thresholds (
MIN_TEMP
,MAX_TEMP
) - PWM frequency (
PWM_FREQUENCY
)
- Wi-Fi credentials (
- Connect the hardware as per the pin definitions in the code.
- Upload the code to your ESP32.
- The system will automatically adjust fan speed based on temperature readings.
- Monitor the fan speeds and temperatures via the MQTT broker.
- If the Wi-Fi connection fails, the system will continue to adjust fans based on sensor readings.
- Additional Fans and Sensors: Update
NUM_SENSORS
andNUM_FANS
variables and configure the corresponding GPIO pins. - PWM Frequency: Modify the
PWM_FREQUENCY
variable to match your fan requirements. - Temperature Thresholds: Adjust
MIN_TEMP
andMAX_TEMP
to suit your cooling needs.
- If you get temperature readings of -127°C, ensure the DS18B20 sensors are connected with an appropriate pull-up resistor. The build-in resistor might not be sufficient, add a 5kΩ resistor to pull up the the pin to 3V3.
- Verify the MQTT broker details.
- Check serial monitor output for debugging information.
Claude Wolter
Feel free to contribute to this project by submitting issues or pull requests.
This project is for non-commercial use only. Please adhere to the licensing terms.