Battery level

I would like to run my Arduino of a 12V 7ah battery (in case the mains power goes down). I want to buy a charger like this, but the manufacturer says I should not leave it on the battery permanently. Can I measure the level of the battery with my Arduino, and then connect the charger with a relay switch if it falls below a certain level?
Any ideas would be appreciated.

most likely, yes. But, if you loose mains power, how are you going to run the charger?

Normally power failures don't last more than 12 hours. Hopefully the battery can keep powering the arduino from the battery during that time.
Does anyone have any idea how to measure the battery?

You can use the following voltage divider circuit to measure voltage. This gives you some smoothing via the capacitor, over-voltage protection via the 5.1V zener diode and the resistors themselves reduce the input voltage to a useful range.

If the input is 15V then we should expect to see 15V *100k / (220k+100k) = 4.6875V at the output.

A lead acid battery's no-load output voltage is proportional to its state of charge. It's also proportional to ambient temperature, which may complicate monitoring if not in a climate controlled environment.

For example:

How to know when the battery reaches full charge so to turn off the charger?

groundfungus:
How to know when the battery reaches full charge so to turn off the charger?

One could do current monitoring (measure voltage drop across a small series resistor) and stop when current reaches some predetermined level.

Alternately, one could just charge for a fixed amount of time.

Most chargers have some sort of visual indication that the charge is complete... You could use a ldr over the chargers LED to monitor this. Alternatively if you don't mind hacking into the charger you simple disconnect the led /solder a wire onto its leg and monitor the voltage of that output directly.

groundfungus:
How to know when the battery reaches full charge so to turn off the charger?

If the charger relay is controlled by the Arduino, simply turn off the relay to disconnect the charger, then take a reading over several minutes. If the readings indicate around 12.5 or higher charging is finished, if less turn the relay back on. Repeat as necessary.

I suggest you get a charger that you can leave connected permanently. If the max voltage of the charger does not exceed about 12.3v the battery cannot be overcharged.

...R

I think you mean ~13.3volt.
In my experience, those 12volt/7Ah lead-acid batteries last about 4years if permanently connected to <= 13.4volt. And only months if permanently connected to 13.8volt.
You could use e.g. a 1N4004 diode in series with the +wire to drop the voltage of that charger from 13.8 to ~13.2volt.
A 5volt micro-power buck converter could power your Arduino twice as long.
Some have a shutdown pin, so no power-hungry relay either.

Leo…

Wawa:
I think you mean ~13.3volt.

Thank you. I did not (I was being conservative) but I believe you are correct having re-read the Battery University website.

…R