Aref settings in arduino...

hello friends,
i am using arduino for my project with two voltage source.. one is 5v from USB and other is 3.7v battery... i need to measure battery voltage of the same battery and indicate its status so i am using AD0 to measure the voltage of battery.. my Aref pin is connected to vcc,so when i connect USB i get correct reading in adc and when it switches to battery( its maximum voltage is 4.2v and will reduce after some usage simultaneously) its reading is incorrect and its always showing 5v(1023)
I think in battery operated tome its Aref is also changed to 3.7v
friends please give me a solution for this

If AREF and A0 are both connected to VCC (which they are when VCC == VBAT) then you will get a reading of 1023.

You need a different reference, I've not done this but maybe the internal reference (1v1?) and a voltage divider on VBAT.

Search for "secret voltmeter" in the forum. With this the Arduino can measure its own Vcc

thank you friends....thanks for the support of everyone

olf2012:
Search for "secret voltmeter" in the forum.

"getbandgap" returns a version without bugs...

https://www.google.com/search?q=getbandgap+site%3Aforum.arduino.cc