Products > Embedded Computing

How to cut power to Arduino after a set time?

<< < (5/5)

Peabody:

--- Quote from: engineheat on June 25, 2019, 01:57:25 pm ---
--- Quote from: Peabody on February 12, 2019, 05:04:00 pm ---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.

--- End quote ---

Can 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

--- End quote ---

The 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.

sokoloff:
You also probably want to remove the bootloader and have your code execute immediately upon button press rather than after the bootloader delay.

engineheat:

--- Quote from: Peabody on February 12, 2019, 05:04:00 pm ---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.

--- End quote ---

I 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

sokoloff:

--- Quote from: engineheat on July 01, 2019, 02:17:41 am ---I 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

--- End quote ---
Great.

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.

Peabody:

--- Quote from: engineheat on July 01, 2019, 02:17:41 am ---
I 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.


--- End quote ---

You 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.

Navigation

[0] Message Index

[*] Previous page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod