মূল বিষয়বস্তুতে যান
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
Open in Lab
UNOATmega328P: The 8-bit AVR microcontroller that runs your sketch (16 MHz, 32 KB flash, 2 KB RAM).ATmega328PUSB-B: USB connection for uploading sketches and for the Serial Monitor. Also powers the board (5 V).DC jack: Barrel jack for 7–12 V from a battery pack or adapter (centre positive).ATmega16U2: Converts USB to serial for uploads and Serial.print().RESET: Restarts your sketch from the beginning (setup() runs again).L (D13): Built-in LED connected to pin 13 (LED_BUILTIN).ON: Power indicator.5 V regulator: Turns 7–12 V from VIN/jack into a steady 5 V.16 MHz: Clock source: the microcontroller runs 16 million cycles per second.ICSP: In-circuit programming header (SPI). Used to burn a bootloader; not needed for normal uploads.30°C · 50%DRIVERstop

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.