MOSFET switch for powering the Arduino

Hi,

I have a project where I want to power the Arduino using a MOSFET.
The idea is that when I push the pushbutton, the Arduino turns on, then the Arduino puts a pin connected to the MOSFET gate HIGH keeping itself powered on. Then (in the code) I want the Arduino to set that same pin LOW when I hold the pushbutton down for 3 seconds.

My problem is that with my circuit, the Arduino power LED is always glowing. The LED glows very dim until I push the button and the Arduino poweres on. The problem is that the ciruit is always leaking power.

Any idea how I can change the circuit for this not to happen? I want the power usage to be 0 when the Arduino is powered off.

From photo (attachment):
P1= Pushbutton (connected to VCC)
A4= Output pin for keeping the Arduino powered on
A3= Pushbutton input

Sorry, can't use Google accounts to post images here (or anywhere else for that matter ...). :astonished:

Paul__B:
Sorry, can't use Google accounts to post images here (or anywhere else for that matter ...). :astonished:

Oh, sorry. I added the photo as an attached file insted

Hi,
OPs circuit;

Tom... :slight_smile:

Hi,
First it is not a good idea to switch the gnd of the circuit off.
You need to switch the positive power side, using a P-CH Mosfet like this.


From Latching Power Switch Circuit (Auto Power Off Circuit) | Random Nerd Tutorials

Google

arduino latching power switch

Hope this helps.. Tom... :slight_smile:

Hi Tom,

Thank you. The guide was very helpful. I was hoping to achieve the same, but with as few components as possible. The circuit will be soldered on a smal PCB in the end with a standalone Atmega328P.
Do you think the circuit can be simplified? :slight_smile:

If you only want to use the Atmega328 and no other devices, why not just put it to sleep?

Virtually no other components required.

Paul__B:
If you only want to use the Atmega328 and no other devices, why not just put it to sleep?

Virtually no other components required.

Its for a headlamp project, so for the circuit to not drain the batteries, I want to cut the power to the Arduino chip.

I suspect the leakage is current flowing through RP1 via the protection diode on A3. You might try moving RP1 over so it grounds to the pre-switch ground (i.e. - pins 3 & 5 of the 328P) rather than to the power supply ground.

You have the same issue if there are any other devices connected to the 328P. Their grounds need to be switched too.

Edit: There is also a current path from A4 through D1 and RGS to ground, and that may be enough to partially turn on the mosfet. These complications argue for using a second transistor as in TomGeorge’s circuit. And you have the added requirement that the pushbutton has to serve as an input to the 328P as well as keep the power on. While there may not be a logical reason why low side switching wouldn’t work, these circuits are typically done using a P-channel mosfet to switch the high side. Attached is a high-side circuit that uses a single GPIO pin. It’s set to INPUT_PULLUP which keeps the power on, but reading the pin will also detect if the pushbutton is being pressed.

ArduSoftPwr.jpg

HansiFansi:
Its for a headlamp project, so for the circuit to not drain the batteries, I want to cut the power to the Arduino chip.

So put the ATMega to sleep. A current drain of 50 μA or so will be comparable to whatever the shelf life drain is of most batteries you would be using for a headlight.

ShermanP:
I suspect the leakage is current flowing through RP1 via the protection diode on A3. You might try moving RP1 over so it grounds to the pre-switch ground (i.e. - pins 3 & 5 of the 328P) rather than to the power supply ground.

You have the same issue if there are any other devices connected to the 328P. Their grounds need to be switched too.

Edit: There is also a current path from A4 through D1 and RGS to ground, and that may be enough to partially turn on the mosfet. These complications argue for using a second transistor as in TomGeorge's circuit. And you have the added requirement that the pushbutton has to serve as an input to the 328P as well as keep the power on. While there may not be a logical reason why low side switching wouldn't work, these circuits are typically done using a P-channel mosfet to switch the high side. Attached is a high-side circuit that uses a single GPIO pin. It's set to INPUT_PULLUP which keeps the power on, but reading the pin will also detect if the pushbutton is being pressed.

Thanks for all the info. I think I will look a bit more at the circuit you provided. If possible, I would need a circuit using less components. I dont have much space on the PCBs for this part.

Paul__B:
So put the ATMega to sleep. A current drain of 50 μA or so will be comparable to whatever the shelf life drain is of most batteries you would be using for a headlight.

I think this could be a good solution, but the problem here will be that the Arduino always will turn on just by connecting the battery.

What about the circuit I have attached? Any thoughts?

HansiFansi:
I think this could be a good solution, but the problem here will be that the Arduino always will turn on just by connecting the battery.

So what? If it is not needed, it will turn itself off again within a second or so. And you are only going to connect the battery the first time you assemble it or replace the battery. The lamp will not turn on yet because you have not pressed the button.

Unless of course, you have! :sunglasses:

Paul__B:
So what? If it is not needed, it will turn itself off again within a second or so. And you are only going to connect the battery the first time you assemble it or replace the battery. The lamp will not turn on yet because you have not pressed the button.

Unless of course, you have! :sunglasses:

Okey, so lets say that I connect the battery, the Arduino tuns on, after 1 second it goes to sleep. Then when I push the button it wakes up again. How do the Arduino then stay on? Wouldn't the code make the Arduino again go back to sleep after 1 second?

Do I put the "1 second sleep" code before the setup or loop? Where in the code will the Arduino be when it wakes up?

I do want to use your method, I just need to see/understand how it will work :slight_smile:

The idea with the battery is that I can connect the battery and then just leave the headlamp (the circuit) without it using power (50uA in sleepmode is ok), then when I after 2 seconds or 2 days press the button the standalone 8mhz Arduino wakes up ready to use.

HansiFansi:
Okey, so lets say that I connect the battery, the Arduino tuns on, after 1 second it goes to sleep. Then when I push the button it wakes up again. How do the Arduino then stay on? Wouldn't the code make the Arduino again go back to sleep after 1 second?

That is called "programming". The Arduino reads the pin to which the battery is connected and accordingly determines whether to put the lamp on for the prescribed period or go to sleep. That's what the code is for.

Incidentally, the waking from sleep is performed by an interrupt - you have to code it so there is an interrupt routine for that pin to handle waking up, before going to sleep.

When power is first applied, your code would set up the GPIO pin as an INPUT_PULLUP, make sure it reads high (you aren’t pressing the button), then set up an interrupt for that pin, then go to sleep.

When you press the button and the interrupt occurs, the interrupt service routine would disable the interrupt for the pin, wait until you’ve released the button, then return from the ISR to the point in your code immediately after you went to sleep, and do whatever you want it to do in awake mode.

Your code would poll the GPIO pin periodically while it’s doing whatever else you want it to do. When it detects that the pin has gone low (you’ve pressed the button), it shuts down whatever you’ve got going on, waits until you’ve released the button, re-enables the interrupt, and goes to sleep.

In power_down deep sleep mode, the processor can draw less than a microamp But other things on the Arduino board can still draw significant current - the voltage regulator, the power-on LED, and the USB adapter chip. The mosfet circuit has the advantage of turning off the power completely to everything. But if your battery supply voltage is within the permissible range for the processor, so that you don’t need a voltage regulator, something like a Pro Mini with the regulator and power LED removed, would get you down to that microamp.

If you want to do the mosfet switch, the attached schematic is the simplest I know of which lets the push-button turn on the power and also be an input while the power is on.

Hi;
@FSharmanP circuit;


Tom.... :slight_smile:

Here's another version of the power circuit. It uses the same number of parts, but uses only one GPIO pin for both input of the pushbutton's state and output to keep the power on. It uses a mosfet as the lower transistor, and the Arduino's GPIO input pullup resistor drives its gate high. But you can also read the pin state to see if the button is being pressed. I haven't actually tried this, but it looks like it ought to work.

ShermanP:
If you want to do the mosfet switch, the attached schematic is the simplest I know of which lets the push-button turn on the power and also be an input while the power is on.

Thanks Sherman.
I will test the first circuit you added. Parts are ordered so I can test on a breadboard before I order the custom PCBs for my project.

Ordered these transistors and mosfets. Should be ok for powering a standalone Atmega328p at 3.3v?