IoT-Based Smart Fan Control Using ESP8266, DHT11 and KiwisIoT
by ananthi rk in Circuits > Electronics
18 Views, 0 Favorites, 0 Comments
IoT-Based Smart Fan Control Using ESP8266, DHT11 and KiwisIoT
- In this project, we will build an IoT-based Smart Fan Control System using an ESP8266 NodeMCU, a DHT11 temperature sensor, a relay module, a 5V DC fan, and the KiwisIoT platform.
- The system measures the surrounding temperature using the DHT11 sensor and sends the temperature readings to the KiwisIoT dashboard through Wi-Fi. The user can also turn the fan ON or OFF remotely using the dashboard.
- The ESP8266 acts as the main controller. It reads temperature data, communicates with the IoT platform, and controls the fan through a relay module.
- This project is suitable for beginners who want to learn about IoT, sensor interfacing, Wi-Fi communication, and remote device control.
Supplies
Components Required
- ESP8266 NodeMCU development board – 1
- DHT11 temperature sensor – 1
- 2-channel relay module – 1
- 5V DC fan – 1
- Suitable 5V DC power supply for the fan – 1
- Jumper wires – as required
- USB cable for programming the ESP8266 – 1
- Computer with Arduino IDE installed
- Wi-Fi connection
- KiwisIoT account and dashboard
How Does the Project Work?
The DHT11 sensor measures the temperature of the surrounding environment and sends the readings to the ESP8266 NodeMCU.
The ESP8266 connects to a Wi-Fi network and communicates with the KiwisIoT platform. Temperature readings are sent to Channel 0, where they are displayed on the dashboard.
Channel 1 is used to control the fan. When the user selects ON, the ESP8266 activates the relay, and the fan starts running. When the user selects OFF, the relay switches off and the fan stops.
Project Workflow
Temperature Monitoring:
DHT11 Sensor → ESP8266 NodeMCU → Wi-Fi → KiwisIoT Dashboard
Remote Fan Control:
KiwisIoT Dashboard → Wi-Fi → ESP8266 NodeMCU → Relay Module → 5V DC Fan
Understand the Components
ESP8266 NodeMCU
The ESP8266 NodeMCU is the main controller of this project. It reads temperature data from the DHT11 sensor, connects to Wi-Fi, communicates with KiwisIoT, and controls the relay module.
DHT11 Temperature Sensor
The DHT11 measures the surrounding temperature. The sensor's data pin is connected to the D5 pin of the ESP8266.
Relay Module
The relay works as an electrically controlled switch. It allows the low-voltage ESP8266 controller to switch the separate power supply to the fan.
This project uses Relay Channel 1, connected to the D1 pin of the ESP8266. The second relay channel is not used.
5V DC Fan
The fan provides airflow and is controlled by the relay. It receives power from a separate suitable 5V DC supply rather than directly from an ESP8266 GPIO pin.
KiwisIoT Platform
KiwisIoT provides the dashboard for displaying temperature readings and sending fan-control commands to the ESP8266.
Circuit Connections
Before connecting the components, disconnect the power supply.
A. DHT11 Sensor Connections
Connect the DHT11 sensor to the ESP8266 NodeMCU as follows:
- DHT11 VCC → ESP8266 3.3V
- DHT11 DATA → ESP8266 D5
- DHT11 GND → ESP8266 GND
If your DHT11 is a bare sensor rather than a breakout module, check its pinout and required pull-up resistor before connecting it.
B. Relay Module Connections
Connect the relay module as follows:
- Relay IN1 → ESP8266 D1
- Relay GND → ESP8266 GND
- Relay VCC → Suitable supply specified for the relay module
Use a relay module whose input is compatible with the ESP8266's 3.3V logic. Connect the controller ground and relay ground together when required by the module.
Only Relay Channel 1 is used.
C. 5V DC Fan Connections
Connect the fan through the relay contacts:
- 5V supply positive (+) → Relay COM
- Relay NO → Fan positive (+)
- Fan negative (−) → 5V supply negative (−)
COM means Common, while NO means Normally Open. With this arrangement, the fan normally remains OFF when the relay is not activated.
Important safety note: Do not power the fan directly from an ESP8266 GPIO pin. Use the correct power supply for the fan and relay module. This wiring is intended for a low-voltage 5V DC fan, not a household AC fan or mains-voltage circuit.
Install Arduino IDE and Required Libraries
We need the Arduino IDE to write and upload the program to the ESP8266 NodeMCU.
1. Install Arduino IDE
Download and install the Arduino IDE from the official Arduino website:
https://www.arduino.cc/en/software
2. Install ESP8266 Board Support
Open Arduino IDE and configure ESP8266 board support through Boards Manager.
Then select:
Tools → Board → ESP8266 Boards → NodeMCU 1.0 (ESP-12E Module)
Select the correct COM port under Tools → Port after connecting the board to the computer.
3. Install Required Libraries
Open:
Sketch → Include Library → Manage Libraries
Search for and install:
- DHT sensor library
- Adafruit Unified Sensor
- KiwisIoT library, using the installation method provided by the platform
These libraries are used to read the DHT11 sensor and communicate with the KiwisIoT platform.
Create the KiwisIoT Dashboard
Create or open your project dashboard on the KiwisIoT platform.
Configure two channels for this project.
Channel 0 – Temperature Monitoring
Use Channel 0 to display the temperature measured by the DHT11 sensor.
The ESP8266 sends the temperature value in degrees Celsius to this channel.
Example display:
- Temperature: 29.00 °C
- The displayed value will depend on the actual temperature around the sensor.
Channel 1 – Fan Control
Use Channel 1 as the fan-control input.
Configure a control that sends the appropriate values:
- ON = 1
- OFF = 0
When Channel 1 sends the value 1, the ESP8266 activates the relay. When it sends 0, the relay is deactivated.
Keep your KiwisIoT topic ID ready because it must be entered into the Arduino program.
Upload the Arduino Code
Code Explanation
1. Library declarations
The ESP8266 Wi-Fi, KiwisIoT, and DHT libraries are included at the beginning of the program.
2. Wi-Fi and dashboard settings
The Wi-Fi credentials allow the ESP8266 to connect to the network. The topic ID identifies the KiwisIoT dashboard or device topic used by the project.
3. Sensor initialization
The DHT11 data pin is configured as D5. The program reads the temperature using dht.readTemperature().
4. Temperature transmission
The sendTemperature() function reads the sensor, checks whether the reading is valid, and sends the value to Channel 0.
5. Fan control
The onControl() function checks incoming channel commands. Channel 1 controls the relay: the value 1 turns the fan ON, and the value 0 turns it OFF.
6. Main loop
The loop() function repeatedly runs KiwisIoT communication and sends a new temperature reading every two seconds.
Note: This program assumes an active-LOW relay module. Relay behavior varies between modules, so verify the ON/OFF logic with your specific relay before connecting the fan. The exact channel callback and dashboard configuration must also match your installed KiwisIoT library version.
Test the Smart Fan Control System
After uploading the program, follow these steps to test the project.
1. Check the Serial Monitor
Open Arduino IDE and select:
Tools → Serial Monitor
Set the baud rate to 115200.
Check whether the program starts and whether temperature readings appear.
Example output:
The values shown above are examples. Your output may differ depending on the sensor reading and library behavior.
2. Test Temperature Monitoring
Open the KiwisIoT dashboard and observe Channel 0.
The temperature displayed on the dashboard should correspond to the reading reported by the DHT11 sensor.
Allow a little time for the sensor to respond when the surrounding temperature changes.
3. Test Fan ON
Set Channel 1 to ON or send the value 1.
Expected behavior:
- The ESP8266 receives the control command.
- The relay activates.
- The 5V DC fan starts running.
- The Serial Monitor reports the received command.
Example:
4. Test Fan OFF
Set Channel 1 to OFF or send the value 0.
Expected behavior:
- The ESP8266 receives the OFF command.
- The relay deactivates.
- The fan stops running.
Example:
5. Verify Both Functions
Confirm that Channel 0 displays temperature and Channel 1 controls the fan independently.
Take photographs of the assembled circuit, Arduino Serial Monitor, and KiwisIoT dashboard for your project documentation.
Troubleshooting
Problem 1: Temperature Is Not Displayed
Possible causes:
- Incorrect DHT11 wiring.
- Incorrect sensor data pin.
- Missing DHT library.
- Loose jumper wires.
Solution: Check the VCC, DATA, and GND connections. Confirm that the code uses D5 for the sensor and verify the sensor's power requirements.
Problem 2: ESP8266 Does Not Connect to Wi-Fi
Possible causes:
- Incorrect Wi-Fi name or password.
- Unsupported Wi-Fi configuration.
- Weak signal.
Solution: Check the credentials and ensure the network provides compatible 2.4 GHz Wi-Fi access for the ESP8266.
Problem 3: Temperature Is Not Appearing on KiwisIoT
Possible causes:
- Incorrect topic ID.
- Dashboard channel mismatch.
- Network connection problems.
- Incorrect KiwisIoT library setup.
Solution: Verify the topic ID and Channel 0 configuration. Confirm that the ESP8266 can communicate with the platform.
Problem 4: Fan Does Not Turn ON or OFF
Possible causes:
- Incorrect relay wiring.
- Incorrect relay input pin.
- Unsupported relay logic.
- Insufficient or unsuitable power supply.
Solution: Verify the D1 connection, relay supply, common ground requirements, and relay contact wiring. Test the relay without the fan first and confirm whether it is active-LOW or active-HIGH.
Problem 5: ESP8266 Restarts When the Fan Starts
Possible causes:
- Unstable power supply.
- Electrical noise from the fan or relay.
- Incorrect grounding or wiring.
Solution: Use a suitable, stable power supply for the fan and relay. Check the wiring and keep the fan's current path separate from the ESP8266's GPIO power path.
Final Result
The IoT-based Smart Fan Control System demonstrates how a temperature sensor, ESP8266 NodeMCU, relay module, and IoT dashboard can work together.
The DHT11 measures the surrounding temperature and sends the readings to KiwisIoT through the ESP8266. The user can then operate the fan remotely through the dashboard.
The project combines temperature monitoring with remote switching and provides a foundation for learning more advanced IoT automation.
Conclusion
In this project, we built an IoT-based Smart Fan Control System using ESP8266 NodeMCU, a DHT11 temperature sensor, a relay module, a 5V DC fan, and KiwisIoT.
The system demonstrates temperature monitoring, Wi-Fi communication, dashboard integration, and remote fan control. It is a practical beginner-level project for understanding how IoT hardware and software work together.
By extending this design with automatic control and additional monitoring features, it can serve as a foundation for more advanced IoT automation systems.