Great video! Thank you for the demo and the schematic. the pull-down resistor for the MOSFET can be much larger 10 K - 1 M. You can also use the internal (built-in) LED as indicator instead of tying up pin # 12 and using 2 more components.
Thanks. Interestingly I found (and designed myself) only high side switch with P-MOSFET. It's fine, cause I used it to shutdown SD card reader and it's voltage regulator once. Kind of problem is that if switch is designed to disconnect Arduino from battery to prevent deep discharge and damage of rechargeable batteries, not every MOSFET works. Some may still allow few microamps to flow - either because Vgs(th) is specified for 1mA, or because they conduct a bit all the time and there's some sweat spot - if voltage is close to Vgs they conduct, if voltage is double vgs, they conduct too and when voltage is close to maximum rating (e.g. 60V), there should be current no higher than 1mA. But for similar design I used 1M as a mosfet pullup (here pulldown) and 100k for base of bipolar transistor.
Thanks! Great video. At 11:50 you ask if this draws any current (when not turned on I assume). I could not measure any current on my multimeter, which can measure currents down to 10 uA. In theory, the only current is the leakage of the PNP transistor through the pull-down resistor on the gate. In practice, the battery will die of age (self discharge) :-)
Thanks Robert, my meter has trouble measuring accurate uA currents due to the burden voltage so I have to go with 'in theory' for most things. Thanks for checking it out, I really appreciate it.
You could meassure what the current consumption is when you put the uC to sleep mode and then make a wakeup call via interrupt pin. And compare both metvods. But I'm guessing your solution is more efficient.
The problem with this circuit is short button presses, the micro needs time to boot. Why not add a cap and resistor to artificially prolong the on state after the button press ?
Cool stuff. If you replace the mosfet with a 2n700x (logic level nmos) (edit: oops, bs170 is similar to 2n7000), you can hook its gate to pin 13 via a resistor. The circuit will be the same as before just without the pnp. Why ? because when the avr powers on, the GPIO is in High-Z. The first thing the software needs to do is to turn on the gpio driver for pin13, bring it high. I think. Watched the whole video before responding.
Question: can you not just wire pin 13 directly to the MOSFET gate via a current limiting resistor and pull the pin HIGH to power off the MOSFET? Why use a transistor there? Thanks
Really a detail but you need to show the emitter of the transistor on your schematic. By the way, I'd be interested in a solution to automatically turn on that switch every hour for a battery-powered remote sensor application. Thanks for the video!
I'm not sure I understand... At 5:57 you explain: "The nano, when it boots up, will put pin 13 high". Wouldn't that turn OFF the PNP transistor? Assuming the emitter is on BAT+ (you didn't draw the arrow, but it makes sense), the base should be at least 0.7V more negative than the emitter in order to turn the transistor on. Anyway, thanks for all the great videos. You have inspired me to brush the dust of some 30 years old knowledge... And I might be wrong when it comes to the PNP transistor. It's been a long time... :)
There could be a problem of NANO being held to the "On" state through one of the I/O pins being sinked to BATT-. Might need to separate your peripheral I/O GND from BATT-.
You are absolutely right, they all need to go through the mosfet/nano ground. Or as I wired it in the end the LED needs to go to power with the micro providing the ground path.
+Mark Higgins honestly I cannot remember why, there must have been a reason. I will post a video update with an answer or simplification of the circuit ;-)
It will but you will stuggle to get 300ma through it with 3 AAA batteries on the gate of the mosfet. I would pick something with a lower on resistance.
I couldn't get the circuit to work. The only difference from yours is that I used an Arduino Uno. The MOSFET will power the UNO when the switch is held and then off when released. When I add the transistor and attach it to pin 13 via a 1K resistor, the Arduino remains on after the switch is released. So all working well. However, when I set pin 13 low, digitalWrite(pwrPin, LOW), the Arduino continues to operate. I tried different pins both analog and digital but still no joy. For some reason the transistor will not switch off (open the gate on the MOSFET) once it is powered. The only way I could get this to work is by resetting the Arduino board (I used the watchdog function). But that's not really the way to do it...but I can't find any other way??
I am having the exact same problem. I can turn off the BJT with a push button but not by taking the base down using a digital low from the UNO. Don’t understand why?!
just my opinion. some transistor becomes live when the gate is above 0.7V. the reason why you can't turn it off could be that pin 13 sourced out 0.7V when set to low.
Great video! Thank you for the demo and the schematic. the pull-down resistor for the MOSFET can be much larger 10 K - 1 M. You can also use the internal (built-in) LED as indicator instead of tying up pin # 12 and using 2 more components.
That's a very useful circuit David! Thanks for sharing!
Most LDOs now have EN/SHUTDOWN pin, so its ON/OFF state may be arranged similar way without dropping additional MOSFET into a circuit.
Thanks. Interestingly I found (and designed myself) only high side switch with P-MOSFET. It's fine, cause I used it to shutdown SD card reader and it's voltage regulator once. Kind of problem is that if switch is designed to disconnect Arduino from battery to prevent deep discharge and damage of rechargeable batteries, not every MOSFET works. Some may still allow few microamps to flow - either because Vgs(th) is specified for 1mA, or because they conduct a bit all the time and there's some sweat spot - if voltage is close to Vgs they conduct, if voltage is double vgs, they conduct too and when voltage is close to maximum rating (e.g. 60V), there should be current no higher than 1mA. But for similar design I used 1M as a mosfet pullup (here pulldown) and 100k for base of bipolar transistor.
Neat circuit!
Nice idea! Gonna have to implement this if I ever make something battery powered I want to have soft on-off switches :D
Thanks! Great video. At 11:50 you ask if this draws any current (when not turned on I assume). I could not measure any current on my multimeter, which can measure currents down to 10 uA. In theory, the only current is the leakage of the PNP transistor through the pull-down resistor on the gate. In practice, the battery will die of age (self discharge) :-)
Thanks Robert, my meter has trouble measuring accurate uA currents due to the burden voltage so I have to go with 'in theory' for most things. Thanks for checking it out, I really appreciate it.
I have seen many TH-cam videos, perhaps this is the best and easiest, love your work bro ,keep it up!
You could meassure what the current consumption is when you put the uC to sleep mode and then make a wakeup call via interrupt pin. And compare both metvods. But I'm guessing your solution is more efficient.
The problem with this circuit is short button presses, the micro needs time to boot.
Why not add a cap and resistor to artificially prolong the on state after the button press ?
Cool stuff. If you replace the mosfet with a 2n700x (logic level nmos) (edit: oops, bs170 is similar to 2n7000), you can hook its gate to pin 13 via a resistor. The circuit will be the same as before just without the pnp. Why ? because when the avr powers on, the GPIO is in High-Z. The first thing the software needs to do is to turn on the gpio driver for pin13, bring it high. I think. Watched the whole video before responding.
Question: can you not just wire pin 13 directly to the MOSFET gate via a current limiting resistor and pull the pin HIGH to power off the MOSFET? Why use a transistor there?
Thanks
It is more power efficient.
Could this be modified to work with 3 switches then tell which switch was pressed to start the power?
What happens when the button is held closed indefinetly? Like using it for a mailbox door sensor, and the door is left open? Thanks
I guess the MOSFET gate current is little high. I recommend a resistor between BJT emisor and Gate terminal of mosfet.,
Really a detail but you need to show the emitter of the transistor on your schematic. By the way, I'd be interested in a solution to automatically turn on that switch every hour for a battery-powered remote sensor application. Thanks for the video!
Why not only MOSFET and PIN 13 (gate) to be high when microcontroller is ON?
You can swap the functions of pin 12 and 13 to save a resistor and a led by using the built-in led. ;)
Not quite as visual in the video though :)
Okay . Is very Good Circuit.
I'm not sure I understand... At 5:57 you explain: "The nano, when it boots up, will put pin 13 high". Wouldn't that turn OFF the PNP transistor? Assuming the emitter is on BAT+ (you didn't draw the arrow, but it makes sense), the base should be at least 0.7V more negative than the emitter in order to turn the transistor on. Anyway, thanks for all the great videos. You have inspired me to brush the dust of some 30 years old knowledge... And I might be wrong when it comes to the PNP transistor. It's been a long time... :)
Sorry, you are right, it seems I mis-spoke when I said High, I meant low.
thanks man, i was thinking the same!
where is the Code to this?
There could be a problem of NANO being held to the "On" state through one of the I/O pins being sinked to BATT-. Might need to separate your peripheral I/O GND from BATT-.
You are absolutely right, they all need to go through the mosfet/nano ground. Or as I wired it in the end the LED needs to go to power with the micro providing the ground path.
Why are you using a transistor to drive the mosfet gate and not just the uC pin itself? Is it just because it's not logic level?
+Mark Higgins honestly I cannot remember why, there must have been a reason. I will post a video update with an answer or simplification of the circuit ;-)
Mark Higgins if its a 9v batterie you would probably kill the arduino by feeding 9v to its pin once you press the button, I think.
Mark Higgins I was thinking the same. As long as you're not pushing more than 5v across the switch the transistor isn't required.
If the 9V is a problem, a resistor in series and the protection diodes in the micro should keep the levels safe.. Right ?
I too think that connecting the pin 13 directly to the gate of the MOSFET would able to do the trick
Nice.
i usually connect limiting resistors to the anode side of leds, is it the same putting them on the cathode? thanks :)
+squalazzo yeah it is exactly the same.
Please measure the current :)
Hi david, the 2N7002 work for this circuit?
It will but you will stuggle to get 300ma through it with 3 AAA batteries on the gate of the mosfet. I would pick something with a lower on resistance.
David Watts Which mosfet do you recommend? please
The IRLML2502 or something of a similar spec would be good.
Why is it 11 degrees? That is not very comfortable!
I cannot get it to work
I couldn't get the circuit to work. The only difference from yours is that I used an Arduino Uno. The MOSFET will power the UNO when the switch is held and then off when released. When I add the transistor and attach it to pin 13 via a 1K resistor, the Arduino remains on after the switch is released. So all working well. However, when I set pin 13 low, digitalWrite(pwrPin, LOW), the Arduino continues to operate. I tried different pins both analog and digital but still no joy. For some reason the transistor will not switch off (open the gate on the MOSFET) once it is powered. The only way I could get this to work is by resetting the Arduino board (I used the watchdog function). But that's not really the way to do it...but I can't find any other way??
I am having the exact same problem. I can turn off the BJT with a push button but not by taking the base down using a digital low from the UNO. Don’t understand why?!
just my opinion. some transistor becomes live when the gate is above 0.7V. the reason why you can't turn it off could be that pin 13 sourced out 0.7V when set to low.
I want to increase time to 4 hours. I want to use it to switch off my cooler after 4 hours of running
im a bit late but did you implement a timer to keep track of any last input/activity?
Just keep HIGH the pin connected to base of transistor (eg. Pin 13) for 4 hours. You need to program the Nano to do this.
Please send circuit and code please