Back to Projects
IntermediateArduino Uno R3
40 minutes build
Temperature-controlled fan
Combine a sensor, a decision and a motor driver into an automatic fan.
Interactive Simulation
Temperature-controlled fanarduino-uno
Required Components Checklist
Assembly Steps
1
Sensor
DHT11 data on pin 4, powered from 5V.
2
Driver
IN1 → pin 7, IN2 → pin 8, EN → pin 5 (PWM). Motor supply from a battery pack; share GND with the Uno.
3
Control law
Below 25 °C off; 25–35 °C maps to increasing speed; failed readings switch the fan off.
Arduino Sketch
#include <DHT.h>
DHT dht(4, DHT11);
const int IN1 = 7, IN2 = 8, EN = 5;
void setup() {
Serial.begin(9600);
dht.begin();
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(EN, OUTPUT);
digitalWrite(IN1, HIGH); // always spin the same way
digitalWrite(IN2, LOW);
}
void loop() {
float t = dht.readTemperature();
if (isnan(t)) {
Serial.println("Sensor error - fan off for safety");
analogWrite(EN, 0);
} else {
int speed = 0;
if (t >= 25) speed = map(constrain(t, 25, 35), 25, 35, 100, 255);
analogWrite(EN, speed);
Serial.print(t);
Serial.print(" C -> fan ");
Serial.println(speed);
}
delay(2000);
}
Challenges & Extensions
Ready to take this project further? Try these challenges:
- •Add a manual override button.
- •Show the speed on an LCD.
- •Use humidity too: speed up when it's humid.