ESP32 S3 UNO - Control Pump

This ESP32 S3 Uno pump tutorial shows you how to wire a 12V water pump through a relay and turn it on and off with Arduino code. The ESP32 S3 Uno form board cannot drive the pump by itself, so the relay switches the pump's own 12V supply. You can use this idea for plant watering, an aquarium, or a water refill station.

In this tutorial, you will:

  1. Learn the pinout of a 12V water pump
  2. Wire a 12V pump and a relay module to the ESP32 S3 Uno
  3. Write Arduino code to turn the pump on and off
  4. Upload the code from Arduino IDE and test the pump
  5. Try a MOSFET module instead of the relay, so you can also change how fast the pump moves water

Why two ways? With a relay, the pump is either running or stopped. With a MOSFET module, you get the same ON and OFF, but you can also lower or raise the flow with PWM, and the switching makes no noise.

ESP32 S3 Uno pump

Overview of 12V Pump

A small 12V pump moves water through a vinyl tube when it gets power. It is easy to use, but it needs much more power than a board pin can give. Knowing its pins helps you wire it the right way.

Pinout

ESP32 S3 Uno Pump Pinout
image source: diyables.io

A 12V pump usually has just two pins. The black wire is the negative (-) pin, and it goes to GND of the DC power supply. The red wire is the positive (+) pin, and it goes to the 12V output of the power supply.

How to Control Pump

When you connect the pump to a 12V supply, it simply runs. To turn it on and off from code, you need a switch that the board can control.

Why use a relay

The ESP32 S3 Uno pins give only 3.3V and a small current, so they cannot run the pump. A relay sits between the board and the pump. The board sends a small signal to the relay, and the relay connects or cuts the pump's 12V power. If relays are new to you, read the ESP32 S3 Uno - Relay tutorial first. It explains the relay pinout, how it works, and how to program it.

Why use a MOSFET module

A MOSFET module is a quiet, electronic switch for DC loads. It can also send PWM to the pump. To see how the module works and how its terminals are wired, check the ESP32 S3 Uno - MOSFET Module guide.

Relay vs MOSFET Module for Pump

Relay MOSFET Module
Pump control ON and OFF ON and OFF, plus flow (pump speed) with PWM
Switching sound audible click none
How fast it switches slow, milliseconds very fast
Lifetime contacts slowly wear out no moving parts to wear
Pump type AC or DC pumps DC pumps only
Pump supply as the relay rating allows at least about 6V, so the gate turns on
Isolation from the ESP32 S3 Uno yes (coil and contacts) yes (PC817 optocoupler)
Pick it for AC pumps, simple ON/OFF DC pumps, flow control, frequent switching

For a 12V DC water pump, the MOSFET module gives you more: you can water plants gently instead of at full blast. The relay is still the right part for an AC (mains) pump.

ESP32 S3 Uno Pinout

The image below shows the pinout diagram of the ESP32 S3 Uno form board. Use it to find the Uno header pins (D3, 5V, GND…) and their GPIO numbers when you wire the pump circuit.

ESP32 S3 Uno pinout diagram

Wiring Diagram

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

The wiring diagram between ESP32 S3 Uno Pump

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 pump's red (+) wire. Connect the pump's black (-) wire to the negative wire of the power adapter.

WARNING

Never connect the 12V supply to the ESP32 S3 Uno pins. The 12V power must only go to the relay terminals and the pump. 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 pump 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.

/* * This ESP32 S3 Uno code was developed by newbiely.com * * This ESP32 S3 Uno code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3-uno/esp32-s3-uno-controls-pump */ // constants won't change const int RELAY_PIN = 17; // the ESP32 S3 Uno pin GPIO17 (D3), which connects to the IN pin of relay // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin GPIO17 (D3) as an output. pinMode(RELAY_PIN, OUTPUT); } // the loop function runs over and over again forever void loop() { digitalWrite(RELAY_PIN, HIGH); // turn on pump 5 seconds delay(5000); digitalWrite(RELAY_PIN, LOW); // turn off pump 5 seconds delay(5000); }

Detailed Instructions

Do these steps in order:

  1. New to the ESP32 S3 Uno? Follow ESP32 S3 Uno - Getting Started first.
  2. Wire it up as shown in the diagram.
  3. Connect the board to your computer with a USB Type-C cable.
  4. Open Arduino IDE, choose the ESP32S3 Dev Module board and the correct COM port.
  5. Copy the code above and paste it into Arduino IDE.
  6. Upload the code by clicking the Upload button.
  7. Put the pump in water and plug in the 12V power adapter.
  8. Watch the pump: it should pump water for five seconds, stop for five seconds, and repeat.
  9. Tip: do not run the pump dry for a long time. Most small pumps use the water to cool down, and running dry can damage them.

Code Explanation

The comments inside the code above explain each line. In short, pinMode() makes GPIO17 an output in setup(). Then loop() writes HIGH (pump on) and LOW (pump off), with a 5000 ms delay() between them.

How to Control Pump with MOSFET Module

The relay version works, but it can only give the pump full power. Below, the MOSFET module takes over, so the ESP32 S3 Uno can also run the pump at a lower flow.

Wiring Diagram

The wiring diagram between ESP32 S3 Uno water pump MOSFET module

This image is created using Fritzing. Click to enlarge image

MOSFET Module Pin Connect To
PWM ESP32 S3 Uno D9 (GPIO46)
GND ESP32 S3 Uno GND
+ 12V adapter + (through DC power jack) and pump red (+) wire
LOAD pump black (-) wire
− 12V adapter − (through DC power jack)

The pump motor is a coil, so add a 1N4007 or 1N5819 flyback diode across the pump wires, with the stripe (cathode) on the pump + side. This protects the module from voltage spikes.

※ NOTE THAT:

D9 (GPIO46) is a boot strapping pin. If uploading fails, remove the wire from D9, upload, then connect it again.

ESP32 S3 Uno Code

We use the code from the MOSFET module tutorial without any change. First the pump runs at full flow for 2 seconds and stops for 2 seconds. After that, its power climbs from 10% to 100% and falls back to 0% in 10% steps.

/* * This ESP32 S3 Uno code was developed by newbiely.com * * This ESP32 S3 Uno code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3-uno/esp32-s3-uno-controls-pump */ const int MOSFET_PIN = 46; // ESP32 S3 Uno pin D9 (GPIO46) connected to the PWM pin of the MOSFET module void setup() { Serial.begin(9600); pinMode(MOSFET_PIN, OUTPUT); analogWrite(MOSFET_PIN, 0); // start with the load OFF } void setLoad(int percent) { int duty = map(percent, 0, 100, 0, 255); // convert 0-100% to 0-255 analogWrite(MOSFET_PIN, duty); Serial.print("Load power: "); Serial.print(percent); Serial.println("%"); } void loop() { // turn the load fully ON, then fully OFF Serial.println("Load: ON"); setLoad(100); delay(2000); Serial.println("Load: OFF"); setLoad(0); delay(2000); // increase the power step by step (PWM) for (int percent = 10; percent <= 100; percent += 10) { setLoad(percent); delay(500); } // decrease the power step by step (PWM) for (int percent = 90; percent >= 0; percent -= 10) { setLoad(percent); delay(500); } delay(1000); }

Detailed Instructions

  1. Get the board and Arduino IDE ready, as described in the relay Quick Steps.
  2. Wire the pump to the MOSFET module as in the diagram.
  3. Upload the code, put the pump in water, then plug in the 12V adapter.
  4. Open the Serial Monitor at 9600 baud.
  5. Look at the water coming out of the tube: the stream gets stronger, then weaker. At very low power, a small pump may stop moving water.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32S3 Dev Module' on 'COM15')
New Line
9600 baud
Load: ON Load power: 100% Load: OFF Load power: 0% Load power: 10% Load power: 20% Load power: 30% Load power: 40% Load power: 50% Load power: 60% Load power: 70% Load power: 80% Load power: 90% Load power: 100% Load power: 90% Load power: 80% Load power: 70% Load power: 60% Load power: 50% Load power: 40% Load power: 30% Load power: 20% Load power: 10% Load power: 0%
Ln 11, Col 1
ESP32S3 Dev Module on COM15
2

Tip: use the MOSFET module with DC pumps only, and give it a supply of at least about 6V. An AC pump must stay on the relay.

Video Tutorial

Watch the video below to see this ESP32 S3 Uno project step by step.

Challenge Yourself

Try these ideas once the basic pump works:

  1. Build an automatic plant watering system with the ESP32 S3 Uno, a soil moisture sensor, and a pump.
  2. Make an automatic water refill system with the ESP32 S3 Uno, a water level sensor, and a pump.

FAQ

Can I connect a 12V pump directly to the ESP32 S3 Uno?

No. An ESP32 S3 Uno pin gives only 3.3V and a few milliamps. A 12V pump needs much more voltage and current. Use a relay or a MOSFET module with a separate 12V 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 pump speed with the ESP32 S3 Uno?

Not with a relay. A relay can only switch the pump fully on or off. To change the flow, use a PWM signal with analogWrite() and a MOSFET driver.

Why does my pump run when the code says LOW?

Some relay modules are active LOW. They turn on when the IN pin is LOW. In that case, swap HIGH and LOW in the code, or move the pump wire from the NO terminal to the NC terminal.

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 pumps or relays, GPIO35 to GPIO42 are a good choice. For a soil moisture or water level 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 pump does not run The 12V adapter is not plugged in or the pump is on the NC terminal Plug in the adapter and move the pump wire to the NO terminal
Pump works the opposite way to the code The relay module is active LOW Swap HIGH and LOW in the digitalWrite() lines
Pump runs but no water comes out Air in the tube or the pump inlet is not under water Put the pump fully in water and check that the tube is not bent
Board resets when the pump starts Pump and board share a weak supply Power the pump from its own 12V adapter and keep only the signal on the board

※ 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!