ESP32 S3 UNO - Control Fan
This ESP32 S3 Uno fan tutorial shows you how to turn a 12V or 5V DC cooling fan on and off with a relay. The ESP32 S3 Uno form board cannot power a fan directly, so a relay switches the fan's own power supply. You can use the same idea for a cooling fan in a box, a small air vent, or any DC fan project.
In this tutorial, you will:
- Learn the pinout of a DC cooling fan
- Wire a 12V fan and a relay module to the ESP32 S3 Uno
- Write Arduino code to turn the fan on and off
- Upload the code from Arduino IDE and test the fan

Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Overview of DC Fan
A DC fan is a simple part, but it needs more power than a board pin can give. Knowing its pins and voltage helps you wire it safely.
Pinout
Most small DC fans have only two wires. The black wire is the negative (-) pin and goes to the negative side of the DC power supply. The red wire is the positive (+) pin and goes to the positive side of the power supply.

Always match the power supply to the fan's rated voltage. This tutorial uses a 12V fan, and a 5V fan works the same way with a 5V supply.
How to Control Fan
There are two common ways to drive a DC fan. You can switch it fully on and off, or you can change its speed.
Full speed on/off
When the fan gets its full rated voltage (12V or 5V), it spins at full speed. Cutting the power stops it.
Speed control
When the fan gets a 12V or 5V PWM signal, you can change its speed. That topic is covered in a separate tutorial.
Why use a relay
In this tutorial, you only switch the fan on and off. The ESP32 S3 Uno pins give just 3.3V and a small current, so they cannot run the fan. A relay sits between the board and the fan. The board sends a small signal to the relay, and the relay connects or cuts the fan's own power supply. If relays are new to you, read the ESP32 S3 Uno relay guide first to learn how they work and how to program them.
ESP32 S3 Uno Pinout
The pinout diagram below shows the ESP32 S3 Uno form board. Use it to find the Uno header pins (D3, 5V, GND…) and their GPIO numbers while you wire the fan circuit.

Wiring Diagram
The relay input goes to D3 (GPIO17). The fan and the 12V power adapter connect through the relay's screw terminals.

This image is created using Fritzing. Click to enlarge image
| Component Pin | ESP32 S3 Uno Pin |
|---|---|
| Relay VCC | 5V |
| Relay GND | GND |
| Relay IN | D3 (GPIO17) |
On the high-power side, connect the positive wire of the 12V power adapter (through the DC power jack) to the relay COM terminal. Connect the relay NO terminal to the fan's red (+) wire. Connect the fan's black (-) wire to the negative wire of the power adapter.
WARNING
Never power the fan from the ESP32 S3 Uno pins. The 12V supply must only go to the relay terminals and the fan. The ESP32 S3 Uno pins work at 3.3V and are NOT 5V tolerant. The relay module may use 5V on its VCC pin, because its IN pin only receives a signal from the board.
ESP32 S3 Uno Code
This sketch turns the fan on for five seconds and then off for five seconds, again and again. It sets D3 (GPIO17) as an output and writes HIGH or LOW to it to switch the relay.
Detailed Instructions
Do these steps in order:
- New to the ESP32 S3 Uno? Follow ESP32 S3 Uno - Getting Started first.
- Wire it up as shown in the diagram.
- Connect the board to your computer with a USB Type-C cable.
- Open Arduino IDE, choose the ESP32S3 Dev Module board and the correct COM port.
- Copy the code above and paste it into Arduino IDE.
- Upload the code by clicking the Upload button.
- Plug in the 12V power adapter for the fan.
- Watch the fan: it should run for five seconds, stop for five seconds, and repeat.
- Tip: you should hear the relay click each time the fan changes state. If the fan works the opposite way, your relay module may be active LOW, so swap HIGH and LOW in the code.
Code Explanation
The comments inside the code above explain each line. In short, pinMode() makes GPIO17 an output in setup(), and loop() writes HIGH (fan on) and LOW (fan off) with a 5000 ms delay() between them.
Video Tutorial
Watch the video below to see this ESP32 S3 Uno project step by step.
FAQ
Can I connect a 12V fan directly to the ESP32 S3 Uno?
No. An ESP32 S3 Uno pin gives only 3.3V and a few milliamps. A 12V fan needs much more voltage and current. Use a relay or a transistor/MOSFET with its own power supply.
Can I power the relay module from the 3.3V pin of the ESP32 S3 Uno?
Most relay modules have a 5V coil, so power their VCC from the 5V pin. The IN pin can still take the 3.3V signal from the ESP32 S3 Uno on most modules. If your relay does not click, use a 3V relay module or a module with a transistor driver.
Can I control the fan speed with the ESP32 S3 Uno?
Not with a relay. A relay can only switch the fan fully on or off. To change the speed, use a PWM signal with analogWrite() and a MOSFET driver, or a 4-pin PWM fan.
Can I use a 5V fan instead of a 12V fan?
Yes. The wiring and code stay the same. Just use a 5V power supply for the fan on the relay side, so the voltage matches the fan.
What if my project needs more pins than the Uno headers give?
The ESP32 S3 Uno has two extra rows of holes with more GPIOs. GPIO15 and GPIO16 are I/O, PWM and analog. GPIO45 and GPIO35 to GPIO42 are I/O and PWM. GPIO47 and GPIO48 are output only, with PWM. Solder pin headers to use them and write the GPIO number in code. For more fans or relays, GPIO35 to GPIO42 are a good choice. For a temperature sensor, use GPIO15 or GPIO16. Be careful with two things. First, GPIO47 and GPIO48 may run at 1.8V instead of 3.3V on some modules (especially ones with "V" in the name, like R8V or R16V), so 3.3V devices can be damaged or act strangely. Second, GPIO0, GPIO3 (D6), GPIO45 and GPIO46 (D9) are boot strapping pins, and a wrong connection can stop the board from booting or uploading code. Use the other extra pins first.
Troubleshooting
| Problem | Possible Cause | Solution |
|---|---|---|
| No COM port in Arduino IDE | USB driver is missing or the cable is charge-only | Install the CP210x or CH340 driver, try a data USB cable, or hold BOOT while pressing RESET |
| Relay never clicks | Relay VCC or GND is not connected, or the relay needs 5V | Power the relay VCC from 5V and check the GND wire |
| Relay clicks but the fan does not spin | The 12V adapter is not plugged in or the fan is on the NC terminal | Plug in the adapter and move the fan wire to the NO terminal |
| Fan runs the opposite way to the code | The relay module is active LOW | Swap HIGH and LOW in the digitalWrite() lines |
| Fan spins slowly or stutters | The power supply voltage or current is too low | Use a supply that matches the fan voltage and has enough current |
| Board resets when the fan starts | Fan and board share a weak supply | Power the fan from its own adapter and keep only the signal on the board |