Dual power supply: Battery and 5V
Place a diode from Vdd (or Vin - same junction though) to the cathode of D1.







simulate this circuit &ndash; Schematic created using CircuitLab

This will work just like an OR gate: Your circuit will be powered from Vin if (Vin - 0.6V) > Vbattery. Otherwise, the circuit will be powered from battery. You can use a germanium diode in order to reduce voltage drop on that extra diode.