this code is working on the ESP in home assistant. I can switch the switch on an off in home assistant
and i can see the ESP responding as it should. However the relay does nothing. Both the green and red light are on the relay, and if I unplug GPIO2 then the green light goes off, and back on when I plug it back in. i’m obviously missing something somewhere. Eventually I want this to control a 24vDC solenoid, hence the pulse. The relay is a SONGLE SRD-05VDC-SL-C
Thanks for your help.
100% of all my (over a dozen) relays designed for “5V” work without any hiccups on the 3.3V GPIO logic on my ESP’s. The VCC of the relay obviously get’s 5V and the relay pin get’s reliable triggered over around ~2.5V (which makes them perfectly fit to work with ESP’s)
Power to esp32 is via 5v to usb.
then ESP32 GND to Relay GND
ESP32VIN to relay VCC
ESP GPIO2 to relay IN
I’m thinking it may be voltage to the relay not being 5V, I’ll get a stepdown today and power the esp32/Relay from the 24V power supply for the soleniod (using the stepdown).
OK, So I have confirmed 5v to board and relay. When I turn the switch on and off (in home assistant) the blue light on the esp32 board responds but nothing on the relay. If i unplug the pin2 the relay activates and the blue light goes on, when i plug it back in the relay activates and blue light goes off. I’m stumpted as to how i get the switch to activate the relay.
we do know because, pin 2 is universally used for the onboard led. There may be some odd ball dev board where this isn’t the case but, gpio 2 is almost always the onboard led.
have you confirmed this is a 5v relay? These come in different voltages like 12v and 24v and they look 100% identical. post a picture of your relay and how do you have the jumpers configured? Do you have the jumper set to High or Low. You usually can’t toggle a 5v relay with it set to High on the jumper, you need to set it to Low and then invert your gpio.
ya, I didn’t see that OP had typed out the model of the relay. These relays look identical and it’s not hard to overlook the voltage and accidentally grab a 12v. The other reason I said he should post a picture is those Songle relays are usually on a module and not just the relay like that picture. Which module and what additional circuitry is useful information.
disconnect the 5v to the relay and instead use a 3.3v output on the board. If it has a H-L jumper, move the jumper to L. Invert the GPIO in your code. Often 5v is too much voltage and the relay wont be able to fully turn ON/OFF with only a 3.3v gpio. I have a bunch of relays that do this and i have to go back and swap the 5v with 3.3v then Viola!