Electrical – N-channel MOSFET used to control 5V relay from 3.3V ESP8266 pin

3.3v5vmosfetrelay

Today I "played" with a relay for the first time.

I only had an N-channel MOSFET available (an IRLZ44N) and wanted to control the relay from an ESP8266's GPIO pin – i.e. use a 3.3V signal to control the relay's input pin, which expects 0 or 5V.

ESP8266 controlling a 5V relay with an N-channel MOSFET

  • I had a 10K resistor handy, so I used it to current-limit the fet's Gate. To my understanding, MOSFETs only care about voltage, not current – so a "big" current limiter at the gate shouldn't matter anyway.

  • When the IRLZ44N is off, the relay's input is connected to the 5V over R1 – and when it's on, the input goes to ground. At that operational mode a resistor is needed; without it, the 5V would end up going directly to ground.

The circuit works – I tested it and the relay responds as expected. But measuring voltages, I saw that the voltage after R1 is not 5V; it's less, since some current goes in the relay's input. In doing so, the voltage drops from 5V to 3.5V; there's approximately 5mA going in the relay's input, and 1.5V ends up being wasted on R1.

It seems that if I had used a larger R1, the circuit wouldn't work – the voltage would drop too far. And as-is, 3.5V may be a marginal situation for the relay. EDIT: Using the 3.3V signal from the ESP directly on the IN1 input doesn't trigger the relay – so it seems the 3.5V we reach with this circuit is indeed borderline

Another disappointing thing about this circuit: when the relay is off, we waste current through R1.

Can you guys recommend a better circuit to use with my IRLZ44N, to turn the ESP8266's 3.3V to 5V and optimally control my relay?

Thanks in advance.

Best Answer

I found the following schematic on this website. Its likely incorrect in some parts though, as S8550 is a PNP part, they probably meant S8050.

enter image description here

Since you stated that directly plugging a 3.3V signal didn't work, you can try one of the following (considering your N-FET limitation):

  • Use your IRLZ44 to directly drive the relay
  • Put a resistor in parallel with R3, to increase the current going into the NPNs base and try to trigger it with 3.3V again.

p.s.: I hope you aren't actually connecting GND to AC with your relay as it could be quite unpleasant/dangerous:

enter image description here