Help with automatically selecting a power source

Thread Starter

SXRguyinMA

Joined Feb 20, 2012
2
Hi guys! I made this setup for a Valentine's day project: http://computersandcircuits.com/?q=vday_led_mixer

It currently runs off of 4 AA's in series and works just fine. M wife suggested I make it able to plug into the wall so the batteries don't drain as fast. My question is how can I set something up where it'll run off of a 2.5mm DC jack from the wall automatically, but when it's unplugged it'll switch to battery power? It doesn't need to be a seamless transition, I just want it to use the wall source as primary if it's available.

I could always just put a switch to select between wall or battery power, but if she forgets to switch it back to wall power after having it on battery power it'll kill out the batteries lol. Thanks in advance! :D
 

crutschow

Joined Mar 14, 2008
23,140

Thread Starter

SXRguyinMA

Joined Feb 20, 2012
2
That's almost perfect. Exactly what I need operation-wise. Now to just find a 2.5mm panel-mount style....hmmm... Thanks!
 

dumle29

Joined Jun 26, 2011
45
You could also do something like this:


an then use some code like this:

Rich (BB code):
void powerManager()
{
    if(digitalRead(9) == LOW)
    {
        digitalWrite(10,HIGH);
    }
    else
    {
        digitalWrite(10,LOW);
    }
}
and then just do a
Rich (BB code):
powerManager();
in the start of your loop.

what it does, is this:

D1 prevents the DC from trying to charge the battery, until the Arduino has switched the battery off.

D2 keeps the battery from pulling pin 9 high (turning off the battery)

R1 pulls pin 9 high, if the plug has been connected, R2 pulls pin 9 low, if it isnt connected. R2 has to be larger than R1, so R1 can pull pin 9 HIGH.

in the code it checks wether or not, a dc plug has been attached. If it has, it turns pin 10 off, shutting off the logic level fet, keeping the battery from powering the chip. if its low (no dc plug attached), it turns pin 10 high, turning on the mosfet, allowing it to run un battery.

The cap i mistakenly named power filtering (it does that too) is meant to be pretty big, and is supposed to feed the arduino, during the switch. possibly use this supercap http://dk.mouser.com/ProductDetail/Cornell-Dubilier/EDLSD223V5R5C/?qs=sGAEpiMZZMvANcmvDb1WMcmxD589JsgB

hope it helps :)
 
Last edited:

dumle29

Joined Jun 26, 2011
45
Oh and the 9v has to be dc regulated(Lm7805). but put the FET before the lm7805 :p

you could use a IRLZ34 as your FET

i made this change, or it wont start up on battery.
its the 3rd resistor (still called R1 since i made it in paint :/)

the resistor, pulls the gate high, and turns on the arduino. This has a high value, to save battery power, when the gate of the transistor is pulled low. It will pull 0.09 mA off the battery when using a DC socket. you could increese the resister to make that smaller


 
Last edited:
Top