I'm using a ESP8266 to activate a siren. The siren is activated thru a 5V relay, and the 5V relay is connected to a transistor, the transistor is connected to a pin of the ESP8266. The power supply of the ESP8266 failed and it hung, in this state the pin went high and the relay was triggered.

I was wondering if there is someway to trigger the relay with some kind of code, not just voltage, as a safety mechanism to avoid activation due malfunction. My first idea was replacing the transistor with a cheap microcontroller, like an ATmega 88p.

Is there a more robust way for doing this?

  • 4
    \$\begingroup\$ Welcome to EE.SE. Schematics are better than words. There's a button on the editor toolbar and it's easy to use. \$\endgroup\$ – Transistor Nov 3 '17 at 22:18
  • 1
    \$\begingroup\$ yeah, why would a transistor malfunction? Why would it malfunction more likely than a microcontroller, which is literally made out of thousands upon thousands of transistors? You should really share your circuit. \$\endgroup\$ – Marcus Müller Nov 3 '17 at 22:22
  • \$\begingroup\$ was it a MOSFET transistor? You can just put a pull down resistor (or pull up if it's PFET high side switch you have, but i doubt it) to make sure the gate of the N-channel MOSFET can't float high and accidentally latch on \$\endgroup\$ – KyranF Nov 3 '17 at 22:37
  • \$\begingroup\$ The transistor is necessary to trigger the relay. The ESP8266 cannot source (or sink) enough current on its own. Depending on the siren power requirements, you might not even need a relay, just use a power-FET as the switch. \$\endgroup\$ – Kurt E. Clothier Nov 4 '17 at 2:59
  • 1
    \$\begingroup\$ @KurtE.Clothier: agreed, another microcontroller is not going to help. The simplest possible solution might be to just add a pull-down resistor on the GPIO that is just strong enough to overcome whatever is pulling up the pin on power-off. \$\endgroup\$ – Dean Franks Nov 4 '17 at 5:06

For critical systems, a failsafe circuit is used that has to be toggled continuously to activate the relay.

The GPIO pin is toggled in the main software loop (typically) after doing all the normal processing. If the loop stops, the toggling stops and the relay is deactivated.


simulate this circuit – Schematic created using CircuitLab

C1 blocks DC from the GPIO pin, C2 and R1 form a low pass RC filter that determines how long the output will stay active when the toggling stops (and removes the ripple from the AC component that is passed by C1 and rectified by D2).

You can simulate this using the above schematic or recreate in LTSpice or similar to see how the circuit works.

The values of C1, C2 and R1 are dependent on the GPIO toggling frequency.

  • \$\begingroup\$ Was about to suggest the same thing \$\endgroup\$ – Mike Nov 3 '17 at 23:01
  • \$\begingroup\$ A poor solution since it simply adds more components that could fail, and does not address the primary component failure ....the driver FET or transistor. The correct way is to use the WDT and driver sensing. \$\endgroup\$ – Jack Creasey Nov 3 '17 at 23:12
  • \$\begingroup\$ The concern was power supply failure or software failure on the ESP8266. Using a solid state driver with fault monitoring instead of the relay addresses the issue of relay or driver transistor failure. There are many parts available for automotive use that would fit the bill and are designed to fail open but also have short circuit and overcurrent detection \$\endgroup\$ – Dean Franks Nov 3 '17 at 23:49
  • \$\begingroup\$ @JackCreasey The micro controller (and WDT) are more likely to fail than a non power-handling transistor. That's a nice solution, but passive components should always be the fail safe. \$\endgroup\$ – Kurt E. Clothier Nov 4 '17 at 2:55

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.