Sunday, 13 July 2025

How to Control a DC Fan Using Arduino PWM (with Circuit Diagram)

Keywords: Arduino fan control, PWM, transistor, temperature fan control


How to Control a DC Fan Using Arduino PWM (with Circuit Diagram)

Controlling the speed of a DC fan is one of the most practical applications for beginners working with Arduino. Pulse Width Modulation (PWM) allows us to adjust the speed of a fan smoothly and efficiently without expensive hardware.

In this tutorial, you'll learn how to:

  • Use an Arduino to control a 2-wire DC fan

  • Apply PWM to change speed

  • Build the full circuit with a transistor and diode


What You'll Need

ComponentQuantity
Arduino Uno1
2-wire DC fan (5V–9V)1
NPN transistor (e.g. 2N2222 or BC547)1
1kΩ resistor (base resistor)1
Diode (1N4007 or 1N5819)1
Breadboard and jumper wires
External power supply (9V battery or adapter)1 (optional for 9V fans)

Circuit Diagram

Explanation:

  • The transistor acts as a switch. It receives a PWM signal from Arduino on its base through a 1kΩ resistor.

  • The diode is connected across the fan terminals in reverse bias to protect from voltage spikes (flyback diode).

  • The fan is powered from the 9V source (or Arduino 5V for smaller fans).


📄 Arduino Code

c++

int fanPin = 9; // Connects to the transistor base void setup() { pinMode(fanPin, OUTPUT); } void loop() { // Increase fan speed gradually for (int speed = 0; speed <= 255; speed += 5) { analogWrite(fanPin, speed); delay(100); } delay(2000);
// Decrease fan speed gradually
for (int speed = 255; speed >= 0; speed -= 5) { analogWrite(fanPin, speed); delay(100); } delay(2000); }

Tips:

  • Use analogWrite() to generate PWM on pins 3, 5, 6, 9, 10, or 11.

  • Don't power a 9V fan directly from Arduino — use an external source with a shared GND.

  • Don't power a 9V fan directly from Arduino — use an external source with a shared GND.


Conclusion

Using PWM with Arduino to control a fan is simple and educational. This same principle can be applied to control LEDs, motors, heaters, and more. For automatic control, you can even combine this with a temperature sensor like LM35 — which we’ll cover in a future tutorial.

No comments:

Post a Comment

Theory vs. Hands-On Experience: What Really Matters in Electrical Engineering?

  Introduction: The Ageless Debate In all workshops, classes, and web forums where engineers gather, one perennial question remains: Whi...