I am not very experienced with relays but I need to control the state of a relay with a PWM signal such that if the microcontroller is damaged and the controlling pin gets stuck in a high or low state the relay will not get power. I am hoping to implement this with passive components only.

In the image below is my circuit with basic control Digital high = relay off and so on. enter image description here

If I add a capacitor between the microcontroller and the transistor I will filter out DC but now I need the transistor to stay open when a PWM frequency is applied, or the relay to say closed.

I have tried to simulate it and found that adding a parallel resistor and capacitor after the transistor helped, but not enough as seen below.

I have also changed the duty cycle but this has little to no effect.

enter image description here The red arrow(red simulated output @ 20KHz) refers to the output from the microcontroller and the blue arrow is the output fed into the relay(blue simulated output).

I have played around with the value of these components and this is as low as I can get voltage (the relay will see) to go.

I am also worried that this might put the relay into an unknown state due to this 3V offset.

I have seen other systems, they use the inherent properties of the inductor in the relay when controlling it with a PWM signal but as this is a 16A relay I am hesitant to do that and I don't want contact welding.

Any help or insight to this design problem is appreciated.

  • 1
    \$\begingroup\$ 1) why would the microcontroller get damaged, would it not be simpler to just prevent that from happening? 2) your design method is "try this, try that" which has a low chance of getting to a good solution. You should take a step back and write down the requirements in a structured way like: PWM present: relay on, No PWM: relay off, MCU output stuck low/high: relay off. Then you could AC couple and rectify the PWM signal to enable an NMOS to switch on the relay. Then another NMOS in series to PWM the relay. \$\endgroup\$ Jul 19, 2018 at 8:57
  • \$\begingroup\$ What you might want is a window comparator and rc filter the pwm to a voltage and have the relay only closed when the voltage is within the middle range \$\endgroup\$
    – PlasmaHH
    Jul 19, 2018 at 9:16
  • \$\begingroup\$ The reason why the micro might get damaged is due to lightning striking the casing, and the relays are also connected to live, so lightning could damage from ant direction. I know the "try this, try that" might not work every time but I got a little desperate. But thank you, you understand what I am asking, should I change my question to the structure you have suggested? Your AC couple suggestion sounds good. Would you mind elaborating? \$\endgroup\$
    – Gareth T.
    Jul 19, 2018 at 9:17
  • \$\begingroup\$ @PlasmaHH the window comparator is an active component, I am trying to stay away from that, for now, but I will consider your suggestion. \$\endgroup\$
    – Gareth T.
    Jul 19, 2018 at 9:20
  • \$\begingroup\$ @GarethT.: then why do you use a transistor? Its an active component too. \$\endgroup\$
    – PlasmaHH
    Jul 19, 2018 at 9:20

2 Answers 2


Feed a square wave from your MCU to this circuit: -

enter image description here

It naturally blocks DC due to the 1 uF capacitor at the input but converts the AC waveform back to a DC level. So if you feed 3.3 volts p-p you will get a DC level on the output of 3.3 volts minus two diode drops i.e. a DC level of about 1.9 volts. If you use schottky diodes it might be more like 2.2 volts.

Next, use a MOSFET with a gate source parallel resistor that would naturally discharge the 10 uF capacitor should the MCU stop sending a square wave. You need to pick a value that doesn't discharge too much between MCU square wave cycles but does discharge in reasonably quick time when the square wave is terminated or lost.

Use the MOSFET to activate the relay but choose a MOSFET that has a low gate-source threshold voltage circa 1 volt.

  • \$\begingroup\$ Good answer. However, given the level of the questioner, might it be clearer if you showed the resistor in parallel with the cap, and the MOSFET? You could also explain that the time constant will be RC, and that you need to select such that RC >> 1/20000, and RC=~0.5*reaction time. \$\endgroup\$
    – colintd
    Feb 22 at 20:58

This sounds really concerning, especially your comments about lightning. It seems like you're attempting a safety-critical design with no knowledge of functional safety. If failure of your device is dangerous (to life or property) you could be opening yourself up to legal liability as well.

As other people have pointed out, you are introducing other single points of failure into your system.

Just on one point here, your processor could fail with the PWM still being output. This could be due to:

  • A logical bug

    • Your software should be written for compliance with EN 61508 or a similar standard.
  • A hardware malfunction

    • Hardware should be designed for compliance with a standard such as EN 61508, there are many other standards that may be required or just simply helpful such as DO-160 for lightning protection.
    • If you are using a relay for a critical function it should be a Safety Relay. What if your relay contacts weld or it simply fails internally? I've seen relays get physically stuck due to a plastic armature part breaking up. Contact welding can happen even after many, many cycles if you have inadvertently made a marginal design (relay contact material choice and snubbing are important).
    • Processors should be protected by supervisory circuits such as Windowing Watchdogs and Power Management controllers. Ideally they would be a safety microcontroller such as TIs Hercules range too.

We don't know your system but if, say, the relay was controlling a heating element you could protect against entering an unsafe condition by including a thermal fuse in the heating package allowing the unit to fail-safe.

Functional Safety is far too broad to cover here but maybe these quick points will be helpful for you to consider.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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