Relay turning on continuously water pump

Hello to Everyone,

Before submitting this request I searched over ESPHome website and the forum but I have not find any solution, but if I missed anything, please let me know.

I’m trying to create an automatic water system. I had one before with no issue until one day it stop working, so I decided to update the system and create a new one.

My system is composed by an ESP32 + HC-SR04 + Relay + Water Pump. Before starting with the welding of the cables, I tried all the system in a test board and all was working correctly, but once I weld it it’s not working properly. The issue is that the Relay continues to open / close (you can here the tic tic tic noise) and the water pump continues to go.

To weld it, I used this schematic that I created, and after checking the code, I think that the problem could be possible from here, so I’m hoping that you can help me:

The code in this moment calculates with the ultrasonic sensor the capacity of the tank, to avoid activating the water pump if there is no water, but for the switch / Relay I have this code.

switch:
  - platform: gpio
    name: "Bomba Agua Comedor"
    id: relay_1
    pin: GPIO2
    restore_mode: RESTORE_DEFAULT_OFF
    inverted: true

I hope I provided all the possible information.

Thanks in advance!

I’m not very good with relays but here are some steps I would try.

  1. Activate pullup on pin 2.
  2. Triple check wiring, especially grounds.
  3. Is the relay ok to switch control with 3.3V?
  4. Try another pin.

Does sound like a floating pin possibly. Also how long is the cables from ESP to relay. Long wire to signal pin might be picking up stray signals and firing off.

Your relay output is inverted, so the pump will be on by default, and off when the relay activates. Your relay expects 5V and has a sensitivity of 0.36W. You are supplying it with 3.3V, with a 70ohm coil resistance (https://www.circuitbasics.com/wp-content/uploads/2015/11/SRD-05VDC-SL-C-Datasheet.pdf) that gives 0.16W.

It seems to me that the relay isn’t getting enough power and is never fully switching. It was probably sheer luck that conditions were exactly right for it to activate on the breadboard. Try moving the relay board’s power supply to 5V.

I would also be careful running the pump off the board’s 3.3V regulator, they aren’t designed to provide very much current, and you are adding a source of electrical noise right onto the microcontrollers nice clean 3.3V rail

Hi all,

Thanks for all your answers.

@cbib05 I don’t understand what you mean by Output inverted, but I tried changing it to 5V as suggested, but the issue persist or you mean switching both power supplies to 5V?

@Spiro The distance is very close, I’ll say 10CM.

@Mahko_Mahko The pullup option, as for what I searched, it’s only for binary sensors or I misunderstood something? Wiring I tripled checked and it’s all as indicated in the picture. For another Pin i can try, any suggestions?

Thanks in advance!

Use a gpio with 2 X OK and no notes (to be totally safe).

You’re right on the pull-up - my bad on that one.

Try to run it with the sensor not attached. If it doesn’t click on/off without sensor then it was sensor triggering it. That may narrow down problem. Do the logs in Esphome show the sensor triggering it?

Hi all,

Thanks a lot for your help!

@Mahko_Mahko The link that you shared was really usefull. I changed the pin to config of the relay to PIN 16 and is working perfectly now!

Thanks a lot to everyone!

Regards,

1 Like

I have a screen shot of Andreas Spiess’ “priority 1” pin list in my ESPHome working directory and have had waaaayyy fewer dramas since I started using them first.

2 Likes