This project utilizes an ESP8266 (NodeMCU) to automatically control the speed of a DC fan based on ambient temperature readings from a DHT11 sensor. Real-time status updates, including current temperature and fan speed percentage, are displayed on a 0.96" OLED screen.
- Automatic Speed Control: Fan speed increases linearly as temperature rises (20°C to 35°C).
- Visual Feedback: OLED display shows real-time Temperature (°C) and Fan Speed (%).
- Safety Cutoff: Fan remains off below the minimum temperature threshold to save power.
- PWM Output: Uses Pulse Width Modulation for smooth fan speed transitions.
- Microcontroller: NodeMCU ESP8266 (ESP-12E)
- Sensor: DHT11 Temperature & Humidity Sensor
- Display: 0.96" I2C OLED Display (SSD1306 Driver)
- Actuator: 12V DC Fan
- Driver: MOSFET Module or Transistor (e.g., 2N2222/IRF540) to drive the fan
- Power: External power supply for the fan (if >5V)
| Component | NodeMCU Pin | Description |
|---|---|---|
| DHT11 Data | D4 (GPIO 2) | Temperature Data Signal |
| OLED SDA | D2 (GPIO 21) | I2C Data Line |
| OLED SCL | D1 (GPIO 22) | I2C Clock Line |
| Fan Signal | D5 (GPIO 14) | PWM Control Signal to MOSFET/Base |
| VCC | 3.3V / Vin | Power (Match component voltage) |
| GND | GND | Common Ground (Essential) |
- Install Arduino IDE: Download and install the latest version.
- Board Manager: Go to File > Preferences and add http://arduino.esp8266.com/stable/package\_esp8266com\_index.json. Then install esp8266 via the Board Manager.
- Install Libraries: Open the Library Manager (Sketch > Include Library > Manage Libraries) and install:
- Adafruit SSD1306
- Adafruit GFX
- DHT sensor library (by Adafruit)
- Upload Code: Open SmartFan.ino, select your Board (NodeMCU 1.0) and Port, and click Upload.
The system uses a linear mapping logic to determine fan speed:
- Below 15°C: Fan is OFF (0% speed).
- 15°C - 35°C: Fan speed scales linearly from 20% to 100%.
- Above 35°C: Fan runs at Maximum Speed (100%).
This project is open-source and available under the MIT License.