Dear Arduino User,
Good mornming to all.
Im new user of this forum and came to know by my frnds about this forum.
I am looking for assistance on displaying battery percentage .
I am using 3.7v battery to run arduino.
My query is i want to display 0% at 3.7v and 100% at 4.2v. i am using chargeable battery.
On 3.7v digital value is 771.
On 4.2v digital value is 875.
with difference of 0.5v my battery percentage will increase by 10%. This is wat i want to display.
I am unable to find the correct step to do so.
I am getting result if im using 0v to 5v conversion in percentage.
ex: int volt=(analogval/1023)*100;
How it can be resticted from 3.7v to 4.2v to display the battery percentage form 0% to 100% ,which will be increased by 10% on increment of 0.5v.
I hope my query is been clear to all.
Thanks for reading and consideration.
Good day!
percentage = map(analogval, 771, 875, 0, 100);
.
Thanks Larry for your help.
I'm in school now by afternoon when I reach at my place I will definitely check and confirm u.
Earlier I was trying with mapping but with worng value.
Volts=map (analogval,771,875,0,1023).
Thanks once again.
analogval = analogRead(A0) ;
percentage = map(analogval, 771, 875, 0, 100) ;
percentage = constrain(percentage, 0, 100) ;
.
joe1993:
I am using 3.7v battery to run arduino.
How is the battery connected to the Arduino?
If it is directly powering the Arduino then analogRead() will be using the battery voltage as the reference point so it will always appear to read 100%. There is a solution to that but I will wait for your answer rather than confuse things.
...R
Thanks Larryd and Robin.
In sometime i will update the status how its working after change suggested from you.
I'm on the way for my place.
How is the battery connected to the Arduino?
If it is directly powering the Arduino then analogRead() will be using the battery voltage as the reference point so it will always appear to read 100%. There is a solution to that but I will wait for your answer rather than confuse things.
@Robin yes i am directly powering arduino by using battery as reference point.
Want to read battery percentage level from analog pin.
Please suggest if i am doing anything worng.
joe1993:
@Robin yes i am directly powering arduino by using battery as reference point.
Then have a look at the code in this link which uses the internal reference voltage to read the battery voltage
...R
Hi,
Welcome to the forum.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Thanks.. Tom.. 
Hello Tom,
Please find the attach copy of diagram made by hand actual pic is at my PC at home.
Currently I'm travelling from school to home .
Sorry Tom won't able to upload drawing showing size issue...
But I will share it soon as I reach at my place.
Thanks.
Hi,
No problems, keep file size under 1M. Use Paint to resize the file.
Thanks.. Tom.. 
Hello Larryd,Tom,
Sorry for late reply.due to connectivity wont able to update you.
I used map and constrain as per suggestion its working fine.
Thanks once again .
One last suggestion required .
I want to known is there a possibility that i will keep password to my toy car and it should be run on 5no's of time after ON/OFF and it should ask for password again.
Example : Today i enter THE password AND toy car start working may for whole day and its been turn
OFF after its been use .
Next day again without password it can be used once it turn ON.
Same it will work for 5 time without password but after 5 time it should ask for
password.
I know i need to use EEPROM to save the number of run time and count it .
Is there any example is available like what i have asked.please share if it is available.
Hope i have cleared my query.
Thanks once again Larrdy and Tom.
Battery percentage issue is Solved.
Have a good day!
Thanks Robin for sharing example code for better understanding abt battery percentage issue.
