How to make an automatic switching power supply for a 12v lamp (wall adaptor and batteries)?

I'm converting a few lamps to run on 12v for wedding decorations, but would like them to have a bit more useful life after the big day.

I am going to power the lamps from 8xAA batteries (to give 12v) which according to my calculations should power my 12v 4.5w (so 0.375a) LED bulb for somewhere between 4 and 5 hours (plenty of time for when they will be used).

I would like to also put a DC socket on the lamps so they can be used as normal desk lamps with a wall adaptor, but still have the ability to run on batteries if needed. The simple solution would be to use a switch which can toggle between battery power and the wall power, but I would like to (if I can) wire it up so the switch is only "on or "off", and it will always run on wall power if it is available, but to switch automatically to battery power if not (if the cord gets pulled out or if there is a blackout, etc).

I think I have worked out a circuit for this, but I haven't tested it yet, and I would appreciate any feedback on things I might have overlooked, or if there is a simpler way to do it.


In my plan below:
Wall Power (when available) runs from the DC socket, to the P-Channel mosfet gate (causing high resistance for the battery, effectively disconnecting it). The Power passes through a diode (to stop the battery connecting to the mosfet gate) then to the switch, bulb and to ground.
If the wall socket is unplugged, or if there is no power running to it for some reason, then the mosfet gate drains via the resistor (I am unsure of what resistance to use here) to the negative battery terminal so the mosfet now provides low resistance for the battery.
The Battery power runs to the mosfet, if there is low resistance it then goes to the switch, bulb and negative terminal on the battery.


I have very limited space in the base of the lamp to put all this in so I am trying to keep it minimal and using as small components as I can (so I can keep as much concrete in the base as I can for stability).

When I get it sorted I am intending to publish the project as a step-by-step for anyone else who might like a battery backed up lamp.

If anything doesn't make sense please tell me and I will try to clear it up.
Thanks for any help in advance!

Picture of How to make an automatic switching power supply for a 12v lamp (wall adaptor and batteries)?
sort by: active | newest | oldest
G4224T3 years ago

Ok you had me intrigued with this one so I simulated it. It would probably work in principle although you may have to try various Fets. The resistor doesn't seem to be doing much either, except shorting the DC supply when the switch is switched off.

Theres a couple of schematics attached, one showing the voltage and the current when the DC supply is working (switched on in the simulation) and one showing the voltage and current when the DC supply is removed.

You'll be able to see that the voltage and current drop when supplied through the battery. This is pretty much down to the selection of Mosfet you use.

Hope it helps anyway, but heres another thought, you may be better off using rechargeable batteries. Any small charging circuit would do then and you wouldn't need to replace all those batteries as often?

Battery Backup - DC applied.pngBattery Backup - DC Removed.png
RandomIdeaMan (author)  G4224T3 years ago

Thanks for your help!

I had actually thought of rechargeable batteries (and I will be using some for this) but I'm not sure how to make a charging circuit (it would need some way to know when the batteries have been fully charged and then disconnect them wouldn't it?).

If you could point me in the right direction for that I would be very grateful too, but I had just envisioned taking the batteries out and ptting them in a normal charger after it's been used on battery power.

I guess to use rechargeable batteries properly then over charging / heating should be considered in any circuit. Here's a link to a web page I found that shows lots of different charging circuits of varying complexities.

http://www.hobbyprojects.com/B/battery_chargers.ht...

Im sure there will be something on there that suits should you decide to go down that route.

RandomIdeaMan (author) 3 years ago

Oops, my bad, its a 4.5 watt bulb (so 0.375 amps). I'll fix that up. It does run fine on the batteries (I have tested that much).

ernestcraphead: Sorry if it's hard to follow, I can't read circuit diagrams very well, and have even less luck in drawing them (I'm trying to correct that, but I have a lot of learning to do and as it's a hobby I don't ever seem to have enough time to work at it).

The mains power does go to the mosfet, but also via the diode to the bulb too.

mpilchfamily: just using a diode would drain the batteries when when it's plugged in to power wouldn't it? or am I missing something?

The idea is that it runs on power from the wall when it's available, but the batteries kick in when there is no power from the wall.

G4224T3 years ago

I think you might struggle to power 4.5A from AA batteries or indeed a DC adapter. Normal AA's have a capacity of around 900mA whilst heavy duty batteries can be up to 3A. Connecting your batteries in series will increase the voltage to 12v but won't increase the current, you would have to connect another 8 in parallel to double the current capacity as I understand it.

Either way a DC adapter capable of supplying 4.5A is quite a hefty adapter.

Im not too sure on your circuit description though, it would be easier if you could post the circuit diagram of what you have in mind? it looks like the battery is just trying to switch the FET on above??

No need for a switch between the wall adapter and the batteries. Place a diode between the batteries and the wall adapter so the power from the wall doesn't try to charge the batteries and you'll be fine. Other than the batteries being used at the same time as the wall adapter.

Do you have an adequate wall adapter for this? 12V 5A wall adapters are not vary common. Unless your using a switching mode power supply.