Electronic – Activate a 5V relay with a 3V3 GPIO

mosfet

I need to activate a 5V relay with the 3V3 GPIO of an ESP8266.

However the GPIO pin to be used has an additional function as a boot mode select pin for which it must be high at startup, therefore the signal controlling the relay should be high when not activated, and low to activate it.

I was thinking about a P-Channel MOSFET acting as a switch, but any solution with minimum components is welcome.

Best Answer

  1. It doesn't sound right that a GPIO (general purpose input/output) pin needs to be low to indicate the relay should be on. Surely the microcontroller or FPGA driving the GPIO pin can invert the logic internally.
  2. Even if the digital signal is what it is, you can always invert it, then use simple circuits for driving a relay that have been posted many times here on this site. This could be done with a additional transistor, or a explicit digital inverter. Note that single inverters come in the same package that individual transistors come in.
  3. If you use the right part, read that datasheet, and do the math carefully, you should be able to drive a 5 V high side switch from a 3.3 V digital signal. It's easy enough to turn on the high side switch with 0 V. The tricky part is making sure it is off, or at least off enough, with 3.3 V in, while still ensuring sufficient current capability to power the relay at 0 V.

    A PNP with the right resistor divider driving the base should work. But again, you have to design this carefully.

#1 is really the best choice. Just invert the signal in the firmware or logic definition.