The issue of controlling the solenoid valve on ESP32 via relay in Home Assistant

retleh10

Newbie
Joined
Sep 27, 2023
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
13
Hi, I’m a beginner with ESP and I’m making an automatic irrigation system on ESP32 and I have a problem with the control of the solenoid valve. When I turn on the power on the relay (OKY3030 OKYSTAR), the red LED (power) turns on and the green +SW is on all the time. I found a simple code and use it in Home Assistant:

switch:
- platform: gpio
name: "Solenoid valve"
pin: GPIO26
restore_mode: ALWAYS_OFF

A button has been created in the HA panel that I should control the valve with, but the valve is on all the time.
When I use this button, the green LED dims slightly.
The 5V power supply is from the ESP (USB-C cable connected), and the solenoid valve is powered by 12V DC.
In the attachment I add a wiring diagram. Please help me to solve the problem.

 

Just a guess without seeing your code:
The 5V pin on the ESP32 board is the USB supply fed through a diode so it will generally be a little lower than 5V but it may not be able to supply enough current to operate the relay board. The green LED, whatever it is because it doesn't appear in your schematic, may be dimming because the power rail is dropping.

Brian.
 

Normally one also uses a diode across a solenoid to minimize inductive
spike due to solenoid coil. Help prevent relay arcing of contacts.



No diode in circuit :



Diode clamp across solenoid :





Regards, Dana.
 
Last edited:

We are yet missing a specification of the relays module input circuit. It's not necessarily compatible with 3.3 V logic level signal provided by ESP32.
--- Updated ---

You should also check if level sensor output can be directly connected to ESP32 without voltage reduction.
 

Cookies are required to use this site. You must accept them to continue using the site. Learn more…