Custom PCB Relay Issues - Page 1
Forum section: electronics / beginners

author: bizkits
author_rank: Contributor
timestamp: September 28, 2020, 02:19:49 pm
content: I designed a really simple custom PCB which uses an ESP32 to control 4 relays and a Wiznet 5500 LITE to read a sensor values over Ethernet.1 relay controls a 24V Omron relay which controls a large load (400V+).1 relay controls a Red and Green LED lights (12V)1 relay controls a dry contact to activate a sliding door1 relay controls an overhead light 220VAC. (Straight through)The board is powered using a 24V power supply which gets step down into 5V using the OKI-78SR-5.The Red and Green LED lights is powered using the same 24V which gets stepped down into 12V by a separate step down converter (something like this:https://www.amazon.com/Converter-Reducer-Regulator-Adapter-DC15-40V/dp/B01EFUHFDU).Initially, the issue I faced was when I turned off the Omron relay, my board may restart. I managed to fix it by powering the board using the 12V step down converter (Powering the LED). I am unsure why this happens even though I have the flyback diode(1N4007) at the relay which should prevent any backward EMF.Even though the first issue was fixed, is there a way to share the same 24V supply?The current issue I encounter is with the WIZNET 5500 module. Sometimes after 1-3 cycles or sometimes > 30 times of activating the Omron relay, and overhead lights, the WIZNET 5500 module fails to initialize which prevents me from reading the sensor values. A soft reset of the WIZNET 5500 module doesn't help, but restarting the whole ESP32 module seems to bring the WIZNET 5500 back.From these signs, I suspect there could be some electromagnetic interference (from the loads) which affected the ESP32.Another possible issue could be my relays are not isolated. (I read that I should power the relay with an external power source rather than from same power source of the ESP32).As the PCB is deployed somewhere else, I made a small setup to try replicate the issue. However I didn't manage to replicate the issue. Hence for now I can only come up with all the possible issues and try to implement them when I head down the next time.I have attached my schematic and PCB layout.Any suggestions or critics are welcome as I am trying to improve everyday.Thank you.Update 1First of all, thank you all for the comments and suggestions. I took sometime to digest all of them and made sure I understood all the suggestions.I have came up with an updated schematic and PCB board and attached to the same post.1. Current limiting resistors for BJT transistor baseAfter reading up, I added a 1Kohm resistor at each I/O pins. Using the formula below I should have a safer current(ESP32 Pin Voltage - MUR160 Diode forward Voltage) / Resistor = Current(3.3V- 1.25V)/1Kohm = 2.05/1Kohmz = 0.00205A = 2.05mA2. 1N4007 are slow diodesI watched a video on "What is a schottky diode" (youtube.com/watch?v=bXEyCf1P0UU) and at 2:32, he showed a comparison between a slow diode (1N4007) and a faster diode (1N5817). Indeed the 1N4007 had issues with clearing the back emf. Hence I have changed my diodes to the MUR160 as recommended by Manul.3. Missing groundsI connected all grounds and added a ground pour on both layers. However, I am not sure if I should cover the whole board or just under the ESP32 portion?4. Decoupling and Bulk capacitorsThanks Doctorandus_P, viperidae and DTJ for bringing up adding decoupling and bulk capacitors.In this round, I have changed the DC-DC converter to a RECOM R-78E5.0-1.0. (https://www.mouser.sg/datasheet/2/468/R-78E-1.0-1711201.pdf) It's similar to the Murata.Referring to the datasheet, I see there is 2 sections. The first is "EMC Filter Suggestion according to EN55032" and second "Standard Application".I followed the "Standard Application" for now. Is there any significant benefits if I follow the "EMC Filter Suggestion"?The "Standard Application" recommended 10uF and 10uF. I chose 35V for the decoupling capacitor and 10V for the bypass capacitor. I chose those values as 35V>24VIN and 10V>5VIN.DTJ mentioned that I should add 1nF ceramic, 100nF ceramic and a 10uF 10V in parallel to the Power Pin of the ESP32.I was thinking if it is really required when I have added the bypass capacitor on the 5V rail.5. 400V load concernsI understand the safety issues and concerns with driving high voltage loads.In the circuit, the "LOAD" is a 24VDC OMRON Relay. This 24VDC OMRON Relay will control a high voltage load (~400V).Hence it is not the blue squarish relay which is controlling the high voltage load.All the 5V relay is only controlling voltage <= 24V loads.Update 2The board finally arrived and I have soldered it together. After testing, it does help prevent the board from crashing when the overhead lights turn off.However, the W5500 board keeps crashing after the load/light is turned on/off. I will have to reinitialize the W5500 everytime. Now I'm suspecting when the load / lights are turned off, it causes EMI.This EMI causes my PCB to mess up its signal. Anyone can suggest or advice how to solve this?

author: Manul
author_rank: Super Contributor
timestamp: September 28, 2020, 03:57:49 pm
content: 1. Are you driving BJT transistors directly from IO ports? No current limit at all?2. 1N4007 diode is very slow and is not a good choice for back emf protection. Choose faster diode. Less then 100ns is good for most applications. I personally like MUR120 as a general purpose diode.

author: viperidae
author_rank: Frequent Contributor
timestamp: September 29, 2020, 12:04:08 am
content: You could try bypassing the supply to the relays with a cap or two.By the looks of it, all current to and from the relay coils goes past the power input of your esp.Like the other poster said, you should have current limiting resistors to the transistors.Don't assume the esp board has a well designed power supply either. I had one that would reboot itself sometimes unless I decreased the wifi transmit power.

author: FearTec
author_rank: Regular Contributor
timestamp: September 29, 2020, 04:23:21 am
content: A "Q" and "D" are swapped on the silk screen, Add a version number.

author: DTJ
author_rank: Super Contributor
timestamp: September 29, 2020, 07:10:41 am
content: As others have said add some decoupling capacitors CLOSE to the micro-contoller +ve power pin.Try a belt and braces approach and add 1nF ceramic, 100nF ceramic and a 10uF 10V in parallel to ground from the power pin (20) on the micro.Maybe also ground the unconnected micro ground on p13.You might have done something weird with the grounds. What would normally be done is to place a ground plane or ground pour on one layer and all grounds connect to this.If you are doing 2 layer board like you are then pour a polygon plane on one side and hook all grounds into it.It looks like your grounds run in/out and via the ground frame inside the uC package.What do you mean by "1 relay controls a 24V Omron relay which controls a large load (400V+)."Do you mean over 400V or is it meant to be watts. AC or DC. You may need to be careful about routing separation for high voltages.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: September 29, 2020, 12:29:16 pm
content: This is clearly a beginners project with beginners mistakes.There should be a GND plane under and around the ESP32 module with a solid connection between all it's GND pins.Leaving some of the GND pins, such as pin 13 open is not good.All components should be connected to this same GND plane. Having the return current for the W5500 module go through the ESP32 module is not good.The W5500 module also only has one of the 3 GND pins connected. Not good. Connect them all to the GND plane.The antenna section of the ESP module should have no traces whatsoever near it.Check the datasheets of all sub PCB's (ESP, W5500, Murata) for recommendations about both decoupling capacitors and bulk capacitors. Your Murata DC-DC module may also need extra capacitors on the 24Vdc side. These modules often depend on extra capacitance being available. Not putting the capacitors on the module itself makes them smaller and cheaper, and external capacitors can be tailored to the application.And indeed the BJT's for the relays need base resistors.I do not trust these squarish relays (Songle?) I've opened one up and internal clearances are very minimal. The contacts can probably switch 240Vac, but clearance to the coil wires is grossly inadequate. The result is that you should consider the whole PCB as "live" when working on it while relays are connected to mains voltage. A relay like the Omron G2 series is much better in this regard. It does not only have much bigger separation on the PCB pins, but also internally it has a labyrinth to increase creepage and reduce spark over during faults. These are well worth the little extra money. It really is the difference between the cheapest garbage from china, and a relatively well made product for a small price.Some well placed inductors or chokes can also improve the reliability, but good LCR filtering is a whole chapter of a big book on itself.For switching bigger loads, it is also common to use 2 relay's in series. A small relay switches a bigger off-board relay. This is not only for the size and power rating, but switching big loads tend to generate significant electrical noise, and the small relay is an extra barrier to separate that noise from your sensitive ESP circuit.

author: Silenos
author_rank: Regular Contributor
timestamp: September 29, 2020, 06:31:54 pm
content: The"400 V load"220 V and the sight of relays looked very spooky. I can immedietally tell your design doesn't conform EU standards regarding "safety of electrical devices" or whatever these are titled, and I doubt Asian ones are more relaxed at these issues. Even for 230 V mains the air, surface creepages, pcb/soldermask isolations are relevant. If you are going to install this in actual a building permanently, better validate your standards. It won't be a wasted time.What exactly nominal/peak load/power do you expect? device inrush current? - your HV tracks seem too narrow. Plus imagine someone or the driven device shorts the relay network protected by 20 A slow fuse in the box, shall your device survive and stay safe?or if it is really 400 V "power tap", by muuch bigger fuse: your tracks may vaporize and the connector may melt producing the smoke wall.If it is 400 V, the Songle relays seem unrated for such voltage.Don't even try saving money here - get brand, properly rated relays and connectors, and rest, as Doctorandus_P says.Edit: oh ok, you do drive intermediate relay for those 400 V. My bad at reading, I'm getting paranoid against mains+ designs. So just 220 V

author: bizkits
author_rank: Contributor
timestamp: September 29, 2020, 07:13:35 pm
content: Quote from: Manul on September 28, 2020, 03:57:49 pm1. I have read up on the dangers of not adding any current limit.In my updated schematic, I added 1Kohm resistors on each transistor's base.2. Thanks for pointing that out. I was searching online for more information regarding diodes and came across a video talking about "schottky diode". And in the video, the author did a comparison between the 1N4007 and 1N5817 which showed the disadvantages of the slow 1N4007. Are there any reasons why so many people are still using the 1N4007 when there are better alternatives out there?

author: bizkits
author_rank: Contributor
timestamp: September 29, 2020, 07:20:27 pm
content: Quote from: DTJ on September 29, 2020, 07:10:41 amI added a bypass capacitor for the DC-DC converter which powers the microcontroller.Is it still recommended to add even more decoupling capacitors in parallel after the bypass capacitors? The reason is because I am not using a "raw" ESP32. And the microcontroller board may already have decoupling capacitors.As for the ground pour, is there any significant different between having a polygon plane and a rectangular plane (covering the whole board)?

author: wraper
author_rank: Unknown
timestamp: September 29, 2020, 07:23:52 pm
content: You don't need a fast diode. So what if it has slow recovery time like 1N4007, it does not matter in this application.QuoteYou don't need a relay to drive relay. That Q1 transistor can drive 24V relay directly just fine.

author: bizkits
author_rank: Contributor
timestamp: September 29, 2020, 07:28:50 pm
content: Quote from: Doctorandus_P on September 29, 2020, 12:29:16 pmThank you for reading my post and pointing out my mistakes.1. GND planeI have taken your advise and connected all GND. When you say I should have a GND plane around the ESP32 module, does it mean that I should not have a GND plane covering the whole of the top and bottom layer? In my updated schematic (I updated my original post with the attachements), I did a GND pour on both top and bottom layer. Should I instead do a GND pour only on the "ESP32" side?2. AntennaI have rotated and realigned the position of the modules. Now the antenna is facing outwards without any traces below.3. Decoupling capacitors and bulk capacitorsInstead of the Murata DC-DC module, I swapped it with the RECOM R785.0-1.0.Referring to the datasheet, I see there is 2 sections. The first is "EMC Filter Suggestion according to EN55032" and second "Standard Application".I followed the "Standard Application" for now. Is there any significant benefits if I follow the "EMC Filter Suggestion"?The "Standard Application" recommended 10uF and 10uF. I chose 35V for the decoupling capacitor and 10V for the bypass capacitor. I chose those values as 35V>24VIN and 10V>5VIN.4. Base resistorsI have added 1Kohm on each of the transistor's base to limit the current5. Squarish relays concernsI understand the safety issues and concerns with driving high voltage loads.In the circuit, the "LOAD" is a 24VDC OMRON Relay. This 24VDC OMRON Relay will control a high voltage load (~400V).Hence it is not the blue squarish relay which is controlling the high voltage load.All the 5V relay is only controlling voltage <= 24V loads.

author: floobydust
author_rank: Super Contributor
timestamp: September 29, 2020, 07:36:06 pm
content: Nothing wrong at all using 1N4007 slower diodes across relay coils. Even 1N4148 or BAV99 are fine with SRD 05 relay coil 89mA.You have no series resistors limiting base-current to the transistors.The W5500 Lite might be overloading the 3.3V regulator AS1117 on the ESP board, check the power budget.If it is relay contact arcing making EMI, then you need RC snubbers added across them. On the bench, with no load the board wouild work.Don't put ground-pour under the ESP32 antenna, or around the AC mains relay traces! Your coil pcb traces are too close to the relay contact middle pin. You must have decent clearances for the high voltage.

author: bizkits
author_rank: Contributor
timestamp: September 29, 2020, 07:39:32 pm
content: Quote from: Silenos on September 29, 2020, 06:31:54 pmThank you for pointing out the different standards. I will look into them.I understand all the potential disasters which may occur when it comes to mains and hence I avoid any mains.This PCB is powered using a 24VDC power supply.

author: bizkits
author_rank: Contributor
timestamp: September 29, 2020, 07:49:02 pm
content: Quote from: floobydust on September 29, 2020, 07:36:06 pmFor back emf, is there a rule of thumb on the "reverse voltage" I should base on to decide if I should use the diode?My current thought is the higher the better as I am unsure how high the spikes can reach.I have added resistors in my new schematics.Regarding the power budget of the AMS1117, I doubt it is the issue however it is interesting that you pointed that out. The reason I took this out of the equation was because I have the similar setup in my workplace which didn’t have any issues polling from the WIZNET 5500. The issue only occured when the relays activated X times. X is unpredictable.I will look into RC snubbers. Even if there's not relay contact arcing, is it advisable to add RC snubbers for stability?Noted on the ground-pour under the ESP32 antenna or around AC mains. Even though I am not entirely sure the reason, I suppose it may cause interference?

author: bizkits
author_rank: Contributor
timestamp: September 29, 2020, 07:51:24 pm
content: Quote from: wraper on September 29, 2020, 07:23:52 pmCan you explain a little more why it does not matter in this application?I didn't thought of driving the 24V relay directly. But it seems like a good suggestion.

author: wraper
author_rank: Unknown
timestamp: September 29, 2020, 09:44:35 pm
content: Quote from: bizkits on September 29, 2020, 07:51:24 pmBecause even slow diodes open fast (in forward direction). Closing (recovery) after reverse voltage is applied is slow but it does not matter in this application.

author: floobydust
author_rank: Super Contributor
timestamp: September 29, 2020, 10:06:42 pm
content: Quote from: wraper on September 29, 2020, 09:44:35 pmI think we got mixed semantics - diode's recovery (when the diode turns off, stops conducting) is slow on a 1N4007 like 4usec. They turn on fast though, which is what matters to protect the BJT.OP you could measure the 3.3V rail and see if it sagging when the relays are on (base current is high with no resistors). The AS1117-3.3 will also be getting hot I think because Ethernet transceivers are pigs on power. WIZ5500 needs 150mA alone, plus the ESP32 draws up to 500mA peaks during TX. I always add bulk capacitance to the 3.3V rail, at least 100uF. You have an earth-ground connection on the project? It's needed for the Ethernet cable.I recommend no ground-pour on the relay contact traces, they are considered "dirty" with switching spikes you don't want coupled to your circuit ground and they can be high voltage if switching mains or inductive loads. Snubbers are a hassle but suppress arcing across relay contacts which can cause an MCU to malfunction if inductive loads are being switched.

author: wraper
author_rank: Unknown
timestamp: September 29, 2020, 10:21:51 pm
content: Quote from: floobydust on September 29, 2020, 10:06:42 pmDid not notice that. According to OP there is mains voltage. So ground fill over that area is a big no-no. It's not safe as it is now.Quote

author: DTJ
author_rank: Super Contributor
timestamp: September 30, 2020, 02:13:14 am
content: Hey OP - you have made a pile of mistakes on this but as your first design you've probably done quite well.All of us have made the same mistakes in the past.Just be very careful with mains voltages!

author: bizkits
author_rank: Contributor
timestamp: September 30, 2020, 03:08:51 am
content: Quote from: wraper on September 29, 2020, 10:21:51 pmI am planning to change the way I power the overhead lights currently to using the same way I power the main load. Using a 24VDC OMRON Relay.Hence there will be no mains voltage. Even so, I think I will leave the relay portion without a ground pour.

author: bizkits
author_rank: Contributor
timestamp: September 30, 2020, 03:12:44 am
content: Quote from: wraper on September 29, 2020, 09:44:35 pmI'm sorry but I still don't quite understand.In what applications will fast recovery matter? Are there any examples you could give?

author: wraper
author_rank: Unknown
timestamp: September 30, 2020, 03:31:02 am
content: Quote from: bizkits on September 30, 2020, 03:12:44 amMostly in SMPS. There are other use cases but SMPS makes the vast majority of where fast recovery diodes are used.

author: wraper
author_rank: Unknown
timestamp: September 30, 2020, 03:45:41 am
content: BTW if you have 24V on board, the best would be to use all 24V relays. 5V relays are not that common and consume a lot of current. Not to say it's not the best idea to share the same power between sensitive electronics and things consuming a lot of current and producing current spikes. Needing to step down the voltage to power those relays when you can power them directly from 24V makes even less sense.

author: bizkits
author_rank: Contributor
timestamp: September 30, 2020, 06:53:45 am
content: Thanks everyone for giving your inputs and sharing what can be improved.I have taken most of the advise and will order a new board with the follow schematic attached.1. Mainly I followed the "Standard Application" in the RECOM R785.0-1.0 and added a bypass and decoupling capacitor.2. Grounded all grounds and added a ground pour on both top and bottom layers excluding the areas of the relays, ESP32 antenna and WIZNET 5500 modules.3. Added 1Kohm resistors on the I/O pins which enables the BJT for the relays.4. Changed the 1N4007 diode into a faster diode MUR160.5. I also added a bulk capacitance of 6.3V 100uF Tantalum Bulk Capacitor near the 3.3V of the WIZNET 5500. I did this as the AMS1117 which regulates the 3.3V supply rail may have interferences when the ESP32 pulls more current when switching the relays or transmitting wirelessly.I think these changes is good enough for now and when the board comes, I will do a test to see if it's more stable and reliable.

author: Manul
author_rank: Super Contributor
timestamp: September 30, 2020, 08:35:22 pm
content: Transistors are upside down in the schematic...

author: bizkits
author_rank: Contributor
timestamp: October 01, 2020, 01:37:43 am
content: Quote from: Manul on September 30, 2020, 08:35:22 pmOh my, thank you for pointing that out. I totally didn't noticed that while I was doing up the connections!

author: HwAoRrDk
author_rank: Super Contributor
timestamp: October 01, 2020, 09:36:36 pm
content: I would not snake the 5V rail between the relay coil pins like that, especially given one or more of the relays are switching 220V AC. If you re-arrange the layout like attachment shows, you can avoid running those traces near the output pin of the relay. Also, it gives the opportunity to add some routed slots (purple lines) for extra clearance.