Arduino Nano - Fan
This tutorial instructs you how to use Arduino Nano to turn a fan on and off. Instructions on how to adjust the speed of the fan will be presented in a separate tutorial.
Or you can buy the following sensor kit:
|DIYables Sensor Kit 30 types, 69 units
Overview of DC Fan
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 will be teaching how to use Arduino Nano to turn a fan on and off. Controlling the fan's speed will be discussed in a different tutorial.
To control a fan on off, we need to utilize a relay between the Arduino Nano and the fan. The Arduino Nano can then use the relay to turn the fan on or off.
If you are unfamiliar with relay (pinout, functionality, programming, etc.), please refer to the Arduino Nano - Relay tutorial for more information.
This image is created using Fritzing. Click to enlarge image
Please note that if you use 5V fan, you need to use 5V power adapter. You MUST not use the Arduino's 5V pin to power fan because it cannot provide enough current for the fan.
Arduino Nano Code
The code below will cause the fan to turn on every five seconds and then off again after the same amount of time.
- Connect your Arduino Nano to your computer using a USB cable.
- Launch the Arduino IDE and select the appropriate board and port.
- Copy the code above and open it in the Arduino IDE.
- Click the Upload button in the Arduino IDE to send the code to the Arduino Nano.
- Check out the fan's state.
Check out the line-by-line explanation contained in the comments of the source code!