Community project

Arduino Fan Controller

Arduino
Photo of Arduino Fan Controller
Generated with AI

trịnh Quý

Published October 4, 2026

This Arduino Uno project creates a fan controller with environmental monitoring. The fan and indicator LED switch on and off in 5-second intervals, while a DHT11 temperature/humidity sensor and LM393 light sensor continuously monitor conditions and report readings to the Serial console. The fan is driven through an NPN transistor circuit with a protective diode, allowing the Arduino's digital pin to safely control the 5 V DC motor.

The guide provides a complete wiring diagram showing how to connect the transistor, diode, sensors, and fan to the Arduino, along with a full parts list and step-by-step assembly instructions. Upload the provided firmware to get started, then open the Serial monitor to watch real-time temperature, humidity, and light level data while the fan cycles automatically.

Wiring diagram

Wiring diagram for Arduino Fan Controller

Gather all the parts

QtyComponent
1

5 V DC Fan

A small 5 V two-wire fan that moves air when power is applied.

1

NPN Transistor (2N2222 / BC547)

General-purpose NPN bipolar junction transistor (BJT) in TO-92 package. Used as a low-side switch to drive loads (e.g. buzzers) whose current exceeds ESP32 GPIO source capability (~12 mA). A ~1 kΩ base resistor is placed between the ESP32 GPIO and the transistor base. The collector connects to the load negative terminal (buzzer –), and the emitter connects to GND. When the GPIO goes HIGH (3.3 V), the transistor saturates and switches the load on. Compatible with both 2N2222/2N2222A and BC547/BC547B variants. Add a flyback diode (e.g. 1N4148) across inductive load terminals.

1

1N4007 Diode

General-purpose silicon rectifier diode in DO-204AL (DO-41) axial through-hole package. Rated 1A average forward current and 1000V peak reverse voltage (VRRM). Forward voltage drop ~0.7V at typical load (up to 1.1V at full 1A). Used here in series with LM7805 Vout for reverse polarity protection: anode to LM7805 output, cathode to 5V rail, resulting in ~4.3V on the output rail. Not suitable for high-frequency switching (reverse recovery ~2µs–30µs); intended for DC or 50/60Hz rectification only.

1

5 V LED

A single indicator LED that lights when the Arduino enables the fan.

1

Resistor

220 Ω

Through-hole resistor (current-limiting in series with an LED)

1

Resistor

220 Ω

A 220 ohm resistor that safely limits the small control current from the Arduino to the transistor.

1

DHT11

Digital temperature and humidity sensor (lower accuracy than DHT22)

1

LM393 LDR Light Sensor Module

A ready-made light sensor board with an LDR and adjustable threshold; its AO pin provides a varying brightness level and its DO pin switches at the set threshold.

Assemble it in 6 steps

1. Place the Arduino and keep USB unplugged

Put the Arduino Uno beside the breadboard. Leave its USB cable unplugged while you make the wires, so a wrong connection cannot power the circuit.

  • Do not power the Arduino until you have checked the fan diode and all 5V and GND wires.

2. Keep the fan switch wiring

Keep the fan circuit already built: Arduino D9 goes through the 220 Ω base resistor to the 2N2222 base (control signal). The emitter goes to GND (ground), and the collector goes to the fan negative lead. Connect the fan positive lead to 5V (power). Put the 1N4007 across the fan: striped end to 5V and unstriped end to the fan negative/collector point (protects the transistor when the fan stops).

  • Check the 2N2222 package marking for its actual base, collector, and emitter leg order before inserting it.
  • The striped diode end must go to 5V; reversing it creates a short circuit when the fan is switched on.

3. Keep the indicator LED wiring

Keep Arduino D8 connected through its 220 Ω resistor to the LED long leg or positive input (light control). Connect the LED short leg or negative input to GND (ground).

  • Do not connect the LED directly to an Arduino pin without its 220 Ω resistor; too much current can damage the LED or Arduino pin.

4. Wire the DHT11 sensor

Connect DHT11 VCC to Arduino 3.3V (power), GND to Arduino GND (ground), and DATA to Arduino D2 (signal).

  • Most three-pin DHT11 modules already include the small pull-up resistor, so they only need VCC, GND, and DATA.
  • Make sure VCC and GND are not swapped — swapped power can damage the sensor.

5. Wire the light sensor module from the photo

Use the four-pin side labelled VCC, GND, DO, and AO. Connect VCC to Arduino 5V (power), GND to Arduino GND (ground), and AO to Arduino A0 (brightness signal). Leave DO unconnected; the program reads AO so it can show the full changing light level rather than only dark or bright.

  • The small blue screw adjusts when DO changes state, but it does not affect the AO connection used by this program.
  • The LDR is already fitted on this board, so do not add the old loose LDR or 10 kΩ resistor.

6. Check shared power and upload

Make sure every GND wire joins an Arduino GND pin. Recheck that D2 is only the DHT11 DATA wire and A0 is only the light module AO wire. Then plug the Uno into USB.

  • After deploying, open the Serial Monitor at 9600 baud to see light, temperature, and humidity readings every two seconds.

Review all connections

1. Connections between "fan_5v" and "Arduino"

Functionfan_5vArduino
powerFAN+5V
groundFAN- → NPN Transistor (2N2222 / BC547) COLLECTOREXT

2. Connections between "transistor_2n2222" and "Arduino"

Functiontransistor_2n2222Arduino
groundEMITTERGND

3. Connections between "base_resistor_1k" and "Arduino"

Functionbase_resistor_1kArduino
digitalP1GPIO 9
digitalP2 → NPN Transistor (2N2222 / BC547) BASEEXT

4. Connections between "flyback_1n4007" and "Arduino"

Functionflyback_1n4007Arduino
powerAnode → NPN Transistor (2N2222 / BC547) COLLECTOREXT
powerCathode5V

5. Connections between "led_resistor_220" and "Arduino"

Functionled_resistor_220Arduino
digitalP1GPIO 8
digitalP2 → 5 V LED Anode +EXT

6. Connections between "indicator_led" and "Arduino"

Functionindicator_ledArduino
groundCathode -GND

7. Connections between "dht11_1" and "Arduino"

Functiondht11_1Arduino
powerVCC3V3
groundGNDGND
dataDATAGPIO 2

8. Connections between "light_sensor_lm393" and "Arduino"

Functionlight_sensor_lm393Arduino
powerVCC5V
groundGNDGND
analogAOGPIO 14

Deploy the firmware

// Arduino Uno fan switch with an indicator LED, DHT11, and LM393 light sensor module.
// The fan and LED switch on for 5 seconds, then off for 5 seconds.
// Temperature, humidity, and light are read independently and printed to Serial.

#include <Arduino.h>
#include <DHT.h>

const uint8_t FAN_CONTROL_PIN = 9;
const uint8_t LED_PIN = 8;
const uint8_t DHT_PIN = 2;
const uint8_t LDR_PIN = A0;

const unsigned long SWITCH_INTERVAL_MS = 5000;
const unsigned long SENSOR_INTERVAL_MS = 2000;

DHT dht(DHT_PIN, DHT11);

bool outputOn = false;
unsigned long lastSwitchMs = 0;
unsigned long lastSensorMs = 0;

void setOutputs(bool turnOn) {
  digitalWrite(FAN_CONTROL_PIN, turnOn ? HIGH : LOW);
  digitalWrite(LED_PIN, turnOn ? HIGH : LOW);
}

void printSensorReadings() {
  float humidity = dht.readHumidity();
  float temperatureC = dht.readTemperature();
  int lightLevel = analogRead(LDR_PIN);

  Serial.print("Light sensor value (0-1023): ");
  Serial.println(lightLevel);

  if (isnan(humidity) || isnan(temperatureC)) {
    Serial.println("DHT11 reading failed. Check its power, ground, and DATA wire.");
    return;
  }

  Serial.print("Temperature: ");
  Serial.print(temperatureC, 1);
  Serial.println(" C");
  Serial.print("Humidity: ");
  Serial.print(humidity, 0);
  Serial.println(" %");
}

void setup() {
  pinMode(FAN_CONTROL_PIN, OUTPUT);
  pinMode(LED_PIN, OUTPUT);
  setOutputs(false);

  Serial.begin(9600);
  dht.begin();

  lastSwitchMs = millis();
  lastSensorMs = millis() - SENSOR_INTERVAL_MS;
}

void loop() {
  unsigned long now = millis();

  if (now - lastSwitchMs >= SWITCH_INTERVAL_MS) {
    lastSwitchMs = now;
    outputOn = !outputOn;
    setOutputs(outputOn);
  }

  if (now - lastSensorMs >= SENSOR_INTERVAL_MS) {
    lastSensorMs = now;
    printSensorReadings();
  }
}

Remix this project

Make it yours in one click

Open a full copy of this project in your own Schematik workspace — diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.

Open in Schematik