The Temperature-Based Fan Control project teaches you how to build an intelligent cooling system that automatically adjusts fan speed based on environmental temperature: responding to heat changes in real-time.
In this project, a DHT11 temperature sensor continuously monitors the air temperature. Arduino reads the temperature and automatically controls a DC fan motor speed using PWM signals. As temperature increases, fan speed increases. As temperature decreases, fan speed decreases.
When the environment is cool, the fan runs slowly or remains off, conserving energy. As temperature rises, the fan gradually speeds up. At high temperatures, the fan runs at full speed to provide maximum cooling. When temperature drops again, the fan automatically reduces speed, creating an adaptive cooling system.
This project teaches Temperature Sensing, PWM Motor Control, Proportional System Response, Fan Speed Modulation, and Smart Temperature Regulation.
By finishing this project, you’ll understand how HVAC systems work in homes, how computer cooling systems respond to CPU temperature, and how smart thermal management systems maintain optimal conditions.
To build this circuit, collect these specific items from your kit:
Arduino Uno × 1, Breadboard × 1, DHT11 Temperature Sensor × 1, DC Motor (Fan) × 1, Motor Driver Module (L298N) × 1, 10kΩ Resistor × 1, Jumper Wires × 8, USB Cable × 1, Power Supply (if needed)
Connect the Arduino GND pin to the negative rail of the breadboard. This creates a shared ground connection for all components.
Connect the VCC pin of the DHT11 temperature sensor to Arduino 5V. This provides power to the temperature measurement module.
Connect the GND pin of the DHT11 to the breadboard GND rail. This completes the power circuit for the sensor..
Connect the DATA pin of the DHT11 to Arduino Pin 7. This pin receives temperature and humidity data from the sensor.
Connect one end of the 10kΩ resistor to Arduino Pin 7 and the other end to Arduino 5V. This stabilizes the DHT11 data signal.
Connect the VCC pin of the L298N motor driver to Arduino 5V. This provides power to the motor control module.
Connect the GND pin of the motor driver to the breadboard GND rail. This completes the power circuit for the motor driver.
Connect the ENA (PWM enable) pin of the motor driver to Arduino Pin 9. This pin controls the fan motor speed with PWM signals.
Connect the IN1 pin of the motor driver to Arduino Pin 8. Connect the IN2 pin to the breadboard GND rail. These pins control motor direction.
Connect the positive terminal of the DC fan motor to OUT1 of the motor driver. Connect the negative terminal to OUT2 of the motor driver.
Check all sensor and motor driver connections before uploading your code. Ensure the fan motor is securely connected to the motor driver outputs.
Important: The motor driver protects Arduino from high current motor loads. The PWM signal on Pin 9 controls the voltage delivered to the motor, which determines fan speed.
In setup(), Arduino initializes the DHT11 library and sets the sensor data pin to Pin 7. Pin 9 is configured as OUTPUT for PWM motor control. Pin 8 is set as OUTPUT for motor direction control.
Inside loop(), Arduino reads the current temperature using dht.readTemperature(). This function retrieves the temperature value in degrees Celsius from the DHT11 sensor.
The temperature value is mapped to a PWM speed value between 0 and 255. Lower temperatures map to lower PWM values (slower fan), while higher temperatures map to higher PWM values (faster fan).
The temperature reading and current fan speed are printed to the Serial Monitor. This allows users to monitor the system operation and verify that the fan responds appropriately to temperature changes.
After uploading your code, here is what happens.
At startup, the Serial Monitor displays the current temperature. If temperature is below the base threshold, the fan runs slowly or remains off. As room temperature increases, the fan gradually speeds up. When temperature reaches high levels, the fan runs at full speed providing maximum cooling. As room temperature decreases, the fan automatically reduces speed. You can test by placing a heat source near the DHT11 sensor and watching the fan speed increase in response. Removing the heat source causes the fan to slow down automatically.
Fan Does Not Spin :- Verify that Pin 9 connects to the ENA pin and Pin 8 connects to IN1. Check that the motor driver receives proper power. Test the fan manually to ensure it works. Check for blockages preventing the fan from spinning.
Fan Runs Only at Full Speed :- Verify the PWM signal is working by checking different analogWrite() values. Check that the motor driver is receiving varying voltage from the PWM signal. Test with a simple PWM test sketch.
Temperature Reading Does Not Display :- Verify the DHT11 connection to Pin 7 and check the pull-up resistor. Ensure the DHT11 library is installed and imported correctly. Try a simple DHT11 test sketch to verify sensor operation.
Fan Speed Does Not Change with Temperature :- Adjust the temperature thresholds and speed mapping values in your code. Verify the temperature sensor is responding to temperature changes. Check the motor driver PWM input for signal variations.
Motor Driver Becomes Hot :- Ensure the motor driver is properly ventilated and has adequate cooling. Check for short circuits in the motor connections. Verify that the motor specifications match the motor driver capabilities.
By finishing this project, you now know :-
How temperature sensors provide analog readings, how motor drivers control DC motors safely, how PWM signals regulate motor speed, how to create proportional control systems, and how to build smart thermal management applications.
In Day 22, you’ll learn how to use a Relay Control Project to safely switch high-voltage appliances, controlling powerful devices using low-voltage Arduino signals.