How to make an automatic switching power supply for a 12v lamp (wall adaptor and batteries)?
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!