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.

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
ESP32 S3 - Controls Pump

Hardware Preparation

1×ESP32 S3 WROOM N16R8
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×Relay
1×12V Pump
1×Vinyl Tube
1×12V Power Adapter
1×Breadboard
1×Jumper Wires
1×Optionally, DC Power Jack

Or you can buy the following kits:

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 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.

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.

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!