Author Topic: ESP32 vs 5V relay  (Read 3306 times)

0 Members and 1 Guest are viewing this topic.

Offline Lucky-LukaTopic starter

  • Supporter
  • ****
  • Posts: 240
  • Country: it
ESP32 vs 5V relay
« on: May 06, 2022, 08:13:25 am »
Hi all
Given the 5V relay in the schematic I think I can use a 3.3v GPIO pin to control it. Right?
What it the minimum voltage to give it the HIGH state having Vcc=5V?
The schematic shows 2 leds and a 1k res in series.
It's a curiosity.
Thanks
https://www.elegoo.com/products/elegoo-8-channel-relay-module-kit

Memento audere semper.
 

Offline golden_labels

  • Super Contributor
  • ***
  • Posts: 1229
  • Country: pl
Re: ESP32 vs 5V relay
« Reply #1 on: May 06, 2022, 09:33:40 am »
The module is designed to take TTL inputs, so not feeding TTL signals is out of spec. You may reverse-engineer it — I assume this is what the “4_channel_relay_schematic” is — and use that knowledge to determine compatibility with other signals, but if that goes to production you face a problem of Elegoo changing components. Not a huge issue for DIY projects where you use the board once.

PC817 is controlled by current, not voltage. You must provide sufficient current to turn it on and do not have current to turn it off. So are the Qn transistors, and so is the relay.

Since the board is active low, you activate the relay by pulling the input to 0V. It is calculated to turn on below 4mA, which is well within ESP32 sink capabilities. So that is not an issue.

Turning it off may be a problem, though. ESP32 running at 3.3V has high output no lower than 2.64V. That gives you 2.36V across the diode, optocoupler input and the resistor. Versus expected virtually no voltage. It’s hard to tell how large current you will get: may be 1mA, may be 100µA. The current on PC817’s output has even wider range. At the upper end it is high enough to keep the relay turned on, at the lower end it should not.
People imagine AI as T1000. What we got so far is glorified T9.
 
The following users thanked this post: Lucky-Luka

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12881
Re: ESP32 vs 5V relay
« Reply #2 on: May 06, 2022, 09:50:47 am »
So-called 'optoisolated' relay boards are almost invariably cr@p with the optocoupler implementation offering little or no advantage  over a simple transistor relay driver, and having the disadvantage of requiring a significantly higher driving current from the logic connected to its input(s)

You can recognize the cr@p by the presence of tracks running under the optocouplers compromising their isolation rating by reducing the creepage and clearance distances - any designer who makes this noob mistake cant be trusted to use safe clearances under the relays either, so unless you've personally checked the clearances the board is a potential deathtrap if used to switch mains voltages even if the relays are rated for mains AC switching (and not fake).

Another sign of cr@apness is if there's any ground or Vcc connection on the board that crosses the supposed isolation gap.  Again this defeats the whole purpose of optisolation. 

In very high EMI environments there may be a need for an optoisolated relay board, but ideally it would bring out both sides of each opto's LED individually (with or without a series resistor) so each channel can be hooked up to the MCU board using twisted pair for noise immunity (also allowing a choice of high side or low side drive), and should probably have an anti-parallel protection diode across each opto's LED.  As described above, creepage and clearance distances under the optos should be the maximum permitted by the footprint, preferably with the board slotted individually under each opto,  (a tight layout with a long slot under all the optos typically results in a mechanically weak board),  indicator LEDs (+ their series resistors) should be in parallel to the relay coils so they can indicate the true relay state and diagnose failed drivers, coil power to the relays should be on a separate connector to the opto inputs, clearances on the contact side of the relays should be at least 4mm between contacts and between channels, and there should be provision to fit snubbers (either series RC, TVS diode or varistor)  across each contact pair.  Furthermore the PCB layout should be in the documentation so any   engineer reviewing the system design can check creepage and clearance distances.

The Elegoo board fails on many of the above and I certainly wouldn't use it for switching mains until I've seen the PCB layout and checked clearances.  The documentation shows there's an isolation slot  between the COM and coil pins of each relay, so *IF* *PRESENT* thee's *some* hope it may be safe for switching mains.   The presence of tracks under the optocouplers and both input side Vcc and 'JD_Vcc' (coil power) on the same connector irredeemably compromises the optoisolation which therefor cant be trusted for more than a low voltage DC offset between the logic and coil power sources.  It would be adequate to break ground loops.

Now on to its actual performance.  If you consult the full Sharp PC817C optocoupler data sheet, you'll find its min. CTRR is nominally 200, at 5mA If.   However Fig. 4 'Current Transfer Ratio vs. Forward Current' shows a significant drop-off at low currents, and at 1mA If, I estimate you can only count on a min CTRR of 125%.    The SRD05SLC relay has a nominal coil current of 71.5mA.  its min. pull-in voltage is 75% of nominal, so you cant tolerate more than 1V drop (assuming the supply is 5V -5%) across the SS8050 transistor, which has a min. hFE of 85. 

Al any opto input current below 1mA you are quite literally off the charts and operation isn't guaranteed.  However I *think* it should operate down to around 0.7mA when new.  N.B. there is no allowance for opto LED aging, so I wouldn't be happy with under 1.5mA for any serious application.  Assuming a low Vf (1.7V nom.) GaAS red indicator LED it *MAY* operate from as low as 3.3V in, but don't bet on it as if an ordinary nom. 2.1V Vf LED is used I believe it will need at least 3.6V!   For long-term reliability, IMHO it needs at least 4.5V drive.

Then as 'golden_labels' has alluded to, you have the voltage drop in the ESP32 output.  This *may* be as high as 10% of its Vcc, though IMHO this is unlikely sinking less than 1mA.  The parameter you want is VOL, though tracking it down in the Espressif documentation is difficult, and you need to know exactly which ESP32 chip is used in your module.

TLDR this relay board isn't suitable for 3.3V logic without level conversion or modification, and may not be 'fit for purpose' anyway!
 
The following users thanked this post: Lucky-Luka

Offline Lucky-LukaTopic starter

  • Supporter
  • ****
  • Posts: 240
  • Country: it
Re: ESP32 vs 5V relay
« Reply #3 on: May 06, 2022, 09:59:18 am »
Thanks Ian.
Very informative. I will re read what you have said because there are a lot of infos.
Which solution do you suggest me to drive a generic load as a 220V light?
Memento audere semper.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12881
Re: ESP32 vs 5V relay
« Reply #4 on: May 06, 2022, 10:17:30 am »
Which solution do you suggest me to drive a generic load as a 220V light?
A reputable brand of DIN rail mount solid state relay purchased from a major distributor so you can be certain its not fake, rated for at least 10 times the light's operating current to handle inrush.  Check the datasheet to be sure it can work with 3V low current drive, or put a driver transistor or IC (e.g. ULN2803) for it on your logic board. 

Mounted in an appropriate DIN rail enclosure, with an insulating barrier between the mains and low voltage sections and the low voltage connections to the relays sleeved, and assuming the relays and low voltage power supply (also DIN rail mount) have appropriate approvals, and the mains wiring is done competently, it should meet your local electrical safety and wiring regulations, and pass inspection.
« Last Edit: May 06, 2022, 10:25:18 am by Ian.M »
 
The following users thanked this post: Lucky-Luka

Offline Lucky-LukaTopic starter

  • Supporter
  • ****
  • Posts: 240
  • Country: it
Re: ESP32 vs 5V relay
« Reply #5 on: May 06, 2022, 10:27:17 am »
why not just a power mos like IRL510 instead of that Darlington?
do you have an example of a relay that you have mentioned in mind?
thanks
Memento audere semper.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12881
Re: ESP32 vs 5V relay
« Reply #6 on: May 06, 2022, 10:43:32 am »
The ULN2803 is convenient if you need to drive several DC loads as it contains all the parts required, including base resistors and 'catch' diodes for inductive loads.  Its a widely second-sourced 'jellybean' part.  Its main disadvantage is its high Vce_sat (on voltage drop) and lowish dissipation limit which limits the total current it can handle.   There are better choices, which for only a few loads, and depending on availability, may include discrete low Vgs threshold MOSFETs.   Once you need more channels, a driver IC is usually preferable to a discrete solution.

Note that a 4A power MOSFET is gross overkill for driving a SSR which is almost certainly under 50mA input current @5V. You should probably be looking at 200mA rated parts in SOT-23 or similar, or TO-92 if thru-hole.
« Last Edit: May 06, 2022, 10:48:01 am by Ian.M »
 
The following users thanked this post: Lucky-Luka

Offline Lucky-LukaTopic starter

  • Supporter
  • ****
  • Posts: 240
  • Country: it
Re: ESP32 vs 5V relay
« Reply #7 on: May 06, 2022, 11:05:53 am »
2n2222a to drive the relay then?
can I just use a power mos instead of the relay then?
Memento audere semper.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12881
Re: ESP32 vs 5V relay
« Reply #8 on: May 06, 2022, 11:18:16 am »
Yes, 2N2222 or *any*' jellybean NPN will do to drive a SSR.  This is *NOT* the case for electromechanical relays as you need to carefully check the transistor has enough gain at the required coil current and that the digital output can deliver enough base current to guarantee saturation.   A simple common emitter BJT is rarely a good choice when driving large relays from a MCU pin.

Direct drive of the lamp with a power MOS requires it to be low voltage lighting with an isolated DC supply.  You said '220V' so presumably its AC mains voltage, so no that's not an option.
« Last Edit: May 06, 2022, 11:22:27 am by Ian.M »
 
The following users thanked this post: Lucky-Luka

Offline tepalia02

  • Regular Contributor
  • *
  • Posts: 100
  • Country: bd
Re: ESP32 vs 5V relay
« Reply #9 on: May 06, 2022, 02:49:06 pm »
Logic level converter can be an option too:
 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3393
  • Country: nl
Re: ESP32 vs 5V relay
« Reply #10 on: May 06, 2022, 03:04:58 pm »
The Chinese relay boards with optocouplers are indeed mostly crap, although there are differences between manurefacturers.

Clearance on the PCB's around he opto couplers is shamefully small.
The (Songle) relays have 250Vac 10A printed on them, but that is only the rating of the contacts. This does not mean the relays have adequate isolation.

The center contract of these relays being in between the coil contacts was a warning bell for me, so I opened up one of these relays, and internally the clearance between the coil and the contacts is less then 2mm, and that is not enough.

If you want to play on the safe side, then get some better quality relays. For example the Omron G2R (clones?) have a very clear and big separation between the coil and the switch. They even have an extra blast shield between these two sections. Even if these relays fail, they're likely to fail in a safe way without putting mains voltage over the coil contacts.

A manurefacurer is a manufacturer that makes crap.
 

Offline Lucky-LukaTopic starter

  • Supporter
  • ****
  • Posts: 240
  • Country: it
Memento audere semper.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12881
Re: ESP32 vs 5V relay
« Reply #12 on: May 06, 2022, 07:09:28 pm »
Read the reviews: https://www.amazon.it/diymore-24V-380V-SSR-40DA-Modulo-solido/product-reviews/B08FWWRK2Y/ref=cm_cr_dp_d_show_all_btm?ie=UTF8&reviewerType=all_reviews

Its a low-end Fotek clone marked 'FQFEK' so at least its not a fake passed off as genuine, and other reviews indicate it has at least *some* power handling capability (or rather that at some time in the past, some of the SSRs shipped by that supplier did).  Don't trust it to provide isolation as like the killer USB chargers, you've got no reason to believe it is built to 1st world safety standards for creepage and clearance distances.

See this thread for reasons to avoid Fotek SSR clones and also Fotek branded SSRs from dubious sources: https://www.eevblog.com/forum/reviews/warning-dont-buy-fotek-solid-state-relays/

« Last Edit: May 06, 2022, 07:15:00 pm by Ian.M »
 
The following users thanked this post: Lucky-Luka

Offline Lucky-LukaTopic starter

  • Supporter
  • ****
  • Posts: 240
  • Country: it
« Last Edit: May 06, 2022, 08:03:24 pm by Lucky-Luka »
Memento audere semper.
 

Online MK14

  • Super Contributor
  • ***
  • Posts: 4577
  • Country: gb
Re: ESP32 vs 5V relay
« Reply #14 on: May 06, 2022, 08:38:10 pm »
I was looking for a decent priced relay for low current home application.
I was just trying not to spend too much without burning down the house.
Maybe something like this:
https://www.ebay.it/itm/133920617666?_trkparms=amclksrc%3DITM%26aid%3D1110006%26algo%3DHOMESPLICE.SIM%26ao%3D1%26asc%3D20200818143230%26meid%3D8a9a3079fd814aa6a7d73c21017862b4%26pid%3D101224%26rk%3D1%26rkt%3D5%26sd%3D191830531168%26itm%3D133920617666%26pmt%3D1%26noa%3D1%26pg%3D2047675%26algv%3DDefaultOrganicWeb%26brand%3DUnbranded&_trksid=p2047675.c101224.m-1
?

I hope you don't mind me asking.  But, do you have any connection, to the seller(s), you are posting links to ?

The sellers name, is let's just say, interesting.

Lucky-Luka  VS  lalalucky
 

Offline Lucky-LukaTopic starter

  • Supporter
  • ****
  • Posts: 240
  • Country: it
Re: ESP32 vs 5V relay
« Reply #15 on: May 06, 2022, 08:54:55 pm »
ok I have to confess now...
it's me... straight from suzhor on the eevblog forum trying to sell in a convoluted way cheap ssr modules...  :clap:
 :-DD
Memento audere semper.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12881
Re: ESP32 vs 5V relay
« Reply #16 on: May 06, 2022, 08:57:54 pm »
Another dubious Chinese relay board.  The Omron G3MB series 2A SSR was last manufactured back in 2011 ([ref]) so you can be 99.9% certain its fake.

I've already said how to get a genuine SSR - buy it from a major distributor, *NOT* from Ebay, Amazon or other far east eBazars.  At the end of the day, its safety critical, and up to $100 for a high load genuine SSR is significantly cheaper than a pine box!  :horse:
« Last Edit: May 06, 2022, 09:03:26 pm by Ian.M »
 
The following users thanked this post: Lucky-Luka

Offline Lucky-LukaTopic starter

  • Supporter
  • ****
  • Posts: 240
  • Country: it
Re: ESP32 vs 5V relay
« Reply #17 on: May 06, 2022, 09:14:38 pm »
100E?
this one is legit and it's 5Euro and it looks like will be ok for my purpose (only 1A)...
https://it.rs-online.com/web/p/rele-stato-solido/8074649?cm_mmc=IT-PLA-DS3A-_-google-_-CSS_IT_IT_Rel%C3%A8_Whoop-_-(IT:Whoop!)+Rel%C3%A8+stato+solido-_-8074649&matchtype=&pla-337125950622&gclsrc=ds&gclsrc=ds
or
8Euro and 2A
https://it.farnell.com/panasonic-electric-works/aqg22212/solid-state-relay-2a-9-6-14-4vdc/dp/2846791?mckv=_dc|pcrid|533620239041|plid||kword||match||slid||product|2846791|pgrid|127553312569|ptaid|pla-919912526629&gross_price=true&CMP=KNC-GIT-GEN-SHOPPING-SMART-Electromechanical_10-Jan-22
don't you think?
Memento audere semper.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12881
Re: ESP32 vs 5V relay
« Reply #18 on: May 06, 2022, 09:48:02 pm »
They are almost certainly genuine as RS and Farnell don't muck about with unauthorized sources, but the first is only rated for 4A peak repetitive inrush surge, so is unsuitable for mains voltage  incandescent or fluorescent lamps or LED lamps with capacitor dropper ballasts.  The second is rated for 15A peak repetitive inrush surge, so is more suitable.   Both have the disadvantage of having mains on your PCB*, so you are going to have to do a PCB layout with appropriate creepage and clearance distances and suitable connectors for the mains wiring, and safely mounting and enclosing the PCB, so the total cost to use one will be several times the retail price.

* as opposed to having screw terminals for the mains wiring, and being approved for use mounted on a DIN rail in an off-the-shelf electrical enclosure, so only low voltage wiring goes to your PCB.
 
The following users thanked this post: Lucky-Luka

Offline Lucky-LukaTopic starter

  • Supporter
  • ****
  • Posts: 240
  • Country: it
Re: ESP32 vs 5V relay
« Reply #19 on: May 07, 2022, 07:33:25 am »
can you show me the link to one SSR that you have in mind?
Memento audere semper.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12881
Re: ESP32 vs 5V relay
« Reply #20 on: May 07, 2022, 08:12:50 am »
First, please provide specs for your lamp load so I can select an appropriate SSR.

Also note that AC SSRs typically have a significant off-state leakage current, which can result in some types of energy efficient lamps flashing slowly with rather short flashes when they are supposed to be off.  There are workarounds for this, but if the lamp is particularly low power a traditional relay may be preferable.
 

Offline inse

  • Frequent Contributor
  • **
  • Posts: 662
  • Country: de
Re: ESP32 vs 5V relay
« Reply #21 on: May 07, 2022, 08:34:44 am »
What's the reason for driving relays with optocouplers anyway?
 

Offline Lucky-LukaTopic starter

  • Supporter
  • ****
  • Posts: 240
  • Country: it
Re: ESP32 vs 5V relay
« Reply #22 on: May 07, 2022, 08:37:59 am »
I have found that relay module at home and I've decided to use it.
They sell millions of these items on amazon.
Probably they thought it's a good idea to avoid switching noise to the microcontroller.
Memento audere semper.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12881
Re: ESP32 vs 5V relay
« Reply #23 on: May 07, 2022, 08:48:33 am »
What's the reason for driving relays with optocouplers anyway?
Sometimes, when switching particularly nasty loads with heavy duty relays or contactors, you need the extra opto-isolation to prevent EMI from large load transients, picked up by the coil of a traditional relay or contactor breaking through to the controlling logic and glitching it.   It also vastly reduces the risk of damage to the control logic if the relay's isolation breaks down e.g. due to catastrophic contact failure sputtering metal all over its innards, which is obviously important if you have a lot of relays switching high energy circuits.

I have found that relay module at home and I've decided to use it.
They sell millions of these items on amazon.
Probably they thought it's a good idea to avoid switching noise to the microcontroller.
If you've already got a relay module, please post good closeup photos of both sides of its PCB if its a 'bare board' module, so we can at least advise you if we see anything that would make it unsuitable for mains use.

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf