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:
- A circuit connecting the ESP32 S3, relay module, and 12V pump
- A sketch that toggles the pump on and off every 4 seconds
- Serial Monitor output confirming pump state in real time
- A foundation for aquarium, irrigation, or cocktail machine automation

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

The 12V pump has two wires for connection:
- Negative (-) wire (black): Connect to the negative terminal of the 12V DC power supply
- 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.

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.
Detailed Instructions
- New to ESP32 S3? Complete our Getting Started with ESP32 S3 guide first.
- Wire the relay, pump, and 12V power adapter following the wiring diagram above.
- Connect the ESP32 S3 to your computer using the USB Type-C cable.
- Open the Arduino IDE on your computer.
- Select ESP32S3 Dev Module (or your specific ESP32-S3 board variant) from the board menu, and choose the correct COM port.
- Copy the code above, paste it into Arduino IDE, and click the Upload button.
- Open the Serial Monitor (baud rate 115200) to watch the pump status messages.
- Observe the pump turning ON and OFF every 4 seconds automatically.
- 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:
Applications and Project Ideas
The ESP32 S3 pump control setup shown here forms the foundation for a wide range of practical automation projects.
- Automated Aquarium: Control water circulation and filtration systems on a timer to keep fish healthy without manual intervention.
- DIY Irrigation System: Water your plants automatically based on a schedule or soil moisture sensor readings.
- Coffee Machine Automation: Build a programmable espresso or drip coffee maker with precise timing control.
- Cocktail Dispenser: Create an automated bartender that dispenses drinks at the push of a button or via a web interface.
- Fountain Controller: Program decorative water fountain patterns and timing sequences for indoor or outdoor displays.
- 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.
- Beginner: Modify the code to change the ON/OFF timing intervals to 10 seconds each and observe the difference.
- Beginner: Add an LED indicator that lights up whenever the pump is running so you have a visual status signal.
- Intermediate: Add a push button to manually start and stop the pump independently of the automatic timer.
- Intermediate: Connect a soil moisture sensor and activate the pump only when the soil reading drops below a set threshold.
- Advanced: Create a web interface using the ESP32 S3's built-in WiFi to control the pump remotely from a phone or browser.
- Advanced: Build a complete multi-pump irrigation system where each pump runs on its own independent schedule stored in EEPROM.