I want to use the following external-interlock schema to control a relay when the interlock terminal is opened or shorted.

The micro-controller does many other things but I restricted the pin-outs to focus on the relay part.

The K1 relay is a non-latching normally open relay. The 5V supply supplies voltage to external interlock control and to the micro-controller as well as to the relay coil. R7 and R8 are there to limit the LED current. R11 and C5 is to prevent bouncing. D1 input detects the interlock ON/OFF state, D2 output goes ON and activates the relay so the 12V power supply turns off. Once the interlock terminals shorted the relay will close contacts and the 12V supply will be ON.

enter image description here

My problem is that I want to make use of another switch (or push button ect) call it SW_New which is coupled to the micro-controller so that the relay acts like a latch. When someone opens the interlock the relay will activate but it will not close again when the interlock is shorted; instead it will require SW_New to be pushed again. I’m a bit confused how I could implement it. What sort of logic or switch/button would be work for such aim?

edit for an answer:

enter image description here

  • 1
    \$\begingroup\$ Do you want to implement the new logic in the uC code (connecting SW_New to a uC pin), or with external logic circuit/devices? \$\endgroup\$
    – AnalogKid
    May 30, 2022 at 13:33
  • \$\begingroup\$ uC code is fine. Not even the C code(I can write myself) I need to know what to do. \$\endgroup\$
    – cm64
    May 30, 2022 at 13:34
  • \$\begingroup\$ If possible with uC solution and a adhoc component(like a special switch or button ect) better for me. \$\endgroup\$
    – cm64
    May 30, 2022 at 13:35

2 Answers 2


What sort of logic or switch/button would be work for such aim?

Any switch, since the latch function will be achieved through software.

If the MCU and relay coil both uses 5V and the MCU pin can source sufficient current, you may be able to drive the relay straight from the MCU. Otherwise use a NPN BJT or some other driver circuit in between. Similarly, if the relay coil needs 12V or 24V (the most common ones), you can solve this too with a circuit in between.

No matter how you drive the coil, you must absolutely use a flyback diode across it. I see none in your schematic.

Don't place the LED in series with the switch. Place it after the switch together with its series resistor and the cathode towards ground. Because there's no apparent need to sink the LED current through the MCU and also you don't want the LED voltage drop to muck up your debouncing and/or button reads. Like this:


simulate this circuit – Schematic created using CircuitLab

R1 = Regulate LED current
R2 = Protect MCU
R3 = Signal pull-down

As for how to write the software:

  • Periodically poll and debounce the switch. For example in a cyclic timer interrupt hitting every 5ms or 10ms. You can use hardware debouncing with a RC filter too but why, since you have a MCU available.
  • Store the state of the button in a variable. Change the state of the variable when the de-bounced button value either goes from low to high (soon as button is pressed) or from high to low (when the button was pressed and released).
  • If you need the state of the relay to persist after MCU reset / power off, then you will need to store the button state in on-chip data flash/eeprom, so if that's a requirement then pick a suitable MCU with data flash.
  • \$\begingroup\$ Thank you for the answer. The relay module takes care of the flyback diode and built in transistors ect. I think I understand what you mean by keeping the state updated by the push button. So I just need an extra push button which also gotta be debounced as well. But I didnt get the series LED part. Could you show me what you mean by wiring the LED proper way? Is it possible to use for you the built in tool for drawing diagram? More clear than sentences sometimes. \$\endgroup\$
    – cm64
    May 30, 2022 at 15:58
  • \$\begingroup\$ "Don't place the LED in series with the switch." When you say switch here do you mean the interlock in my diagram or the switch to be added? \$\endgroup\$
    – cm64
    May 31, 2022 at 7:48
  • \$\begingroup\$ @cm64 It's very basic electronics but I added a schematic. \$\endgroup\$
    – Lundin
    May 31, 2022 at 12:41
  • \$\begingroup\$ I see just wanted to be sure SW1 in your diagram is Interlock terminal in my question correct? \$\endgroup\$
    – cm64
    May 31, 2022 at 12:42
  • \$\begingroup\$ We also talked about reset push button I wanted to be sure what you mean by the SW1 \$\endgroup\$
    – cm64
    May 31, 2022 at 12:43

Here's a simpler solution.

enter image description here

The 12 V relay K1 is energised by the 12 V supply and switches on the + 12 V line.

When the external interlock opens, the relay is de-energised.

The relay is re-energised when the external interlock closes and the restart push button is actuated.

If required the relay contact may be taken as an input to the micro-controller.

The following version has been created to suit your requirements.

enter image description here

The 5 V relay, that switches on the 12 V SMPS, is to be selected from 'high in-rush current' models to avoid contact welding. More details at 230V AC Relay won't switch off and Switch stuck in closed position.

It is energised when the external interlock is closed and the 'restart' push button is actuated.

It is de-energised when the external interlock opens.

  • \$\begingroup\$ But my relay can only be powered by +5Vdc not 12Vdc. And my relay is DC controlled AC relay. See my diagram its contacts are on the Line. Please reconsider your answer. \$\endgroup\$
    – cm64
    May 31, 2022 at 7:51
  • 1
    \$\begingroup\$ My post has been edited to suit your requirements, though it is not standard practice to switch the mains input to the SMPS. You would need to select the 5V relay from 'high-inrush current' models to avoid contact welding. \$\endgroup\$
    – vu2nan
    May 31, 2022 at 11:28
  • \$\begingroup\$ I will use this relay modue download.mikroe.com/documents/add-on-boards/click/relay/… which uses this relay docs.rs-online.com/356b/0900766b80660fe5.pdf In the schematic there are V1 V2 are they thermistor? Can this module handle inrush currents? \$\endgroup\$
    – cm64
    May 31, 2022 at 11:39
  • \$\begingroup\$ G6D relays are not TV rated. G4W relays are. \$\endgroup\$
    – vu2nan
    May 31, 2022 at 12:24
  • \$\begingroup\$ I see maybe thats why they added MOV or thermistor in the module. Btw in your schematic there is two K1 contacts. One is DC one is AC. Its like the relay u use have single coil two switch. Thats not type of relay in question. \$\endgroup\$
    – cm64
    May 31, 2022 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.