ESP32 S3 UNO - Water/Liquid Valve
This ESP32 S3 Uno water valve tutorial shows you how to open and close a 12V solenoid valve with Arduino code. You will connect the liquid solenoid valve to the ESP32 S3 Uno form board through a relay. Then you can control the water flow of water, beer, oil or other liquids from your sketch.
In this tutorial, you will:
- Learn how a liquid solenoid valve opens and closes
- Wire a water solenoid valve and a relay to the ESP32 S3 Uno
- Power the valve from a separate 12V adapter
- Write Arduino code that opens and closes the valve on a timer

Hardware Preparation
| 1 | × | ESP32 S3 Uno-form Board | |
| 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 | × | Liquid Solenoid Valve | |
| 1 | × | 12V Power Adapter | |
| 1 | × | DC Power Jack | |
| 1 | × | Jumper Wires |
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 Water/Liquid Valve
A solenoid valve is an electric tap. It lets you start and stop a liquid flow without touching anything. Knowing its two wires and how it reacts to power makes the wiring much easier.
Pinout

The valve has only two wires. The positive (+) wire is usually red, and it goes to the 12V side of the DC power supply. The negative (-) wire is black or another color, and it goes to the GND of the same DC power supply.
How Water/Liquid Valve works
By default, the valve stays closed. When you apply 12V DC across its two wires, the coil pulls the valve open and the liquid can pass. When you remove the 12V, the valve closes again.
※ NOTE THAT:
Some valves have a rubber gasket inside. They need a small minimum pressure, besides the 12V, before they open. The flowing liquid usually gives this pressure. Also, many valves let liquid pass in one direction only, so check the arrow on the valve body.
How to Control Water/Liquid Solenoid Valve
The valve needs 12V, but an ESP32 S3 Uno pin gives only 3.3V and a few milliamps. So you put a relay between the board and the valve. The ESP32 S3 Uno switches the relay, and the relay switches the 12V to the valve.
If relays are new to you, read the ESP32 S3 Uno - Relay tutorial first. It explains the relay pins, its trigger modes and the basic code.
ESP32 S3 Uno Pinout
The image below shows the pinout diagram of the ESP32 S3 Uno form board. Use it to find the D3 header and its GPIO number when you wire the relay.

Wiring Diagram
The relay input side connects to the ESP32 S3 Uno. The valve connects to the relay output together with its own 12V power adapter.

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) |
※ NOTE THAT:
The valve wires never touch the ESP32 S3 Uno. The 12V adapter, the relay output (COM and NO) and the valve form their own loop. Most relay modules accept a 3.3V signal on the IN pin; if yours does not switch, use a relay module made for 3.3V logic.
ESP32 S3 Uno Code
This sketch opens the water valve for five seconds, then closes it for five seconds, and repeats forever. It drives the relay on GPIO17 (D3) with digitalWrite().
Detailed Instructions
Follow these steps one by one:
- New to the ESP32 S3 Uno? Follow ESP32 S3 Uno - Getting Started first.
- Wire it up as shown in the diagram.
- Connect the board to your computer with a USB Type-C cable.
- Open Arduino IDE, choose the ESP32S3 Dev Module board and the correct COM port.
- Copy the code above and paste it into the Arduino IDE.
- Upload the code by clicking the Upload button.
- Plug in the 12V adapter for the valve.
- Watch the water flow: it should run for five seconds, then stop for five seconds.
- Tip: Test with a bucket or a sink first, so a leak does not reach your board.
Code Explanation
The sketch is short, and the comments inside the code explain each line. In setup(), the relay pin becomes an output. In loop(), the pin goes HIGH to open the valve and LOW to close it, with a 5-second delay after each step.
Video Tutorial
Watch the video below to see this ESP32 S3 Uno project step by step.
FAQ
Can the ESP32 S3 Uno power the solenoid valve directly?
No. The valve needs 12V and a lot more current than a GPIO pin can give. Always use a relay (or a MOSFET module) and a separate 12V adapter. Connecting the valve to a pin can damage the ESP32 S3 Uno.
Will a 5V relay module work with the 3.3V ESP32 S3 Uno pins?
Most 5V relay modules have a transistor or optocoupler input, and they switch fine with a 3.3V HIGH signal. Power the module from the 5V pin and connect IN to D3 (GPIO17). If the relay clicks weakly or not at all, pick a relay module rated for 3.3V logic.
Why does my valve not open even when the relay clicks?
Some valves need a minimum water pressure to open, because of the gasket inside. Without pressure, the valve may stay shut. Also check that the flow follows the arrow on the valve body and that the 12V adapter gives enough current.
Do I need a flyback diode for the valve?
The valve is a coil, so it makes a voltage spike when it turns off. Many relay modules handle this fine, but a diode across the valve wires (cathode to +12V) protects the relay contacts and reduces noise. It is a good idea for long-running projects.
What if my project needs more valves or sensors than the Uno headers give?
The ESP32 S3 Uno has two extra rows of holes with more GPIOs: GPIO15 and GPIO16 (I/O, PWM, analog), GPIO45 and GPIO35 to GPIO42 (I/O, PWM), and GPIO47/GPIO48 (output only, PWM). Solder pin headers to use them and write the GPIO number in code. For extra relays, GPIO35 to GPIO42 are a good choice; for a water level or soil 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.
Can I use the same code as on the UNO R4?
Yes, the logic is the same. Only the pin number changes: D3 on the ESP32 S3 Uno is GPIO17, so the code uses 17 instead of 3.
Troubleshooting
| Problem | Possible Cause | Solution |
|---|---|---|
| No COM port in Arduino IDE | USB driver missing or board not in upload mode | Install the CP210x or CH340 driver, try another USB cable, or hold BOOT while pressing RESET |
| Relay does not click | Wrong pin, or relay VCC/GND not connected | Check that IN goes to D3 (GPIO17) and that VCC is on 5V and GND on GND |
| Relay clicks but valve stays closed | No 12V power or valve wired to the wrong relay pins | Check the 12V adapter and DC jack, and wire the valve through COM and NO |
| Valve opens and closes in reverse | Low level trigger relay or NC pin used | Use the NO pin, or swap HIGH and LOW in the code |
| Valve hums but water does not flow | Too little water pressure or flow against the arrow | Add pressure (raise the tank) and turn the valve to follow the arrow |
| Board resets when the valve switches | Electrical noise from the valve coil | Add a flyback diode across the valve and keep the 12V wires away from the board |
| Water leaks at the joints | Loose fittings | Use proper fittings and thread tape, and test away from electronics |