Temperature Controlled Fan MEDIUM

An automatic fan control system that adjusts fan speed based on ambient temperature. The system uses a temperature sensor to monitor heat and controls a DC fan accordingly.

Materials Used

Arduino Mega 2560 R3 (Elegoo)
DHT22 sensor (temperature & humidity)
16x2 LCD with potentiometer
L293D motor driver IC
3.6V–6V DC motor (fan)
MB102 Breadboard Power Supply (5V)
Breadboard
Jumper wires

Wiring Instructions

LCD: RS=7, E=8, D4-D7=9-12, GND=RW/VSS, 5V=VCC
DHT22: DATA=Pin 2, VCC=5V, GND=GND
L293D Motor: IN1=3, IN2=4, EN1=5 (PWM), Vcc1=5V, Vcc2=5V (motor supply)
Note: All grounds (Arduino + Power Supply + L293D) must be connected together

Project Photos & Demo

Temperature Fan Setup
Fritzing Diagram

Arduino Code

// Temperature Controlled Fan
const int tempPin = A0;
const int fanPin = 9;

void setup() {
  pinMode(fanPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int tempReading = analogRead(tempPin);
  float voltage = tempReading * (5.0 / 1023.0);
  float temperatureC = voltage * 100;

  Serial.print("Temperature: ");
  Serial.print(temperatureC);
  Serial.println(" C");

  int fanSpeed = 0;

  if (temperatureC < 25) {
    fanSpeed = 0;
  } else if (temperatureC < 30) {
    fanSpeed = 128;
  } else if (temperatureC < 35) {
    fanSpeed = 192;
  } else {
    fanSpeed = 255;
  }

  analogWrite(fanPin, fanSpeed);

  Serial.print("Fan Speed: ");
  Serial.println(fanSpeed);

  delay(1000);
}

🔧 Troubleshooting

Fan not responding to temperature? Check these solutions:

🌡️ Temperature Sensor Not Reading
  1. Verify DHT22 connections: DATA→Pin 2, VCC→5V, GND→GND.
  2. Install DHT sensor library: Sketch → Include Library → Manage Libraries → search "DHT sensor library".
  3. Check Serial Monitor output - if showing "Failed to read", sensor may be damaged or incorrectly wired.
  4. Ensure DHT sensor has proper pull-up resistor (4.7-10kΩ between DATA and VCC) - some modules have built-in resistors.
📏 Sensor Types:

DHT11 and DHT22 have different accuracy and pin configurations. Make sure DHTTYPE in code matches your physical sensor!

💨 Fan Not Spinning
  1. Check L293D motor driver connections: IN1→Pin 3, IN2→Pin 4, EN1→Pin 5 (PWM), both Vcc pins→5V.
  2. Ensure all grounds connected: Arduino GND, L293D GND, power supply GND must be common.
  3. Verify motor power supply (Vcc2 on L293D) is adequate - try external 5-9V supply.
  4. Test motor directly with 3-5V to confirm it works before debugging circuit.
🔌 Common Ground!

All grounds MUST be connected together. This is the #1 reason motor drivers fail. Check with multimeter that all GND points have continuity.

🎚️ Fan Speed Not Changing
  1. Verify PWM pin (Pin 5) is being used - only certain Arduino pins support analogWrite().
  2. Check temperature thresholds in code - adjust values to match your testing environment.
  3. Use Serial.println() to debug temperature readings and fanSpeed values in real-time.
  4. Ensure analogWrite() is called with correct pin and 0-255 value range.
🧪 Testing:

Lower temperature thresholds to 20/25/30°C for easier testing. Or gently warm the sensor with your hand to trigger speed changes.

What You Learned

Electrical Engineering Applications

This project demonstrates closed-loop feedback control systems, where sensor input directly influences actuator output. You learned about analog temperature sensing, PWM (Pulse Width Modulation) for motor speed control, voltage-to-temperature conversion, threshold-based control logic, and motor driver ICs for current amplification. These concepts are foundational in thermal management, power electronics, and automated control systems used throughout electrical engineering.

Broader Technology Context

Temperature-controlled fan systems are critical in computer cooling (CPU/GPU thermal management), HVAC systems, automotive engine cooling, data center climate control, industrial process control, and battery thermal management in electric vehicles. This feedback control architecture extends to thermostats, refrigeration systems, incubators, and any application requiring automatic temperature regulation. Understanding proportional control prepares you for advanced PID control in industrial automation.