wall adapter/battery select circuit
I had posted an answer here before, but then I realized it was unnecessarily complicated and deleted it.

There's a simpler way to do what you want: a power multiplexer IC. The TI TPS2115A for example, will take care of everything for you. You can use it like this:







simulate this circuit &ndash; Schematic created using CircuitLab

A resistor between ILIM and ground can give it a current limit function as well. Here, I've shown a 400Ω resistor as in the datasheet examples, but tying ILIM directly to ground can disable current limit if for some reason you want that.