How to cut power to Arduino after a set time? - Page 1
Forum section: electronics / general

author: engineheat
author_rank: Frequent Contributor
timestamp: February 12, 2019, 04:16:44 am
content: I got an Arduino application that uses a 16X2 LCD and a ULN2003 darlington array for driving a stepping motor. After the user start the program, there is a wait of 5 min, and the stepper motor performs an action, afterward I want to cut power to everything to save energy. This is because the program don't need to be ran again for days.I know with the Pro Mini you can go into deep sleep but the LCD and Darlington will still draw significant current I think. I plan to power them all from a 5V source. It'll be nice if there is a mechanical timer that can cut power via hardware, by literally opening the circuit from the 5V power source.I heard you can use MOSFET or relays for this. Not sure how those work. The goal is to have no power consumption after the stepper motor has performed its action. Next time, the user can just power everything back up to restart the program. Then the user can walk away without having to remember to power off everything.What's the easiest way to do this?Thanks

author: RobertHolcombe
author_rank: Frequent Contributor
timestamp: February 12, 2019, 04:44:10 am
content: Are you using an Arduino board, or is it a custom PCB?Does the current draw after the power-off event have to be zero, or is having a relatively low current draw from the micro, and zero draw from the additional circuits acceptable?https://playground.arduino.cc/Learning/arduinoSleepCode

author: jackthomson41
author_rank: Regular Contributor
timestamp: February 12, 2019, 08:06:20 am
content: Quote from: engineheat on February 12, 2019, 04:16:44 amI think you can do that by using arelay. Relay will cut off the external source but then someone has to start it again. It won't get started automatically. You can check thisRelay Interfacing with Arduino.

author: sleemanj
author_rank: Super Contributor
timestamp: February 12, 2019, 08:44:42 am
content: It sounds like you are planning to have these plugged into the wall. In which case, I would just go into deep sleep, any remaining power usage is negligible in terms of costs, probably you'll be left with maybe 30mA at 5v, which is 0.15W, it's just not even worth worrying about when you are plugged into the wall, even if you were off-grid.If you are running on battery however, then yes you would want to get that down. Supply power directly to the 5v pin of the Nano/Pro-Mini, and cut the legs of it's regulator (it sucks for low power). Use an N-Channel mosfet as a switch for the grounds of the display and the ULN2003, a 2N7002 will do probably, google "mosfet as switch" to educate yourself there, And then when it comes time to sleep, put all the pins to INPUT mode disable brown-out detection if it is enabled, and go into deep sleep.Since you are using arduino, my SimpleSleep library does what it says in the name.https://github.com/sleemanj/SimpleSleep

author: Peabody
author_rank: Super Contributor
timestamp: February 12, 2019, 03:47:54 pm
content: You can use a circuit usually made up of two transistors, a momentary switch and a few resistors that will let you push the button to turn on power, and then your Arduino can keep track of the time and turn the power off after a delay. I'm not where I can draw right now, but basically you run all the power throught a P-channel mosfet with its gate tied to the input power rail through a high-value resistor (which keeps the mosfet turned off normally). Also connected to the gate is the push button to ground. And then another transistor, probably an NPN, also connects the mosfet gate to ground, but its base is driven through a resistor by an Arduino I/O pin.So you push the button long enough for the Arduino to power up and turn on the NPN, which keeps the power on after you release the button. Then when the Arduino is ready, it just turns off the NPN and the power is shut off.A slightly more complicated circuit would let you also use the push button as an input after the power turns on.

author: mvs
author_rank: Frequent Contributor
timestamp: February 12, 2019, 04:16:12 pm
content: Quote from: engineheat on February 12, 2019, 04:16:44 amDarlington is a BJT transistor, if you do not supply any base current from arduino it will remain closed with almost 0 consumption.16x2 LCD draws around 1-2mA if you do not use backlight. You can supply power to it directly from arduino pin, no need for external transistor.

author: Peabody
author_rank: Super Contributor
timestamp: February 12, 2019, 05:04:00 pm
content: Attached is the kind of circuit I was talking about. It's possible the first resistor coming out of the GPIO port could be eliminated if the pin is configured as an Input with pull-up resistor. It's also possible that the pull-down resistor on the NPN base isn't needed, but you just don't want any noisy environment to generate something that might somehow turn on the NPN.And as mentioned by sleemanj, you would want to get power from something other than the USB port for this to be practical - unless one of the Arduino models somehow lets you break out the USB V+ line so you can run it through an external circuit. Better to bring in raw 9V or whatever, or regulated 5V, to the appropriate Arduino pin.

author: engineheat
author_rank: Frequent Contributor
timestamp: February 12, 2019, 07:58:21 pm
content: Quote from: mvs on February 12, 2019, 04:16:12 pmSo pretty much if the Arduino is in deep sleep, the Darlington will draw essentially 0 current, and that also applies to the LCD if I power it from the Arduino pin?thanks

author: Doctorandus_P
author_rank: Super Contributor
timestamp: February 12, 2019, 08:56:00 pm
content: The ubiquitous "transistor tester" has a power swich circuit similar to what Peabody posted, but made out of BJT's instead of a MOSfet.BJT's are often better in this regard. MOSfets tend to have a leakage of 1uA between gate & drain while I cant measure the leakage (In the Off-state) of my transistor tester with the equipment I have, its << 0.1uA.Power of a HDD44780 LCD is probably low enough to be driven from an AVR pin, but not the backlight. You may want to insert a transistor here as a power switch.Also: If you switch part of your ciruit off,then you must make sure that the I/O pins of you uC can not source current into the I/O pins of the external circuit.

author: engineheat
author_rank: Frequent Contributor
timestamp: February 13, 2019, 02:20:08 pm
content: Quote from: Peabody on February 12, 2019, 05:04:00 pmAppreciate the drawing. I need a bit more clarification since electronics is not my strong suit. The only connection I see is to the GPIO port. I guess once the Arduino turns on, I output 5V at the GPIO port to turn on the NPN (it'd be in saturation mode, which acts as a closed switch). I can turn off the NPN by outputting 0V at the GPIO port, right?I don't see any power connections to the Arduino, I wonder if the drain side of the MOSFET is supposed to connect to 5V input on the Arduino, and once the gate voltage is low, the MOSFET will act as a closed switch. BTW, is that 100k resistor at the MOSFET a pull down resistor too?thanks

author: Doctorandus_P
author_rank: Super Contributor
timestamp: February 13, 2019, 03:13:35 pm
content: You are correct in the description of how the circuit works.I'll say the same, in different words, sometimes that helps.When power is first applied the NPN transistor is off, nd therefore the 100k resistors pulls the gate to the source of the Fet and the Fet stays "off".When the push button next to the transistor is pushed, the gate of the fet is connected to GND and the Fet turns on. and this effectively forms a short between Source and Drain.You can add some voltage regulator between the Drain of the Fet and the Arduino, or use the arduino power supply circuitry if it has any.When the arduino receives power, the first thing it should do is to make the I/O pin high.This opens the NPN transistor, which keeps the voltage on the gate of the Fet low after the button is released. The normal duration of a button push can be 500ms or lower, so that is all the time the arduino has.When the arduino is finished with it's job, it makes the I/O pin low, which turns off the NPN transistor, the voltage on the Gate is pulled high by the 100k resistor and the MOS fet turns off.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: February 13, 2019, 03:28:14 pm
content: If you like schematics, here is the power supply circuit of the transistor tester.Power is coming in from a barrel jack or 9V battery.It also shows the voltage regulator (IC2) which might as well have been a LM7805.T3 has the same function as the Peabody's MOSfet.T1 is the same as the NPN transistor in Peabody's power circuit, but a led is added because it was a convenient place of a low current path.T2 is "extra".When switch S1 is initially pushed the ATMEGA328 and T2 are at 0V and the transistor just acts as a diode.When the ATMEGA328 is on however, T2 pulls pin PD7 low whenever the button is pushed.If the button is released then pullup resistor R14 pulls pin PD7 high again.In this circuit switch S1 has therefore 2 functions.It turns the whole shebab on when it is first pushed, and when the circuit is already on it is used as a push button on an input of the AVR pin.All these circuits have a limitation.As long as the button is pushed, it is not possible to turn the power supply off. This may be an issue if the circuit is carried around in a rucksack or your back pocket or can get stuck in any other way. The most common way to prevent this is to restrict physical acces to the button, for example to mount it in a slight recess.

author: Peabody
author_rank: Super Contributor
timestamp: February 13, 2019, 05:18:41 pm
content: Quote from: engineheat on February 13, 2019, 02:20:08 pmYes. The mosfet is a P-channel. Think of it as an Australian mosfet where everything is upside down. It's gate pullUP resistor keeps it turned off normally. Pushing the push button grounds the mosfet gate, which turns the mosfet on. While the button is held down, the Arduino boots up, and the first thing is does is set that I/O pin to an output, high. That turns on the NPN (not Australian), which maintains the connection from mosfet gate to ground when the button is released, and keeps the power on. Then when you're ready to shut down, just change the I/O pin to low, and that turns off the NPN, and the gate's pullup resistor turns the mosfet off.QuoteI didn't know what you are using as a power source. If you use, say, a 9V battery, then the mosfet drain would be connected to the Arduino's Vin, or RAW, pin and the Arduino's regulator would produce the regulated 5V for the 328. If you are using a regulated 5V supply, then the drain would connect directly to the 5V pin of the Arduino. The problem comes if you are powering from the USB port. That's fine as a 5V source, but there's just no easy way to break the connection so as to insert this control circuit.

author: Peabody
author_rank: Super Contributor
timestamp: February 13, 2019, 05:39:05 pm
content: Quote from: Doctorandus_P on February 13, 2019, 03:28:14 pmNice circuit. I see that with R9 and R10 you proceed in an abundance of caution, as I generally do. In theory, unlike with mosfets, neither is needed since absence of current flow should be enough to keep both bipolar transistors off. Do you have specific experience that tells you to include these resistors? I have to say that nothing bad has ever happened to me when I've left them out, but I still usually include them.

author: Dave
author_rank: Super Contributor
timestamp: February 13, 2019, 06:58:13 pm
content: There will always be leakage in semiconductors and cascaded current gains can cause problems in these cases.You might also use BE resistors if you want to make sure the charge gets drained from the base quicker, resulting in a faster switching time.

author: engineheat
author_rank: Frequent Contributor
timestamp: February 14, 2019, 04:05:37 am
content: Quote from: Peabody on February 12, 2019, 05:04:00 pmI completely understand your drawing now. thanks.I don't have a single NPN transistor, but I got some ULN2004 Darlington arrays. I guess I can just use one channel of those in place of a single NPN. Granted the saturation voltage would be higher, but this only leads to higher power loss while the device is running, which I don't care. I did read it has a slower switching rate. But aside from having the press the button a bit longer, it shouldn't affect this application right?

author: Peabody
author_rank: Super Contributor
timestamp: February 14, 2019, 05:08:52 am
content: I think a Darlington should work ok for the lower transistor. Or probably even an N-channel mosfet.

author: alex-sh
author_rank: Regular Contributor
timestamp: February 14, 2019, 10:06:34 am
content: Quote from: engineheat on February 12, 2019, 04:16:44 amThe simplest way is to use TPL5110 Breakout. Please see herehttps://learn.adafruit.com/adafruit-tpl5110-power-timer-breakout/overviewVery simple to use and it powers down the whole thing - arduino and lcd with a nA sleeping current.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: February 14, 2019, 10:32:12 am
content: Quote from: engineheat on February 14, 2019, 04:05:37 amSingle transistors are a bit difficult.They tend to come in boxes of 200 (THT), or samplebooks of 1000 (SMD).https://www.aliexpress.com/wholesale?SearchText=transistor+assortmenthttps://www.aliexpress.com/wholesale?SearchText=smd+sample+book+transistor

author: engineheat
author_rank: Frequent Contributor
timestamp: June 25, 2019, 01:57:25 pm
content: Quote from: Peabody on February 12, 2019, 05:04:00 pmCan someone explain this a bit more? how do you "configure" a pin as input with a pull up resistor. I thought you configure a pin as output or input in the software? And how does that eliminate the first resistor coming out of the GPIO?Thanks

author: Peabody
author_rank: Super Contributor
timestamp: June 25, 2019, 02:30:00 pm
content: Quote from: engineheat on June 25, 2019, 01:57:25 pmThe internal pullup is also enabled in software. INPUT_PULLUP is a third pinMode() option for an I/O pin. See the Arduino reference entries for pinMode() and digitalWrite().You can configure the pin as an output, high, and use the external resistor, or as an input_pullup with no external resistor. Either way, you have a resistor between 5V and the transistor base. It's safer to use the external resistor because if you depend on the internal pullup, but inadvertently end up with the pin configured as an output high, then you could have a large current flow through the transistor base.

author: sokoloff
author_rank: Super Contributor
timestamp: June 25, 2019, 07:01:51 pm
content: You also probably want to remove the bootloader and have your code execute immediately upon button press rather than after the bootloader delay.

author: engineheat
author_rank: Frequent Contributor
timestamp: July 01, 2019, 02:17:41 am
content: Quote from: Peabody on February 12, 2019, 05:04:00 pmI finally built this circuit. It worked! It performed just as expected too. If I push the button briefly, the Arduino light would go on briefly and shut off. I had to push the button for a bit longer for the program to run, and then it'll shut off once the program write the GPIO pin to low.This is a lot better than putting the Arduino to sleep as it cuts down the power drain completely. Learned a lot thru this, thanks

author: sokoloff
author_rank: Super Contributor
timestamp: July 01, 2019, 11:13:00 am
content: Quote from: engineheat on July 01, 2019, 02:17:41 amGreat.BTW, this is why I suggested removing the boot loader. Right now, you have to press the button longer than the boot loader timeout so that your code can run and turn the power “keep on” on.

author: Peabody
author_rank: Super Contributor
timestamp: July 01, 2019, 10:18:35 pm
content: Quote from: engineheat on July 01, 2019, 02:17:41 amYou could try placing a capacitor in parallel with the gate pullup resistor. When you power up, both sides of the capacitor should come up to the rail voltage, and the mosfet should stay off. But when you push the ON button even briefly, that will discharge the capacitor, which will take some time to recharge through the pullup, and during that time the gate will stay low, and the mosfet will stay On. Then you wouldn't have to hold the button down while the Arduino boots. I don't know what capacitor value to suggest, but you may need to change the pullup resistor to 1Meg to allow the use of a reasonably-sized cap.