I'm software programmer taking the first steps into the electronics world.
I have a circuit that can be fed by a battery (9V) or by a external DC source (from the wall - I'm considering 12V). Ideally, the battery power should only be used when the external DC power is not available. Also, if the circuit is unplugged from the wall, the battery should assume immediately, because there's a microcontroller in the circuit and I suppose that a power drop would reset the microcontroller.
Both sources will pass though a regulator that'll lower the voltage to 5V.
I wonder if a circuit like the one below will do the trick. It seems really simple (maybe too simple) but it did work in the simulator. The resistor respresents the whole circuit, including the voltage regulator.