Arduino UNO R4 - Control Fan

In this tutorial, we will learn how to control a 12V or 5V fan using Arduino UNO R4. In detail, we will learn:

Arduino UNO R4 fan

Hardware Preparation

1×Arduino UNO R4 WiFi
1×Arduino UNO R4 Minima (Alternatively)
1×USB Cable Type-C
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×(Recommended) Screw Terminal Block Shield for Arduino UNO R4
1×(Recommended) Breadboard Shield For Arduino UNO R4
1×(Recommended) Enclosure For Arduino UNO R4

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.
Additionally, some of these links are for products from our own brand, DIYables.

Overview of DC Fan

Pinout

A DC fan typically has two pins.

  • Negative (-) pin (black): connect to the negative wire of the DC power supply.
  • Positive (+) pin (red): connect to the positive wire of the DC power supply.
Fan Pinout
image source: diyables.io

Ensure that the voltage of the DC power supply matches the voltage required by the fan. In this guide, we will use fans that need 12VDC and 5VDC.

How to Control Fan

  • If a DC fan is powered by a 12V/5V power supply, it will run at full speed.
  • If a DC fan is powered by a 12V/5V PWM signal, you can control the fan's speed.

In this guide, we will learn how to switch a fan on and off using an Arduino UNO R4. We will cover how to control the fan speed in a different guide. To manage the fan, we use a relay between the Arduino UNO R4 and the fan. The Arduino UNO R4 controls the fan through the relay. If you are not familiar with relays (what they are, how they operate, how to program them), you can learn about them in the Arduino UNO R4 - Relay tutorial.

Wiring Diagram

The wiring diagram between Arduino UNO R4 Fan

This image is created using Fritzing. Click to enlarge image

Arduino UNO R4 Code

The following code continuously switches the fan ON for five seconds and then OFF for five resp.

/* * This Arduino UNO R4 code was developed by newbiely.com * * This Arduino UNO R4 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-controls-fan */ #define RELAY_PIN 3 // The Arduino UNO R4 pin connected to the IN pin of relay // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin as an output. pinMode(RELAY_PIN, OUTPUT); } // the loop function runs over and over again forever 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

Follow these instructions step by step:

  • If this is your first time using the Arduino Uno R4 WiFi/Minima, refer to the tutorial on setting up the environment for Arduino Uno R4 WiFi/Minima in the Arduino IDE.
  • Connect the Arduino Uno R4 to the fan according to the provided diagram.
  • Connect the Arduino Uno R4 to your computer using a USB cable.
  • Launch the Arduino IDE on your computer.
  • Select the appropriate Arduino Uno R4 board (e.g., Arduino Uno R4 WiFi) and COM port.
  • Copy and paste the provided code into the Arduino IDE.
  • Press the Upload button in the Arduino IDE to transfer the code to the Arduino UNO R4.
  • Observe the state of the fan.

Code Explanation

The explanation is in the comments of the above Arduino 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!