Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By martinayotte
#48704 The PN2222 isn't the best part to do a relay driver, especially if the relay coil requires a lot of current.
It is better to use MOSFET.
Also, about the use of GPIO2 : beware that GPIO2 needs to be pulled-up for proper boot mode, therefore you should consider that idle state of the relay driver should be OFF when GPIO2 is HIGH, so the driver would need an inverting stage, which mean a second MOSFET.
User avatar
By Joe Job
#48773
The PN2222 isn't the best part to do a relay driver, especially if the relay coil requires a lot of current.
It is better to use MOSFET.


Thanks it is a 5V relay, is there any particular MOSFET that is best to purchase? For instance would this one be OK?

http://www.ebay.es/itm/2-Unidades-IRF32 ... SwuAVWu4Vy

Also, about the use of GPIO2 : beware that GPIO2 needs to be pulled-up for proper boot mode, therefore you should consider that idle state of the relay driver should be OFF when GPIO2 is HIGH, so the driver would need an inverting stage, which mean a second MOSFET.


Could you provide a link that goes into more detail of how to accomplish this as I am unsure how to achieve it.
User avatar
By martinayotte
#48777 The MOSFET link you provided is maybe a bit oversized/overrated if your relay is small and doesn't consume much current. Also, the MOSFET need to have low Vgs, below 3V, which is not case in the one you provided.
I would rather use something like AO3402, or 2N7000 if you don't want surface mounted.

The circuit look like, although I would use another MOSFET instead of the 2N3903, with pulldown on its gate :
Image

Beware that some people reported activities on GPIO2 during Reset, but I'm not convince yet, it is known that such activities are present on GPIO0, but for GPIO2, I need to verify. Maybe by adding a capacitor between both MOSFET can prevent that.