measuring arduino's own battery voltage

i have a setup where i intend to measure arduino's own battery level. the input supply is 6v so i used scaling resistors to scale down 6v to o-5v. this is the following code which i am using to measure the voltage.

//setup code
//loop code
int battLevel = analogRead(A0);
float volt = battLevel*(5.0/1023.0);
int percent = volt/5*100;

i am getting a 100% level even if the input voltage is less than 6V...

By default the Arduino references its voltages between GND and the 5V pin. If your battery is connected to the 5V pin then you're measuring the battery voltage against itself.

See Measurement of Bandgap voltage - #9 by retrolefty - Development - Arduino Forum for a better way to read the voltage on the 5V pin.

D O N E!! :slight_smile: