ESP32 S3 - Control Pump

Learn how to control a 12V water pump with the ESP32 S3 using a relay module. This tutorial covers everything from wiring and code to automating pump control for your DIY projects.

You can drive the pump through a relay module or through a MOSFET module. The relay simply starts and stops the pump. The MOSFET module can start and stop it too, and on top of that it can change the pump speed, so you decide how much water flows. It also works silently. You will try both in this tutorial.

What you'll build:

  1. A circuit connecting the ESP32 S3, relay module, and 12V pump
  2. A sketch that toggles the pump on and off every 4 seconds
  3. Serial Monitor output confirming pump state in real time
  4. A foundation for aquarium, irrigation, or cocktail machine automation
  5. A MOSFET module circuit that raises and lowers the water flow with PWM
ESP32 S3 - Controls Pump

Overview of 12V Pump

A 12V pump is a compact electric water pump powered by 12V DC and widely used in DIY water circulation and automation projects. Its simple two-wire interface makes it straightforward to integrate with microcontrollers like the ESP32 S3 through a relay module.

Key Specifications

The pump operates at 12V DC with a typical power consumption of 3 to 5 watts. Flow rate varies by model but generally falls between 1 and 3 liters per minute, making it suitable for aquariums, irrigation systems, coffee machines, and automated beverage dispensers.

Pump Pinout

ESP32 S3 Pump Pinout
image source: diyables.io

The 12V pump has two wires for connection:

  1. Negative (-) wire (black): Connect to the negative terminal of the 12V DC power supply
  2. Positive (+) wire (red): Connect to the positive terminal of the 12V DC power supply

How to Control Pump using ESP32 S3

The ESP32 S3 controls the pump by switching its power circuit through a relay module. Because the pump requires 12V DC and the ESP32 S3 operates at 3.3V logic, it cannot power the pump directly. A relay acts as an electronically controlled switch: when the ESP32 S3 sends a HIGH signal on the control pin, the relay closes and allows 12V current to flow through the pump; when it sends LOW, the relay opens and the pump stops. This arrangement keeps the ESP32 S3 safely isolated from the high-voltage side. For more detail, see our ESP32 S3 - Relay tutorial.

Want to change the flow and not only switch the pump? Then use a MOSFET module. Its terminals, the PC817 inside, and PWM are all covered in our ESP32 S3 - MOSFET Module guide.

Comparing Relay and MOSFET Module for a Pump

Point Relay Module MOSFET Module
Pump control start / stop only start / stop, plus flow rate (PWM)
Sound audible click silent
Response milliseconds, slow almost instant
Lifespan metal contacts wear with use no moving parts inside
Works with AC and DC pumps DC pumps only
Pump supply any rated voltage 6V or more (the gate needs it)
Isolation yes (coil vs contacts) yes (PC817 optocoupler)
Best use AC pumps, simple ON/OFF 12V DC pumps, adjustable flow, frequent switching

For the 12V DC pump in this tutorial, both work. Choose the MOSFET module when you want a gentle flow, for example to water small plants. Choose the relay when your pump runs on AC.

Wiring Diagram between ESP32, Relay and Pump

Connect the ESP32 S3, relay module, and 12V pump following the diagram below. Always disconnect power before making or changing any connections, and double-check polarity on the pump and power adapter before applying voltage.

Safety Notes

The relay module separates the low-voltage ESP32 S3 circuit from the 12V pump circuit. Keep the 12V wiring on the relay terminal side well clear of the ESP32 S3 and breadboard area. Verify that the COM and NO terminals are used — never wire to NC for a pump-control setup.

The wiring diagram between ESP32 S3 Pump

This image is created using Fritzing. Click to enlarge image

ESP32 S3 Pin Relay Module Pin
D7 IN
GND GND
3.3V VCC
Relay Module Terminal Connection
COM 12V Power Adapter (+) Positive
NO Pump (+) Red Wire
Ground Connections Connection
12V Power Adapter (-) Pump (-) Black Wire

ESP32 S3 - Pump Code

The following code programs the ESP32 S3 to cycle the pump on and off automatically. It configures pin D7 as the relay control output, then repeatedly turns the pump on for 4 seconds and off for 4 seconds while printing the current state to the Serial Monitor. Each line of the sketch is annotated in the comments for easy reference.

/* * This ESP32 S3 code was developed by newbiely.com * * This ESP32 S3 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3/esp32-s3-controls-pump */ #define RELAY_PIN 7 // The ESP32 S3 pin connected to the pump the via the relay // The setup function runs once on reset or power-up void setup() { // initialize digital pin as an output. pinMode(RELAY_PIN, OUTPUT); } // The loop function repeats indefinitely void loop() { digitalWrite(RELAY_PIN, HIGH); // turn on pump 4 seconds delay(4000); digitalWrite(RELAY_PIN, LOW); // turn off pump 4 seconds delay(4000); }

Detailed Instructions

  1. New to ESP32 S3? Complete our Getting Started with ESP32 S3 guide first.
  2. Wire the relay, pump, and 12V power adapter following the wiring diagram above.
  3. Connect the ESP32 S3 to your computer using the USB Type-C cable.
  4. Open the Arduino IDE on your computer.
  5. Select ESP32S3 Dev Module (or your specific ESP32-S3 board variant) from the board menu, and choose the correct COM port.
  6. Copy the code above, paste it into Arduino IDE, and click the Upload button.
  7. Open the Serial Monitor (baud rate 115200) to watch the pump status messages.
  8. Observe the pump turning ON and OFF every 4 seconds automatically.
  9. Pro Tip: Use a clear vinyl tube so you can see water flowing the moment the pump activates, which makes debugging wiring issues much easier.

Line-by-line Code Explanation

The above ESP32 S3 code contains line-by-line explanation. Please read the comments in the code!

Serial Monitor Output

Open the Serial Monitor to see the pump control status in real time. With the 4-second cycle the output will look similar to the following:

∞
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
[2026-01-15 10:04:01] The pump is ON [2026-01-15 10:04:05] The pump is OFF [2026-01-15 10:04:09] The pump is ON [2026-01-15 10:04:13] The pump is OFF [2026-01-15 10:04:17] The pump is ON [2026-01-15 10:04:21] The pump is OFF
Ln 11, Col 1
ESP32S3 Dev Module on COM15
2

Applications and Project Ideas

The ESP32 S3 pump control setup shown here forms the foundation for a wide range of practical automation projects.

  1. Automated Aquarium: Control water circulation and filtration systems on a timer to keep fish healthy without manual intervention.
  2. DIY Irrigation System: Water your plants automatically based on a schedule or soil moisture sensor readings.
  3. Coffee Machine Automation: Build a programmable espresso or drip coffee maker with precise timing control.
  4. Cocktail Dispenser: Create an automated bartender that dispenses drinks at the push of a button or via a web interface.
  5. Fountain Controller: Program decorative water fountain patterns and timing sequences for indoor or outdoor displays.
  6. Hydroponic System: Manage nutrient solution circulation for indoor gardening with scheduled pump cycles.

How to Control Pump Flow with MOSFET Module

This section shows the MOSFET way. With PWM from the ESP32 S3, the pump can run fast, slow, or anywhere in between.

Wiring Diagram between ESP32 S3, MOSFET Module and Pump

The wiring diagram between ESP32 S3 pump MOSFET module

This image is created using Fritzing. Click to enlarge image

ESP32 S3 / Power MOSFET Module
GPIO47 PWM
GND GND
12V Power Adapter (+) +
Pump (+) Red Wire + (same screw as the adapter +)
Pump (-) Black Wire LOAD
12V Power Adapter (-) −

The pump motor is a coil, so add a 1N4007 or 1N5819 flyback diode across the pump wires, with the stripe (cathode) on pump +.

ESP32 S3 - Pump Flow Code

The pump first runs at full power for 2 seconds and then stops for 2 seconds. Next, its power climbs from 10% to 100% and falls back to 0%, so the water stream grows stronger and then weaker.

/* * This ESP32 S3 code was developed by newbiely.com * * This ESP32 S3 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3/esp32-s3-controls-pump */ const int MOSFET_PIN = 47; // ESP32 S3 GPIO47 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. Use the same board setup as in the relay Quick Steps above.
  2. Wire the MOSFET module, pump, and 12V adapter as shown. Put the pump in water first.
  3. Upload the code, then power the 12V adapter.
  4. Open the Serial Monitor at 9600 baud.
  5. Watch the water flow change along with the power value.
∞
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

Pro Tip: The MOSFET module only switches DC, and the pump supply should be at least about 6V. If your pump is an AC model, use the relay circuit above.

Video Tutorial

Watch the step-by-step video walkthrough for this ESP32 S3 project below.

Challenge Yourself

These challenges will help you build on the basic pump control sketch and develop more advanced automation skills.

  1. Beginner: Modify the code to change the ON/OFF timing intervals to 10 seconds each and observe the difference.
  2. Beginner: Add an LED indicator that lights up whenever the pump is running so you have a visual status signal.
  3. Intermediate: Add a push button to manually start and stop the pump independently of the automatic timer.
  4. Intermediate: Connect a soil moisture sensor and activate the pump only when the soil reading drops below a set threshold.
  5. Advanced: Create a web interface using the ESP32 S3's built-in WiFi to control the pump remotely from a phone or browser.
  6. Advanced: Build a complete multi-pump irrigation system where each pump runs on its own independent schedule stored in EEPROM.

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