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.

Hardware Preparation

1×Arduino Nano
1×USB A to Mini-B USB cable
1×Relay
1×12V DC Cooling Fan
1×(Alternative) 5V DC Cooling Fan
1×12V Power Adapter
1×DC Power Jack
1×Jumper Wires
1×(Optional) 9V Power Adapter for Arduino Nano
1×(Recommended) Screw Terminal Adapter for Arduino Nano

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you. We appreciate your support.

Overview of DC Fan

Pinout

Fan Pinout
image source: diyables.io

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.

Wiring Diagram

The wiring diagram between Arduino Nano and Fan

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.

/* * This Arduino Nano code was developed by newbiely.com * * This Arduino Nano code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano/arduino-nano-fan */ #define RELAY_PIN 2 // The Arduino Nano pin that controls the fan via relay module // The setup function runs once on reset or power-up void setup() { // initialize digital pin D2 as an output. pinMode(RELAY_PIN, OUTPUT); } // The loop function repeats indefinitely void loop() { digitalWrite(RELAY_PIN, HIGH); // turn on fan 5 seconds delay(5000); digitalWrite(RELAY_PIN, LOW); // turn off fan 5 seconds delay(5000); }

Detailed Instructions

  • 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.

Code Explanation

Check out the line-by-line explanation contained in the comments of the source code!

Video Tutorial

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!