Arduino - Control Fan
Arduino can not only turn on/off the fan but also control the fan's speed.
In this tutorial, we are going to learn how to turn on/off a fan using Arduino. Controlling the fan's speed will be presented in another tutorial.
Hardware Required
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some links direct to products from our own brand, DIYables.
About DC Fan
Pinout
A DC fan usually has two pins:
- Negative (-) pin (black): needs to be connected to the negative wire of DC power supply
- Positive (+) pin (red): needs to be connected to the positive wire of DC power supply
The voltage of the DC power supply should be equal to the voltage specified by the fan. In this tutorial, we will use 12VDC and 5VDC fans.
How to Control Fan
- If DC fan is powered by 12V/5V power supply, it run with full speed.
- If DC fan is powered by 12V/5V PWM signal, The fan's speed can be controlled.
In this tutorial, we are going to learn how to turn on/off a fan using Arduino. Controlling the fan's speed will be presented in another tutorial. To turn on/off a fan, we need to use a relay in between Arduino and fan. Arduino can turn on/off the fan via the relay. If you do not know about relay (pinout, how it works, how to program ...), learn about relay in the Arduino - Relay tutorial
Wiring Diagram
This image is created using Fritzing. Click to enlarge image
Arduino Code
The below code repeatedly turns the fan ON in five seconds and OFF in five seconds,
Quick Steps
- Connect Arduino to PC via USB cable
- Open Arduino IDE, select the right board and port
- Copy the above code and open with Arduino IDE
- Click Upload button on Arduino IDE to upload code to Arduino
- See the fan's state
Code Explanation
Read the line-by-line explanation in comment lines of code!
Video Tutorial
We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.