Measure battery voltage

Hi,

I would like to know how can I read the battery voltage.

I tried with analogRead(ADC_BATTERY), but the value is not good.
I also tried to set analogReference(AR_INTERNAL1V0), but it gives me 1023 all time.

OUCH !
Stop right away !
Cease and desist LOL

The MKR series are 3.3 volt boards and feeding them with to much can kill them.
The best method is with a voltage divider to LIMIT the range to a MAX of 3 volts.

You can google voltage divider as there are thousands of great results and pictures, even calculators to do the hard work for you.

Once you have a stable reading with the maximum battery voltage you can simply MAP that range to the battery voltage

Then incorporate that function into the rest of your sketch.

As far as I know WiFi1010 already has a divider on ADC_BATTERY which is connected to battery

I stand corrected.
Thanks for putting me right.

This link may then help.