Arduino Nano 33 IoT - Control Fan

This guide explains how to use the Arduino Nano 33 IoT board to control a fan.

Arduino Nano 33 IoT controls Fan

Hardware Preparation

1×Arduino Nano 33 IoT
1×Micro USB Cable
1×Relay
1×12V DC Cooling Fan
1×Alternatively, 5V DC Cooling Fan
1×12V Power Adapter
1×Breadboard
1×Jumper Wires
1×Optionally, DC Power Jack
1×Recommended: Screw Terminal Expansion Board for Arduino Nano
1×Recommended: Breakout Expansion Board for Arduino Nano
1×Recommended: Power Splitter 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.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of DC Fan

Pinout

Fan Pinout
image source: diyables.io

A DC fan normally has two pins:

  • Negative pin (black): Connect this to the negative wire of the DC power supply.
  • Positive pin (red): Connect this to the positive wire of the DC power supply.

The DC power supply's voltage must be the same as what the fan needs. In this lesson, we will use fans that operate on 12VDC and 5VDC.

How to Control Fan

  • When a DC fan gets power from a 12V/5V power supply, it runs at full speed.
  • When a DC fan gets a 12V/5V PWM signal, you can control its speed.

This guide shows you how to use the Arduino Nano 33 IoT to turn a fan on and off. Another guide will explain how to control the fan’s speed.

Since the fan uses high voltage, you cannot hook it up directly to the Arduino Nano 33 IoT. Instead, you need to connect the fan to the Arduino through a relay. We have detailed guides about relays—including wiring, operation, and programming—in our Arduino Nano 33 IoT - Relay tutorial.

Wiring Diagram

The wiring diagram between Arduino Nano and 33 IoT Fan

This image is created using Fritzing. Click to enlarge image

Remember, if you use a fan that runs on 5V, you should use a 5V power adapter.

Arduino Nano 33 IoT Code

The code below switches the fan on and off every 10 seconds.

/* * This Arduino Nano 33 IoT code was developed by newbiely.com * * This Arduino Nano 33 IoT code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-iot/arduino-nano-33-iot-controls-fan */ #define RELAY_PIN 2 // The Arduino Nano 33 IoT pin connected to the fan the via the relay // 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 10 seconds delay(10000); digitalWrite(RELAY_PIN, LOW); // turn off fan 10 seconds delay(10000); }

Detailed Instructions

If you are new to the Arduino Nano 33 IoT, be sure to check out our Getting Started with Arduino Nano 33 IoT tutorial. Then, follow these steps:

  • Connect the components to the Arduino Nano 33 IoT board as depicted in the diagram.
  • Use a USB cable to connect the Arduino Nano 33 IoT board to your computer.
  • Launch the Arduino IDE on your computer.
  • Select the Arduino Nano 33 IoT board and choose its corresponding COM port.
  • Copy the code above and paste it into the Arduino IDE.
  • Click the Upload button in the Arduino IDE to compile and send the code to your Arduino Nano 33 IoT board.
  • Check the fan's status.

Line-by-line Code Explanation

The Arduino Nano 33 IoT code above explains every line. Please read all the comments in the 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!