5.4.13 Project 7.1 Control the Fan
1. Description
In this project, we will learn how to make a small fan.
2. Component Knowledge
The small fan uses a 130 DC motor and safe fan blades. You can use PWM output to control the fan speed.

3. Control Method
Two pins are required to control the motor of the fan, one for INA and two for INB. The PWM value range is 0~255. When the PWM output of the two pins is different, the fan can rotate.
INA - INB <= -45 |
Rotate clockwise |
|---|---|
INA - INB >= 45 |
Rotate anticlockwise |
INA == 0, INB == 0 |
Stop |
4. Control Pins
INA |
19 |
|---|---|
INB |
18 |
5. Test Code
#define fanPin1 19
#define fanPin2 18
void setup() {
pinMode(fanPin1, OUTPUT);
pinMode(fanPin2, OUTPUT);
}
void loop() {
digitalWrite(fanPin1, LOW); //pwm = 0
analogWrite(fanPin2, 180);
delay(3000);
digitalWrite(fanPin1, LOW);
digitalWrite(fanPin2, LOW);
delay(1000);
digitalWrite(fanPin1, HIGH); //pwm = 255
analogWrite(fanPin2, 210);
delay(3000);
digitalWrite(fanPin1, LOW);
digitalWrite(fanPin2, LOW);
delay(1000);
}
6. Test Result
The fan will rotate clockwise and anticlockwise at different speeds.