Powering on/off a module


i have an arduino mega that can output 5v and 3.3v
i am powering the arduino through the usb of my pc

arduino has an rfid that reads my card and sends data to my server thanks to a wifi module (esp8266-12f).
this all works great so far.
in order to save power since i plan to power it through batteries later on, i want to power off the wifi chip (which requires 3.3v) and to power it on programatically only when I scan a card.
i am struggling with how to wire the esp chip to make this work.
I have in hand PN2222A BJT, and also have an NPN MOSFET that i tested working with Voltage treshold 3v. If I plug the mosfet gate to a digital output pin of the arduino, i can drive the pin HIGH/LOW with software to send either 0v or max voltage (that should be around 4.5V). I believe that would trigger the mosfet ON, but the mosfet would turn OFF as soon as the current starts to flow from drain to source (considering it is high side mosfet) because I need Vgs at 3v minimum.
Any guidance in making such a thing work would be appreciated.

PS: I know esp has deep/light sleep modes but I really want to make it completely power on or off with a transistor.


For a high side switch you need a P channel MOSFET, you drive the gate low to turn it on.

You also need to pay attention to the other connections between the Mega and the ESP8266 because there is the risk of phantom powering when the ESP8266 is not powered. To avoid phantom powering make sure all the connections from the Mega to the ESP8266 are low before you turn the power off. Note that if you are using serial the idle state for serial is Tx high, so you need to end the serial connection, make the Tx an output, make it low then turn off the power.

That does make sense. thank you for the info and for the additional valuable details.
I do not have any P channel MOSFET.
So i plan to use a low side switch with N channel MOSFET.
Here is how I intend to wire it :

  • ground and pulled down pins/wires that go from the esp to the arduino will be removed an be soldered to N-MOSFET's drain instead.
  • a digital pin of the Arduino that i can write high 5V/low 0V via software will go to N-MOS's gate.
  • N-MOS's source will go to arduino ground.

Would this be OK? Since this mosfet's source will always be 0V, it will be easy to reach Vgs with a digitalwrite(gatePin, HIGH), right?
This way I would not even have to worry about pulling down all esp's inputs (like the tx you suggested), right?

If this is all OK, here is an other question : I've seen schematics for this configuration where people attach a pull down resistor between the gpio and the gate. Why is that and how do I calculate it?

If you do as you suggest then you still have to take care of the risk of phantom powering, but this time the risk that other connections to the ESP8266 provide a path to ground. You have to ensure that every other connection into the ESP8266 for whatever purpose is at the ESP8266's Vcc voltage. You need to give this some thought as the ESP8266 itself runs on 3V3 but many (perhaps all) the boards you buy are powered at 5V and have an on board regulator. Disconnect the 0V and you have a problem to solve: do you set the pins at 3V3 or 5V? I don't know the answer to that, but I can see it getting messy very quickly.

Buy a P channel MOSEFET.

The resistor is to make sure that the gate is pulled low when the output of the Arduino is an input, which it is when it first powers up until some code changes it to an output. Whether that matters or not depends on what the external circuit does, only you can judge that. There is no calculation, use a 10k resistor.

Welcome to the forum.

Have you worked out how much power your RFid module uses, especially during reading a card?

Thanks... Tom... :grinning: :+1: :coffee: :australia:

@PerryBebbington I did not understand that part "Disconnect the 0V and you have a problem to solve: do you set the pins at 3V3 or 5V?"
I tried the low side switch with N MOSFET : it seems to work but the rfid read stops reading after 2 or 3 readings. There must be some voltage wandering around when i switch on/off the esp or something, i have not managed to debug it yet.
Does the voltage I apply to the gate matters? in my mind, that works almost like a relay, but i'm starting to think having 5v at gater but 3.3v at Drain is not OK. I will try more today and need to read/watch educational content about mosfets.

@TomGeorge Hi. Thanks. I mesured it for you Streamable Video
so, 15mA at most at idle, 20mA at most when reading UID (I halt reader before it spits whole sectors/blocks as I authenticate solely on UID). Maybe even a bit less at idle in practice since i parameterized polling rate of reader at 150 ms instead of every loop(). No better benchmarks/optimization as of now since I'm just prototyping.

wifi chip : 70mA idle (station mode, while connected to my home AP), 200-220mA max when sending data.

If you disconnect the 0V, as you are doing with a low side switch, then you have to make sure there is no other way the ESP8266 can get 0V through its other pins. If, for example, there is an input on the ESP8266 connected to an output on the Mega, and that output is low, then there is a route to 0V through the ESP8266's protection diodes, the pin to 0V on the Mega, powering up the ESP8266 and probably damaging the pins on both boards. The solution is to set the Mega pins high, but which high? 3V3 or 5V? Well, it's a Mega so it can only be 5V. Getting messy.

Of course it matters! Remember to measure with respect to the source, not 0V. You said:

(I)have an NPN MOSFET that i tested working with Voltage threshold 3v.

If you mean the gate threshold is 3V then it's not a logic level MOSFET, you need one that is fully on by 5V. The gate threshold is the voltage at which it is just ever so slightly on, no use for logic. Many logic level MOSFETs have an L in the part number to indicate that they are logic level. What MOSFET do you have?

See above. Fix the obvious problems before looking for anything else.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

@PerryBebbington mosfet is 80R450P

@TomGeorge here is my circuit right now https://i.imgur.com/oyyvjrb.jpg
following Perry's comment, I tried to power my mosfet through my bench psu instead of the arduino's 5v output pin. I'm really not confident at all regarding the wiring if my mosfet with my psu (especially Drain to ground of psu?), but i can tell you this work perfectly fine at 7 volts : rfid can read anytime, and esp can send data to cloud depending if i power on/off my psu.
So Perry seems to be right, I need an N mosfet that triggers earlier (logic level) if i want to keep this low side switch architecture.

Not logic level, so not really suitable. I mean, if it does what you want and it's all you have then by all means use it, but there are far better MOSFETs for micro-controller projects. Do you really need a Vds of 850V? (No, you don't!). Rds of 0.45Ω is not very good either.

How about IRL530/540?

@PerryBebbington I ran a few more tests today and this mosfet actually works fine and triggers at 4.0V as well, so I should definitly be able to controle it on/off through the arduino's digital output (I mesured 4.75V output from the MEGA).
Btw I use this mosfet because that's all I have in hand with lowest Vth. Those are salvaged from PCBs people throw to trashbins, not purchased.
This all works fine when this mosfet is powered via my bench PSU. But it fails when I power it through the MEGA. It actually works fine the very first time (card reader can read once), but then the reader kind of freezes and refuses to read (loop() still goes on and on fine as I put an led to verify it blinks).
It's like my rfid reader's Ground does not like sharing the same Ground with my mosfet (Source pin of the fet).
This is where I am stuck for now.

Please post your schematic in the forum, not a link to it. You should be able to drag and drop it into a reply.