Driving solid state relays from ESP32 - Page 1
Forum section: electronics / beginners

author: crgarcia
author_rank: Regular Contributor
timestamp: August 05, 2022, 11:03:34 pm
content: I am currently driving mains output with PCB relays (PCN-105D) from ESP32 using aULN2003A (datasheet link), that already inlcudes the flyback diodes.I want to start using solid state relays because they incorporate zero-cross detection. I am consideringCPC1976Y (datasheet link)I have never used a solid-state relay. If I understand correctly, I do not need a flyback diode for solid state relays, instead I can treat it as a diode, which means with a resistor I can control it from the ESP32 output (3.3V):Can I connect this relay from the ESP32 with a simple resistor?Is my calculation correct? (Am I reading the datasheet correctly?)Thanks!

author: MrAl
author_rank: Super Contributor
timestamp: August 05, 2022, 11:40:09 pm
content: Quote from: crgarcia on August 05, 2022, 11:03:34 pmHello,That sounds about right but you have to ensure that your microcontroller actually puts out the full 3.3 volts for a logic high. It may not do that once loaded at 5 or 6ma. If it is 3v, that changes things a little.Also verify the drive voltage drop is really 1.5 volts.Another thing to consider is the LED degradation over the years. LED efficiency drops over years although with 5ma it should not be too bad. There is a formula out there you could look up. What this means is that any opto coupler gain is going to drop over years which means at some point the relay may not turn on anymore with 5ma. You could simply go a little higher, 6ma, but you have to check that your microcontroller can put out 6ma and even check that it can put out 5ma.That's about it i guess, except to make sure that your load turn off time can put up with 1/2 cycle delay before it actually turns off. That means PWM wont work very good although normal power switching would be ok, which means if you have to vary the duty cycle you have to do it over longer periods of time like 10 seconds or something like that.

author: themadhippy
author_rank: Super Contributor
timestamp: August 06, 2022, 01:05:09 am
content: The circuit you've shown will do a great job of blowing fuses and possible destroying itself as every time it switches on it will short phase to neutral

author: JustMeHere
author_rank: Frequent Contributor
timestamp: August 06, 2022, 02:13:18 am
content: You should be good. The charts show that 2.5mA will have the optocopuler diode fully on. The ESP32 can source 40mA per pin with a total budget of 1.2A.One thing you should have on your high side of the DC circuit is a biasing resistor. Microcontroller pins can float when being programmed and during boot. Place a 10k or 20k resistor between you micro and the optocopuler. It should be connected to ground. This will help make sure the relay is fully off unless your micro is turning it on.

author: JustMeHere
author_rank: Frequent Contributor
timestamp: August 06, 2022, 02:20:36 am
content: Note: flyback diodes are for deenergizing coils. No coil on your DC side. We don't know what your trying to drive on your load side of the relay. If that has a coil, it's a good idea to protect your relay with a MOV or a RC snubber. I have no clue how to advise you on how size those.

author: crgarcia
author_rank: Regular Contributor
timestamp: August 06, 2022, 07:19:16 am
content: Quote from: JustMeHere on August 06, 2022, 02:13:18 amThank you! I added to the circuitQuote from: MrAl on August 05, 2022, 11:40:09 pmGood point! I will control a Din mounted external latching relay that will control lights. I don't think this is an issue for meQuote from: JustMeHere on August 06, 2022, 02:20:36 amIt has a coil! At the other side of the relay there is an external latching relay, DIN mounted (like this one:link)I have this problem, and it was restarting my microcontroller, and that is the reason why I am trying with a solid state with zero crossing (link to another post)Do I need an snubber instead?

author: jfiresto
author_rank: Frequent Contributor
timestamp: August 06, 2022, 10:37:09 am
content: The 100mA fuse suggests your load may be too low for the solid state relay (I would check its datasheet).