How to design a circuit to disconnect a battery charger automatically?

I want to use an AC to DC 14.4 V adapter to supply both my circuit and its battery. The circuit works with 12 V and I use a battery during power outages (blackout time).

I have prepared the below circuit for switching between adapter and battery, but I need to recharge the battery when power comes on again. Assume the dip switch is the main power key.

The main problem is that if I use an op-amp as a comparator for the battery voltage level, it will show the adapter output voltage, not the battery level. So how can I solve this?

And another problem is: Suppose we are in blackout time and the battery voltage level has decreased to, for example, 9 V. How can I disconnect the battery? Is it possible to use a MOSFET like the IRF510 between battery and circuit?

• “The main problem is that if I use an op-amp as a comparator for battery voltage level, it will shows the adapter output voltage not battery level” ...can you explain more why you think this wont work?measuring the voltage across the battery should be okay. Aug 5, 2018 at 10:41
• @Navaro Oh really?! Actually i didn't try. I thought it will show source voltage. So if it acts like this, the buck converter input voltage decreases and also we would have another decrease on buck converter output terminal. Aug 5, 2018 at 15:32
• I test it. Charger with no load had 14.4v in output terminal. After i connect it to the battery, voltage decreased to 14.16v. I think its naturally, however output current is low (about 0.5A) and its a chip one. I didn't expect this charger more than this :) Aug 6, 2018 at 6:12
• did you measure the charger output voltage or thr voltage across the battery. my understanding is that the battery voltage is used as input for the op amp. place a resistor of a 10-100ohm between the charger and battery and measure the voltage across the battery. Aug 6, 2018 at 11:13
• @Navaro So I should place a 10-100Ohm resistor after D2 and I measure the voltage of battery right after the resistor. Right? Okay I'll test it. Thank you. But Another question. Why engineers are using difficult methods for measuring battery voltage level during charging? For example they disconnect the charger and then they measure it. Or they use Coloumb counting?!!! Aug 7, 2018 at 8:31