Electronic – DC Barrel + Battery schematic

adapterbatteriesconnectorpower supply

I would like to create a power supply for a learning project, using either a DC adapter or a 9v battery.

I've read a few topics here and on the web about barrel connectors, but I'm still not sure how to use it properly in conjunction with a battery.

The schematics and articles I found are unfortunately too vague for my poor understanding, so I made one.
Is this the correct way to wire the battery to a barrel connector, so I can use one or the other?

barrel and battery

Edit

Battery will be 9v, DC adapter will certainly be 12v.

Ideally, I would like to be able to keep the battery in place while using the DC adapter. Battery will then just be bypassed.

Best Answer

That should work fine. Keep in mind that both diodes will drop some of your voltage.

When you have your wall wart plugged in you'll have 12V - diode drop at the input to the regulator, which will force D2 to be reversed biased (because you're using a 9V battery). If you unplug the wall-wart then D2 will become forward biased and you'll have 9V - diode drop at the input to your regulator. I don't know what your output voltage is, but just make sure that the diode drop won't botch it (e.g. look at the datasheet of your regulator and make sure that the drop out voltage criteria is OK given the diode drop).