How to drive a relay with an esp8266 - http://arduinotronics.blogspot.com/2018/08/driving-relays-with-esp8266.html

How to drive a relay with an esp8266 - http://arduinotronics.blogspot.com/2018/08/driving-relays-with-esp8266.html

or simpler version, just throw a 2N7000 n-channel logic mosfet in there instead of the opto-isolator+bipolar transistor. a little less isolation, a lot less components, and the relay doesnt need to be a 5v one

@Justin_Mitchell Great idea, thanks! just ordered 50 … https://amzn.to/2PTR3HO

Like this?

missing/deleted image from Google+

I’ve seen plenty of arguments that the gate resistor isn’t necessary, but I often use them anyway. I also use a 1k or more pull-down resistor on the gate to ensure its off unless actively driven

@Justin_Mitchell a gate to ground resistor would be good if the input was disconnected. I have a gate to esp8266 resistor to protect the gpio pin in case of mosfet failure.

On power up if the pin goes tri-state/input then the floating level might be high enough to trigger the MOSFET and engage the relay, for that fraction of a second until your code reconfigures it. as I discovered on one of my projects :slight_smile:

@Justin_Mitchell I’ll add a 10k from gate to ground.