Is my circuit correct? - Page 1
Forum section: electronics / beginners

author: redgear
author_rank: Frequent Contributor
timestamp: August 25, 2020, 08:48:19 am
content: I am trying to send the trigger signal to the ULN2003A only if the switch are closed and there is a trigger from microcontroller. I used a two input AND gate and connected the output from switch and micro to its input. I want to know if this is the correct way to do it or is there a better way?Thanks

author: george.b
author_rank: Frequent Contributor
timestamp: August 25, 2020, 01:08:13 pm
content: You'd probably want to debounce those switches. Use a small capacitor between SWOUT and ground.Also, unless you need the µC to know the state of SWOUT independently, you could connect those switches to TRIG instead of +5V, so you wouldn't need the AND gate.

author: Renate
author_rank: Super Contributor
timestamp: August 25, 2020, 01:29:27 pm
content: You're doing an overall 3 input AND, two switches and this TRIG signal.Depending on safety consideration and whether this is some fail safe, you could do this logic anywhere.Me? I'd feed the two switches separately to the µP and do the logic there.This would also give you the benefit of identifying switch failures.OTOH, if this goes to a detonator you want to have the logic near the output.You could put the two switches on the output of the ULN2003 or even after the relay.

author: Manul
author_rank: Super Contributor
timestamp: August 25, 2020, 01:48:50 pm
content: It is good to have debounce on a switch. Software or hardware. If you use software debouncing, then you do not need AND gate, you can write this logic in your code and just output signal to drive ULN2003A.If this switch needs to act independently from code, then you need to add hardware debounce. But simple debounce like resistor and capacitor will produce slow edges, so you need to use a gate with schmitt trigger inputs.

author: redgear
author_rank: Frequent Contributor
timestamp: August 26, 2020, 04:01:46 am
content: The AND gate is a fail safe mechanism for the circuit. I want the power to the relays to be cut-off when the switches are opened. The micro checks if the switches are closed and then if the start button is pressed, turns on the relay. But in the case of the micro failing(stuck in the infinite loop, I use the internal WDT but still want to be safe) or something, I want to be able to cut-off the supply once the switches are opened. Thus, the AND gate. I'm open to suggestions and would like to if there is a better way to do it.Quote from: george.b on August 25, 2020, 01:08:13 pmThank You! Will a 0.1uF cap be enough? Yes, the microcontroller should be able to read the output from the switches.Quote from: Renate on August 25, 2020, 01:29:27 pmThank you. I have the micro controlling the logic already. This is a fail safe backup.Quote from: Manul on August 25, 2020, 01:48:50 pmThank You. I will check out gates with schmitt trigger inputs.

author: george.b
author_rank: Frequent Contributor
timestamp: August 26, 2020, 07:09:26 am
content: Quote from: redgear on August 26, 2020, 04:01:46 amIt should be enough. As Manul said, that simple solution does produce a slow edge - not that it has been a problem for me before, but if it's as safety-critical as you make it sound, then go for proper debouncing with hysteresis.

author: redgear
author_rank: Frequent Contributor
timestamp: August 26, 2020, 01:10:58 pm
content: Quote from: george.b on August 26, 2020, 07:09:26 amI am also thinking to connect the output from the switch to relay's 5v supply directly, that way the relay will be activated only if the switches are closed. Is it a reliable way to do it?

author: Manul
author_rank: Super Contributor
timestamp: August 26, 2020, 02:52:36 pm
content: Quote from: redgear on August 26, 2020, 01:10:58 pmFor sure could be a good way. This idea needs to be considered. The good thing is that it is a true cutoff and will work even if gate or relay driver fails horribly. Negative is increased contact wear because of more current and back emf if switch is operated while the driver is driving a relay.

author: redgear
author_rank: Frequent Contributor
timestamp: August 27, 2020, 03:52:50 am
content: Quote from: Manul on August 26, 2020, 02:52:36 pmIt is a safety cut-off switch, under normal conditions it should be operated only when the relay is OFF. But rarely, it can be operated when the relay is ON. Will a diode or something help reduce back-emf?

author: george.b
author_rank: Frequent Contributor
timestamp: August 27, 2020, 01:11:02 pm
content: Quote from: redgear on August 27, 2020, 03:52:50 amWell, there's nothing stopping you from using a transistor to drive the relay instead of driving it directly from the switches, in which case a flyback diode becomes a necessity.

author: redgear
author_rank: Frequent Contributor
timestamp: August 29, 2020, 04:21:01 am
content: Quote from: george.b on August 27, 2020, 01:11:02 pmDriving the relay is not the problem, implementing a fail-safe is. Can the 5v from switches be used to power the relay directly?Something like this:

author: george.b
author_rank: Frequent Contributor
timestamp: August 29, 2020, 06:40:37 pm
content: I'm not entirely sure of what you're aiming to achieve, or how the relay fits in, it's not entirely clear to me from your last picture, but I gather you meant energizing the relay directly from the switches. I don't know what kind of switches or relay you're using and what their ratings are. I might be missing the point entirely, but I was thinking of something like in the attached picture.

author: redgear
author_rank: Frequent Contributor
timestamp: August 30, 2020, 04:31:16 am
content: Quote from: george.b on August 29, 2020, 06:40:37 pmThank You!The relay will energised by a ULN2003A driver. I am trying to provide the 5v supply for the relay directly from the switches. So even if micro fails, they relay's 5v supply is cut as soon as the switches are opened. Will removing the 5v supply while the relays coils are energized cause any problems?

author: george.b
author_rank: Frequent Contributor
timestamp: August 30, 2020, 01:17:38 pm
content: Quote from: redgear on August 30, 2020, 04:31:16 amDepends on how you wire up the ULN2003's pin 9. If you keep it tied to the rail (as in your schematic), then you should add a flyback diode directly anti-parallel to the relay coil. By opening the switches to cut the +5V, you're disconnecting the ULN2003's internal flyback diodes also, and that could cause problems. Also adding snubber capacitors parallel to the switches wouldn't hurt. If you're tapping the signal from the switches/relay to the microcontroller, it might be wise to clamp the signal, just in case (e.g. with a 5.1V TVS or at least a zener).

author: redgear
author_rank: Frequent Contributor
timestamp: August 30, 2020, 02:53:02 pm
content: Quote from: george.b on August 30, 2020, 01:17:38 pmThis is what I have in mind. Will this work without any reliability or safety issues?

author: george.b
author_rank: Frequent Contributor
timestamp: August 31, 2020, 06:18:52 pm
content: Quote from: redgear on August 30, 2020, 02:53:02 pmI'm afraid that's not going to work at all. 5V through a 10k resistor is 0.5mA, which is not enough to drive a relay. The TE PCH relay you're using requires 80 times that current. Check the ULN2003 datasheet - the drivers are common emitter. You won't get the 5V for the relay from the ULN2003. You should probably revert to the previous idea, with the caveats I've stated, and let the 5V for the relay come through the switches (and go to ground through the ULN2003).

author: redgear
author_rank: Frequent Contributor
timestamp: September 01, 2020, 05:17:24 am
content: Quote from: george.b on August 31, 2020, 06:18:52 pmThank You. If I wire the 5v from the switch directly to the relay, how can I detect the state of the switch with the microcontroller?

author: Ian.M
author_rank: Super Contributor
timestamp: September 01, 2020, 07:53:50 am
content: Feed the top end of the relay coil from 5V through the switches. Add a Schottky diode to ground, cathode positive to clamp the back EMF when the switches open. Add a 1K pulldown resistor at the switched top end of the relay coil and use a 10K resistor from that point to your MCU input to sense the switch state. DO NOT switch the 5V to the ULN2003 clamp diode pin.

author: redgear
author_rank: Frequent Contributor
timestamp: September 01, 2020, 08:35:41 am
content: Quote from: Ian.M on September 01, 2020, 07:53:50 amThank You!Did I do it right?

author: Ian.M
author_rank: Super Contributor
timestamp: September 01, 2020, 08:44:48 am
content: Looks good. I assume relay pin 1 is going off to your ULN2003, so doesn't need a separate clamp diode.

author: redgear
author_rank: Frequent Contributor
timestamp: September 01, 2020, 08:54:41 am
content: Quote from: Ian.M on September 01, 2020, 08:44:48 amYes, relay pin 1 is connected to the output of ULN2003A.

author: Ian.M
author_rank: Super Contributor
timestamp: September 01, 2020, 08:59:47 am
content: You'll probably want a smallish capacitor to ground at the MCU pin for debouncing, or at least to filter EMI.N.B. A buffer or MCU input following a RC filter for debouncing *MUST* have hysteresis (i.e. be a Schmitt trigger type input).You should probably (re)read Jack Ganssle's excellent article on debouncing:http://www.ganssle.com/debouncing.htmespecially part 2 where he covers RC hardware debouncers.

author: redgear
author_rank: Frequent Contributor
timestamp: September 01, 2020, 09:03:16 am
content: Quote from: Ian.M on September 01, 2020, 08:59:47 amThank you. I will read the article. But would I still need hardware debouncing if I debounce the presses on software?

author: Ian.M
author_rank: Super Contributor
timestamp: September 01, 2020, 09:35:08 am
content: No, but you probably do need some EMI filtering so the pin doesn't glitch when the relay switches or due to EMI pickup on the button wiring..

author: redgear
author_rank: Frequent Contributor
timestamp: September 01, 2020, 09:39:49 am
content: Quote from: Ian.M on September 01, 2020, 09:35:08 amI have 0.1uF and 4.7uF caps between all VCC and GND pins on the MCU. Is that enough? Do I need caps on the ULN2003A as well?

author: Ian.M
author_rank: Super Contributor
timestamp: September 01, 2020, 10:29:40 am
content: The ULN2003A doesn't need a decoupling cap, as it doesn't even have a Vcc pin!I'd recommend 1nF to ground at the MCU's switch sense input pin which will form a low pass filter with a corner frequency of 16KHz, filtering out most EMI pickup. If the pin has a Schmitt trigger input characteristic, you can increase this capacitor for a suitable hardware debouncing time constant as per J Ganssle's article, and make your software simpler. If not, don't, as increasing the capacitor may cause problems with the digital input not transitioning fast enough.

author: redgear
author_rank: Frequent Contributor
timestamp: September 01, 2020, 10:34:33 am
content: Quote from: Ian.M on September 01, 2020, 10:29:40 amThank you:)One more question, the relay's datasheet recommends a Zener diode + Diode to supress surges between relay pin 1 and the 5v. Do I need it?

author: Ian.M
author_rank: Super Contributor
timestamp: September 01, 2020, 10:58:45 am
content: No, the diode(s) are built into the ULN2003. Simply return the ULN2003 common cathode pin to +5V via a resistor equal to the relay coil resistance if you aren't going to switch off multiple relays at the same instant, or via a 4.7V Zener, cathode to common if you are.

author: redgear
author_rank: Frequent Contributor
timestamp: September 01, 2020, 11:31:38 am
content: Quote from: Ian.M on September 01, 2020, 10:58:45 amAlright, Thanks