Help with automatically selecting a power source

Discussion in 'The Projects Forum' started by SXRguyinMA, Feb 20, 2012.

  1. SXRguyinMA

    Thread Starter New Member

    Feb 20, 2012
    2
    0
    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
     
  2. BSomer

    Member

    Dec 28, 2011
    433
    106
  3. crutschow

    Expert

    Mar 14, 2008
    13,056
    3,245
    If it has a switched third leg to disconnect the battery why would you need a diode?
     
  4. BSomer

    Member

    Dec 28, 2011
    433
    106
    Good point. Why did I say that??? :confused: I guess the cranial cross winds cause a cerebral flameout. :rolleyes:
     
  5. SXRguyinMA

    Thread Starter New Member

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

    Member

    Dec 28, 2011
    433
    106
  7. dumle29

    Member

    Jun 26, 2011
    45
    0
    You could also do something like this:
    [​IMG]

    an then use some code like this:

    Code ( (Unknown Language)):
    1. void powerManager()
    2. {
    3.     if(digitalRead(9) == LOW)
    4.     {
    5.         digitalWrite(10,HIGH);
    6.     }
    7.     else
    8.     {
    9.         digitalWrite(10,LOW);
    10.     }
    11. }
    and then just do a
    Code ( (Unknown Language)):
    1. 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/...223V5R5C/?qs=sGAEpiMZZMvANcmvDb1WMcmxD589JsgB

    hope it helps :)
     
    Last edited: Feb 21, 2012
  8. dumle29

    Member

    Jun 26, 2011
    45
    0
    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


    [​IMG]
     
    Last edited: Feb 22, 2012
Loading...