5V+ Voltage to the arduino analog
For the 12 V battery, let's assume it might get up to 15 to 20 V when charging, so we need a voltage divider to divide that down.



The zener diode is there to clamp the input to no more than 5.1 V in case of spikes or other damaging things on the input. 

The voltage divider will divide down to 25% of the input, ie.

output = R2 / (R1 + R2) = 10 / (30 + 10) = 0.25


So now if you measure 5 V on the analog input you know you have 20 V on the battery. Thus you can scale your calculations appropriately.

(A more common value would be a 33 k resistor, in which case redo the calculation and scale accordingly).



For 240 V I strongly advise against trying something like that with bigger resistors. For one thing, 240 V RMS will have 240 * sqrt (2) = 340 V peak to peak. And that is both negative and positive.

A suitable approach would be to run through a small transformer, which will reduce the voltage and also isolate you from (almost) certain death.

In addition to that you would need to rectify the resulting voltage (say, 12 V) so that you don't put negative voltages into your input pin. And on top of that filter it so smooth out the peaks and troughs.