ESP32 UNO - Control Pump
Want to move water on a schedule? An ESP32 Uno can start and stop a 12V pump through a relay, or set its flow with a MOSFET module. The ESP32 Uno form board only sends a small 3.3V signal, and the 12V water pump gets its power from its own adapter. Use it for plant irrigation, a fish tank top-up or a small refill station.
What you will do:
- Identify the two wires of a 12V water pump
- Wire a relay between the ESP32 Uno and the pump
- Upload Arduino code that switches the pump every 5 seconds
- Swap in a MOSFET module and change the pump speed with PWM

Components You Need
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 .
The 12V Water Pump
After this part, you know what each pump wire does and why a switch part is needed.
Pinout

| Pump Wire | Color | Goes To |
|---|---|---|
| Negative (-) | Black | GND (minus) of the 12V supply |
| Positive (+) | Red | 12V (plus) of the supply |
Good to know: the pump has no polarity marks on the body, so trust the wire colors.
Switching the Pump from Code
Give the pump 12V and it spins at once. To decide when it runs, put a switch part in its power path and let the ESP32 Uno drive that part.
| Switch Part | What the ESP32 Uno Does | Learn More |
|---|---|---|
| Relay | Sends HIGH or LOW to the IN pin; the contacts close or open the 12V line | ESP32 Uno - Relay |
| MOSFET module | Sends a PWM signal; the transistor passes more or less current | ESP32 Uno - MOSFET Module |
Good to know: one ESP32 Uno pin gives 3.3V and a few milliamps. That is far too weak for a motor, so never wire the pump straight to a pin.
Picking a Relay or a MOSFET Module
| Point | Relay | MOSFET Module |
|---|---|---|
| What you control | on or off | on, off and the flow level (PWM) |
| Noise | a click on every change | silent |
| Speed | a few milliseconds | near instant |
| Life span | contacts wear down over time | nothing moves, so nothing wears |
| Pump type | AC or DC | DC only |
| Supply voltage | up to the relay rating | about 6V or more |
| Signal isolation | yes | yes, through a PC817 optocoupler |
| Best use | AC pumps and plain switching | DC pumps with adjustable flow |
A tank that only needs to fill up works fine with the relay. For slow drip watering, or to fill a cup without a splash, take the MOSFET module. Any AC pump stays on the relay.
ESP32 Uno Pinout
Your sketch talks to GPIO numbers, not to the Uno labels printed on the ESP32 Uno form board. Find D3 and D9 in the diagram below and note their GPIO numbers first.

How to Connect the Relay and Pump
When this step is done, the relay sits between the board and the pump, and the 12V side is fully apart from the board.

This image is created using Fritzing. Click to enlarge image
| Component Pin | ESP32 Uno Pin |
|---|---|
| Relay VCC | 5V |
| Relay GND | GND |
| Relay IN | D3 (GPIO25) |
High-power side, in three wires:
| From | To |
|---|---|
| 12V adapter + (via DC power jack) | Relay COM |
| Relay NO | Pump red (+) |
| Pump black (-) | 12V adapter - (via DC power jack) |
Good to know: ESP32 Uno pins are 3.3V logic and NOT 5V tolerant. The relay only receives a signal from D3, so nothing at 5V or 12V ever flows back into the board.
WARNING
Keep the 12V adapter away from every ESP32 Uno header pin. Its wires go only to the relay screw terminals and the pump. A 12V touch on a GPIO destroys the chip.
ESP32 Uno Code
This sketch closes the relay for 5 seconds, opens it for 5 seconds, and repeats.
Upload and Test
- First time with this board? Set it up with ESP32 Uno - Getting Started before you continue.
- Build the circuit by following the wiring table above.
- Plug in the USB Type-C cable between the ESP32 Uno and your computer.
- Select the board in Arduino IDE: pick ESP32 Dev Module and the COM port of the board (CH340).
- Paste the sketch into an empty Arduino IDE window.
- Click Upload (Upload button) and wait for "Done uploading".
- Drop the pump into a water bowl, then plug in the 12V adapter.
- Check the cycle: the relay clicks, water flows for 5 seconds, then stops for 5 seconds.
- Pro tip: point the outlet tube back into the same bowl. You can then leave the test running for minutes with no mess and no refills.
Video Tutorial
See the ESP32 Uno build in action in the video below.
How the Code Works
| Code Part | What It Does |
|---|---|
| const int RELAY_PIN = 25 | Ties the relay IN pin to D3 (GPIO25) |
| pinMode(RELAY_PIN, OUTPUT) | Lets GPIO25 drive the relay |
| digitalWrite(RELAY_PIN, HIGH) | Closes the relay, the pump runs |
| digitalWrite(RELAY_PIN, LOW) | Opens the relay, the pump stops |
| delay(5000) | Holds each state for 5 seconds |
The result is a 10-second loop: half of it pumping, half of it resting.
ESP32 Uno vs UNO R4 for This Project
Moving this pump build from the UNO R4 to the ESP32 Uno changes the pin numbers and the signal level, and nothing else.
| Item | Arduino UNO R4 | ESP32 Uno |
|---|---|---|
| Logic voltage | 5V | 3.3V |
| Relay pin | D3 (3 in code) | D3 (25 in code) |
| MOSFET PWM pin | D9 (9 in code) | D9 (13 in code) |
| PWM call | analogWrite() | analogWrite() (same, 8-bit duty) |
| Wireless | WiFi on the R4 WiFi only | WiFi plus Bluetooth Classic and BLE |
| Arduino IDE board | Arduino UNO R4 WiFi or Minima | ESP32 Dev Module |
The same wiring works as-is, since the relay and the MOSFET module stay on the D3 and D9 headers. Only check that your relay module switches from a 3.3V input; if it does not, use a 3V relay module.
Flow Control with a MOSFET Module
At the end of this part, the ESP32 Uno sets the pump flow from 0% to 100%, not only on and off.
How to Connect the MOSFET Module

This image is created using Fritzing. Click to enlarge image
| Module Terminal | Wire It To |
|---|---|
| PWM | ESP32 Uno D9 (GPIO13) |
| GND | ESP32 Uno GND |
| + | 12V adapter + and pump red (+), shared |
| LOAD | Pump black (-) |
| * | 12V adapter - |
Good to know: the pump motor kicks back a voltage spike when it stops. Put a 1N4007 or 1N5819 diode across the pump wires, stripe (cathode) on the red + side, to protect the module.
ESP32 Uno Code
The sketch runs the pump at 100% for 2 seconds, stops it for 2 seconds, then ramps the flow up from 10% to 100% and back to 0% in half-second steps.
| Code Part | What It Does |
|---|---|
| const int MOSFET_PIN = 13 | Sends PWM out of D9 (GPIO13) |
| map(percent, 0, 100, 0, 255) | Turns a percent into an 8-bit duty value |
| analogWrite(MOSFET_PIN, duty) | Sets how long the MOSFET is on in each PWM cycle |
| for loops with 10% steps | Ramp the flow up, then down |
You see the stream grow and fade, and the Serial Monitor prints each level.
Upload and Test
- Prepare the board in Arduino IDE the same way as the relay steps above.
- Wire the pump and the MOSFET module by following the table. Keep the pump under water.
- Upload the sketch, then plug in the 12V adapter.
- Start the Serial Monitor and set it to 9600 baud.
- Watch the outlet tube: the jet gets stronger, then weaker. At the lowest levels, a small pump may hum without moving water.
- Pro tip: note the lowest percent where water still comes out. Use that number as the minimum in your own watering code.
※ NOTE THAT:
The MOSFET module switches DC only and needs a supply of about 6V or more. Keep a relay for any AC pump.
Go Wireless: Water Plants from Your Phone
At the end of this part, you know how to replace the fixed timer with buttons on your phone.
The ESP32 Uno has WiFi and Bluetooth built in. Put an ON/OFF switch on a phone page to start the pump through the relay on D3 (GPIO25). With the MOSFET module on D9 (GPIO13), a slider can set the flow level instead.
Try These Next
- Add a soil moisture sensor and run the pump only when the soil is dry.
- Add a water level sensor and stop refilling when the tank is full.
- Change the relay timing to 2 seconds on and 30 seconds off for a slow drip routine.
Troubleshooting
| Problem | Possible Cause | Solution |
|---|---|---|
| No COM port shows in Arduino IDE | CH340 driver missing or a charge-only cable | Install the CH340 driver and use a Type-C cable that carries data |
| Upload ends with "Failed to connect" or "Waiting for download" | Chip did not enter download mode | Hold the BOOT button while the upload starts, then release it |
| Relay stays silent | No 5V on relay VCC or GND not joined | Wire relay VCC to 5V and relay GND to an ESP32 Uno GND |
| Relay LED lights but no click | Module needs more than a 3.3V signal | Use a 3V relay module or one with a transistor input |
| Relay clicks but the pump is still | Adapter unplugged or pump wired to NC | Plug in the 12V adapter and move the red wire to NO |
| Pump runs when it should rest | Relay module is active LOW | Swap HIGH and LOW in the two digitalWrite() lines |
| Pump hums but no water flows | Air trapped or inlet above the water | Sink the whole pump and straighten the tube |
| Flow does not change with the MOSFET module | PWM wire on the wrong header or pin 9 left in code | Put PWM on D9 and use 13 in the sketch |
| ESP32 Uno restarts when the pump starts | Pump and board share a weak supply | Give the pump its own 12V adapter and add the flyback diode |
FAQ
Is it safe to run a 12V pump straight from an ESP32 Uno pin?
No. A pin gives 3.3V and only a few milliamps, while the pump needs 12V and hundreds of milliamps. Always put a relay or a MOSFET module in between, powered by a separate 12V adapter.
Which ESP32 Uno pin should I use for the relay?
This guide uses D3, which is GPIO25 in code. Any normal output pin works, but skip A2 to A5 (input only), D0 and D1 (USB serial), and be careful with D8, D10 and A0 (boot strapping pins).
Why does the code use 25 and 13 instead of 3 and 9?
The ESP32 Uno code needs GPIO numbers. The D3 header is GPIO25 and the D9 header is GPIO13. If you type 3, the sketch drives GPIO3, which is the USB serial receive line.
Does a 5V relay module work with the 3.3V signal of the ESP32 Uno?
Most do. The coil gets 5V from the VCC pin, and the IN pin only needs a logic HIGH. If the module LED turns on but the relay never clicks, buy a 3V relay module.
How can I make the pump push less water?
Use the MOSFET module and lower the percent in setLoad(). The relay cannot do this, because it only gives full power or none.
Does analogWrite() work on the ESP32 Uno?
Yes. With the current esp32 by Espressif Systems core, analogWrite() gives an 8-bit PWM signal on any output pin, so the MOSFET sketch runs with no extra library.
Can I run two pumps from one ESP32 Uno?
Yes. Give each pump its own relay or MOSFET module and its own output pin, for example D3 and D4. Check that the 12V adapter can supply the current of both pumps together.
Do I need a driver before the board shows up on my computer?
Yes, the ESP32 Uno uses a CH340 USB-to-serial chip. Install the CH340 driver once, and the COM port appears in Arduino IDE.
What if my project needs more pins than the Uno headers give?
The ESP32 Uno has a few extra holes near the power header: GPIO32 and GPIO33 (I/O, PWM, analog on ADC1, so they also work while WiFi is on) and GPIO15 (I/O, PWM, analog on ADC2). Solder pin headers to them and write the GPIO number in your code. For a soil moisture sensor in a WiFi watering project, GPIO32 or GPIO33 is the best choice. Two warnings: GPIO15 and GPIO0 (the IO0 pin at the unused Uno NC position) are boot strapping pins, and a wrong connection can stop the board from booting or uploading code, so use GPIO32/33 first. Never use the six holes under the digital header (SD0 to SD3, CMD, CLK = GPIO6 to GPIO11); they are wired to the flash chip and using them crashes the board.
Can I start the pump from my phone?
Yes. The ESP32 Uno has WiFi and Bluetooth, so a phone button or slider can replace the timer. The Go Wireless section above links the matching tutorials.