Introduction: Arduino Battery Voltage Indicator

When we are using a battery powered Arduino such as RC robots or Temperature Controller, we might want to check the battery voltage if it needs to be charged or replaced. It happens to me with my RC Panzer. Sometimes when my kids are about to run it, it moves very slow, low battery. Then they are disappointed and need to wait for charging time. I would rather had noticed this battery condition on the last run but I am too lazy to check it with multimeter.

Arduino Uno needs 5 volts power to run, then we need at least 7.4 volts to 9 volts battery. Since Arduino pins support only 5 volts maximum, then we need a Voltage Divider. It is simply made up of two resistors in series. To divide the voltage to half, we need two resistor with the same value. 1K to 20K resistors can be used, but the larger the resistance the lower the power consumed by the Voltage Divider. I am not that good in calculating such thing but that is what I summarize from sources I read. You can correct me if I am wrong and any better explanation to this is most welcome on the comment section.

Step 1: Bill of Materials

  • Arduino Uno or compatible.
  • Male pins (we need four pins only).
  • Two same value resistors (here I use 12K).
  • Two pin female connector. Photo shows three pin because that is what I have. Here I use power switch connector to motherboard instead :)
  • A battery (I use 7.4V lipo battery).
  • 16x2 LCD with I2C adapter. Later on you can switch this to a red LED to indicate low battery at your desired voltage level.
  • A mini breadboard is optional for testing phase.

Step 2: Arduino Sketch

Well, I would like to upload this sketch to Arduino first before connecting it to a battery for testing. Uploading this will show you nothing before you connect all the parts needed for this project, but sooner or later you will still need to upload this sketch. I am not sure what will happen if you have power from usb and also from Vin at the same time. I guess it will be okay, Arduino designers must have think of this possibility and prevent this power conflict. But I will never try it on purpose and risking my Arduino to get burnt :P

In this instructable, I am not explaining about "how to get your LCD display works", but I will leave some links here (which I use) to get your LCD works through I2C connection:

// Print battery voltage
// to 16x2 LCD via I2C
// with Voltage Divider (2x 10K resistor)
  Resistors are aligned in series.
  One end goes to Battery - and also to Arduino GND
  The other goes to Battery + and also to Arduino Vin
  The middle (connection between two resistors) goes to Arduino A0

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR    0x27 //Add your address here.  Find it from I2C Scanner
#define BACKLIGHT_PIN     3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7
#define led_pin 13
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

void setup()
  lcd.begin (16,2); //My LCD was 16x2
  lcd.home (); // go home
  pinMode(led_pin, OUTPUT);
  digitalWrite(led_pin, LOW);

void loop()
 void printVolts()
  int sensorValue = analogRead(A0); //read the A0 pin value
  float voltage = sensorValue * (5.00 / 1023.00) * 2; //convert the value to a true voltage.
  lcd.print("voltage = ");
  lcd.print(voltage); //print the voltage to LCD
  lcd.print(" V");
  if (voltage < 6.50) //set the voltage considered low battery here
    digitalWrite(led_pin, HIGH);

Step 3: Circuit

The wire connections are simple as you can see on the images above.

Using 16x2 LCD and its I2C adapter:

  • Adapter GND to Arduino GND.
  • Adapter VCC to Arduino 5V.
  • Adapter SDA to Arduino A4 (or the pin next to AREF on Digital Pins side).
  • Adapter SCL to Arduino A5 (or the pin next to SDA, two pins from AREF on Digital Pins side).
  • Align two 10K resistors in series on breadboard.
  • Connect the middle of the resistors-in-series to Arduino A0.
  • Connect one end to Arduino GND and also to Battery - (negative).
  • Connect the other end to Arduino Vin and also to Battery + (positive). I think you should connect this one after you load the Arduino Sketch as I tell you my reason before.

Using a LED instead of LCD:

  • Connect LED anode (small piece inside) to Arduino D13.
  • Connect LED cathode (large piece inside) to GND (next to D13).
  • Align two 10K resistors in series on breadboard.
  • Connect the middle of the resistors-in-series to Arduino A0.
  • Connect one end to Arduino GND and also to Battery - (negative).
  • Connect the other end to Arduino Vin and also to Battery + (positive).

When you plug the battery to Arduino Vin, it should work right away showing the voltage of your battery on your 16x2 LCD because Arduino is powered by that battery. If it is not working, please re-check your connection or the battery you use might be lower than 5 volts needed by Arduino to power up. Please try another battery or check it with your voltmeter.

On my test with multimeter, the voltage shown on the LCD is slightly lower then the multimeter display. We are loosing around 0.05V to 0.15V on breadboard and Arduino circuits. But that is not a big problem for me (I don't know what about you), as long as I know whether my battery has enough power to run my robot. That's all.

Step 4: From Mini to Micro

Well, I don't want that "mini" breadboard goes along on my Panzer, then I make it "micro".

  • The first resistor : One end soldered to pin 1 from the left. The other end to pin 4 from the left.
  • The second resistor : One end soldered to pin 2 from the left. The other end to pin 4 from the left.
  • Soldered the connector inner pins to pin 1 and pin 2 from the left.
  • Put the black connector jacket on.
  • Pull out pin 3 from the left.

Well, now we have add-on to Arduino pin : GND, Vin, A0.

Step 5: Re-Connect and Run

Now re-connect the LCD and Battery, we have simpler connection without breadboard.

  • Adapter GND to Arduino GND.
  • Adapter VCC to Arduino 5V.
  • Adapter SDA to Arduino A4 (or the pin next to AREF on Digital Pins side).
  • Adapter SCL to Arduino A5 (or the pin next to SDA, two pins from AREF on Digital Pins side).
  • Battery - (negative) to Arduino GND (on our add-on pins).
  • Battery + (positive) to Arduino Vin (on our add-on pins).

On my test I lost 0.1V and pretty stable. Actually we lost only 0.05V on Arduino circuit. 7.79V is shown on my multimeter. Voltage Divider reduced it to half, that is 3.89V entering the A0 pin. The Arduino reads 3.84V. Then we double it to show the exact voltage back, that is 7.68V.

We can fix this in the sketch, but we need more data population to see the stable voltage lost. One more question is : "Is it my multimeter that is not accurate? Because I bought a cheap one."

Again, I don't mind that little difference as long as I know my battery is fit enough to run my RC toys :)


ninaliuzm made it!(author)2017-04-25

Sir , I am doing a solar car project . We need to change the output voltage of the solar panels(or rechargeable battery,which is 6V in total). How can we do that with the Arduino? For example, At the starting period of the race, we need less voltage more current to gain more torque(shift the voltage to about 3V). After a few second we wanna to change the voltage output to 6V. Another problem is the max voltage of the Arduino is 5V. So should we add a resistor to fix this problem.

chienline made it!(author)2017-04-25

If you want to use this voltage indicator circuit to know the remaining power then yes you need two resistors with the same value as voltage divider, because A0 pin can only handle 5V while your battery is 6V and could be more when fully charged.

If you don't need the battery indicator then your 6V battery can goes directly into VIN pin which can handle up to 12V.

How will you bring down the voltage to get more current? Dropping the voltage to 3V will shut down the Arduino doesn't it?

GlenL22 made it!(author)2017-03-30

Thanks, used this with some edits to suit my Due board to monitor my 2 x 18650 batteries powering my weather station. When volts drop to 5.5, text turns red...time to change/charge batteries. If you don't and volts go too low, the board memory gets wiped! This saved me from having to reload the sketch!



Weather Station on Batteries.jpg
chienline made it!(author)2017-03-30

That's great. You're welcome ^^

suryaprasanth made it!(author)2017-03-28

Sir I need the various camand for various voltage level what can I do

chienline made it!(author)2017-03-28

First, define the maximum voltage of your battery. Remember that LiPo batteries may be higher than their ratings when fully charged. For example, I have a maximum of 24V to be tested. I use 6 resistors that have same values. Actually 5 are enough in my case, but I just want to explain better with 6 in the picture I attach. Battery that is higher than the voltage Arduino can handle is not recommended because it will be bad if it is not carefully wired.

You should take between the first and the second resistors CLOSEST TO GROUND (negative of battery) those are R5 and R6 in the picture and wire it to Arduino analog pin A0.

Concentrate. If you plug somewhere at where I mark with red A to E, then BOOM!! you will lost your Arduino pin, or worst, the whole Arduino :(

Because the voltages there are higher than that 5V Arduino pin can handle.

Don't forget to change the sketch with *6 to convert into true voltage :

float voltage = sensorValue * (5.00 / 1023.00) * 2; //convert the value to a true voltage.


float voltage = sensorValue * (5.00 / 1023.00) * 6; //convert the value to a true voltage.

With 6 resistors, you can measure battery up to 30V. Just remember to concentrate on wiring the A0 pin, that is near the Ground. ^^

%D8%B9%D9%85%D8%B1%D8%A31 made it!(author)2017-03-16

Thanks alot sir for this project
i used it without lcd change it to serial
i have a problem reading the values
when i put 3.7v battery it gives me 4.6
when i used 4.1v battery it gives me 3.9v
what should i do ?

chienline made it!(author)2017-03-16

Do you change any of the circuit above? If you are using battery lower than 5V then you don't need the voltage divider circuit (two identical resistors). Simply plug your battery (-) to arduino GND and battery (+) to Arduino A0, then you need to change the code a little. Find a line commented with "//convert the value to a true voltage" and remove the " * 2".

%D8%B9%D9%85%D8%B1%D8%A31 made it!(author)2017-03-18

I know i have done all of these
i want to use a battery 3.7 v to feed the arduino i put it on the vin as well as the analog pin but on the lcd it gives me 5 v
wht ahould i do ?

chienline made it!(author)2017-03-22

Sorry for my late reply. From what you described, you must be using Arduino Mini or Pro 3.3V? If you are using Arduino Uno, then you must be connecting your USB cable because 3.7V battery is not enough to power an Arduino Uno. If you power your Arduino Uno with USB cable and you only need to test the battery voltage then DO NOT connect battery to Arduino Vin. If it doesn't workout for you, then maybe you can share your wiring by uploading the picture of it here for me to investigate ;)

vipul.swamy made it!(author)2017-03-17

I made it Sir Thank you

chienline made it!(author)2017-03-17

You are welcome ^^

KlausHoller made it!(author)2017-03-08

I made one with LED. I was wondering what needs to be cahnged to use a 12V battery. Any advices?

chienline made it!(author)2017-03-11

​Sorry for being late to reply. For 12V battery you can use voltage divider with 3 identical value resistors. So your battery voltage will be divided by 3 and as long as it is not over 15V at peak, it is safe for the arduino analog pin to read.
Let's say the voltage divider circuit is now :
BatteryPossitive -- R1 -- R2 -- R3 -- BatteryNegative/GND
Run a jumper wire from between R2 -- R3 to Arduino A0.
Then you need to change the code from "*2" to "*3" where we calculate back to RealVoltage to be shown on LCD.

Hope this help ^^

KlausHoller made it!(author)2017-03-11

Thank you, I did it and it worked perfectly!

chienline made it!(author)2017-03-11

You are welcome ^^

John+AngeloS2 made it!(author)2017-02-22

Hi I'm doing a project using lithium ion batteries and I need to measure the voltage. ratings of the battery are 2250mah and 4.2v each. I know arduino can measure the voltage right away but can the arduino withstand the 2250mah total of 36A ? thank you

chienline made it!(author)2017-03-11

Arduino pin will only read the voltage and drawing a very little current. The rating 2250mah simply tell us how long your battery will last on certain circuit/power consumption.

ghostriderA made it!(author)2017-03-06

float voltage = sensorValue * (5.00 / 1023.00); please explain this formula how u got this ?

chienline made it!(author)2017-03-06

Well, Arduino analog pin reads from 0 to 5V. It has 10-bit analog to digital converter. This means that it will map input voltages between 0 and 5 volts into integer values between 0 and 1023. What we get from analogRead() function is an integer from 0 to 1023. So let's say we read an "800" (eight hundred). We need a voltage from that reading so it is : 800/1023 * 5 V = 3.91 V.

If you have previously reduced your battery voltage with a voltage divider into half, then you need to multiply by 2 to get back the real voltage.

ghostriderA made it!(author)2017-03-07

Thank u

rizay made it!(author)2017-02-05

Thanks for the great tutorial. I just wanna ask you one thing , if I have 3,7 V LiPo Battery , Can I plug the battery pin directly to A0 ? is it okay with the battery and Arduino ?

If not , can you give me some recommendation circuit

chienline made it!(author)2017-02-07

Thank you. Yes you can connect battery ground to Arduino ground. Then battery possitive pin to Arduino A0. Then simply change this line in the sketch:

float voltage = sensorValue * (5.00 / 1023.00) * 2; //convert the value to a true voltage.

to this one:

float voltage = sensorValue * (5.00 / 1023.00); //convert the value to a true voltage.

That is removing "*2" because your battery's voltage is below 5V and can be handled by Arduino pin directly without voltage divider.

ArturK21 made it!(author)2017-01-15

Great tutorial, thank you :) could you explain me two thing please :

1) after i connect my 9V battery , initial voltage is around 8.45V , but it quickly drops down to below 8 and continues to go down quickly ( 1/100V every couple of seconds seconds ) - is it really that fast battery gets depleted?

2) Resistors and voltage divider - i had only 1K resistors ( if i'm not mistaken ) so i connected both - it worked fine - why did you recommend 10k? is it why my voltage drops so quickly? also way how i connect to A0 - i did it in the middle of 2 resistors ( on the photo so R A0 R ) does it matter if it would be before or after a leg of resistor ( A0 R R ) , or what would happen if i would connect it after second resistor?

Thank you

chienline made it!(author)2017-01-16

Congratulation you have made it :)

From what your explanation you are using 1K resistors. It means more current is flowing in the circuit (and the voltage is dropping) and the resistors are getting hot. If you use larger value resistors let's say 10K or even 100K, that means less current is flowing and less hot on resistors.

It is important to use the same value resistors and connect your A0 at the middle of those resistors. It means we divide the battery voltage into half for A0 to read (max 5V), then we double the reading in the sketch to get back the battery voltage. For more than 10V battery, see previous comments where we can use 3 or 4 resistors and a little change in the sketch.

If you plug A0 before resistor1, it means you read the battery voltage directly. It is okay if your battery is lower than 5V, then you need no multiplication by 2 in the sketch. But if your battery is more than 5V, then you will burn your A0 pin, or any other part of your Arduino at worst.

If you plug A0 after resistor2, you will read zero voltage because your A0 is now connected to Ground.

galaxybd9 made it!(author)2016-12-20

I have used two 4.75 Kohm resistors. But I cannot get any output in the display.It is only glowing nothing else.

where I need to change the code.

chienline made it!(author)2016-12-20

Do you use Arduino Uno and LCD? What is your battery maximum voltage? First, please check your battery voltage with a multimeter to make sure it has minimum voltage to run both Arduino and LCD (it must be around 6V or more).

DavidB552 made it!(author)2016-11-15

is there anyone who can point me in the direction of something that can tell how much power is left while im using it

I'm going to have an Ardunio The screen a battery and some leds I just want the screen to tell me what percentage of the power is left in the battery.

any one can point me in the right direction would be great?

chienline made it!(author)2016-11-16

Percentage of power left in battery will vary for devices. One device will shutdown at 4.5 volts while other will shutdown at 6 volts. Unless you want to tell percentage of the whole battery itself then you can print to LCD :

lcd.print((sensorValue * (5.00 / 1023.00) * 2)/8*100);

Supposing my 7.4V battery can be fully charged to 8 volts ^^

Or you can note down at what voltage your device shutdown and at what voltage your battery is fully charged, then you can count the percentage of battery left before your device shutdown ^^

LifeHackerEcho made it!(author)2016-09-12

is there a reason why this might start rolling the voltage down?

chienline made it!(author)2016-09-12

rolling the voltage down? I don't get what you mean by that. Could you please explain a little bit?

LifeHackerEcho made it!(author)2016-09-19

the voltage is dropping slowly in increments of .01 volts

chienline made it!(author)2016-09-19

Because of current drawn by our circuit maybe? Arduino and LCD do consume the same battery power unless you put them on separate power to be tested.

arcticStingray22 made it!(author)2016-08-16

So from what i understand you cam read higher voltages by adding more resistors? How woukd you read a 22.2v lipo for example?

Is there any way to out but the signal over bluetooth to an OLED display in say a controller?

chienline made it!(author)2016-08-16

Yes, you can use 6 same value resistors in series which means we divided the voltage into 6 equal values. Then in your sketch remember to multiply by 6 to get the battery voltage back. You need to pay attention to which resistor's leg you feed into your arduino analog pin. Your Arduino is surely not sharing the positive pin of the battery 22.2v, but it can share the same ground. So the voltage reading will be on the resistor near the battery negative pin. Otherwise you will feed 5/6 of 22.2v (instead of 1/6) into your Arduino analog pin and that is bad, really bad.

You can share the voltage reading anywhere. That means you need a bluetooth and arduino on the battery side, and another bluetooth and another arduino on the controller side, and there is a communication over bluetooth between both arduinos. The problem is: do you know how the controller works? Is it your DIY controller or programable?
I would say you build an android controller app so you can read the message sent from bluetooth and dispay it in your app :)

afagard made it!(author)2016-08-09

If you would help me understand something that would be great. I understand we need to use the voltage divider to get the resistance under 5v. The issue is I have a battery rated at 7.2v when fully charged exceeds this voltage by + 2 volts or more. From what I understand this is normal of NIMH batteries. Now if I cannot "trust" that my battery at full charge is 7.2v how can I pick the resistors to divide it below 5? Further, how can I implement the math to figure it out in the code? Is it just not possible under these circumstances?

chienline made it!(author)2016-08-09

LiPo battery has 3.7v per cell while NiMH battery has 1.2v per cell. So I will explain a little about LiPo batteries according to what I read :) Maximum charge of LiPo battery cell is 4.2v and its minimum discharge is as low as 3v. Discharging below 3v will damage the cell and shorten your battery's life. In this project I was using a 2 cells LiPo battery, that means it is written 7.4v and it has 8.4v when fully charged.

Arduino pin can only read from zero volt up to 5v, that's why we need voltage divider. I am not lowering the voltage to exactly 5v, because we will need to do more complicated math to calculate it back to real voltage. Instead, I simply divide it into half by using two identical value resistors. So when my battery is fully charged it has 8.4v, dividing it half we get 4.2v and the Arduino pin can read the value of 4.2v. In the sketch we simply double it back and we get 8.4v.

If my battery drops to 6.4v, the resistors divide it half into 3.2v and the arduino calculate it back to 6.4v. So if you are using a battery with more voltages, let's say 11.1v, you can divide it into one third (1/3) by using 3 identical resistors. And in the sketch will be something like :

float voltage = sensorValue * (5.00 / 1023.00) * 3;

Regarding the resistors value, larger value means less current goes to Arduino pin. Smaller value will pass more current and gain more heat. So the value of the resistors from 1K to 4.7K is good depends on the current of your battery. Large current with small value resistors will end up be burnt by overheating. Someone please correct me if I am wrong :)

afagard made it!(author)2016-08-10

Completely understand now! Thanks ;) Side note: do you know why when A0 is disconnected with this script running the board still reports ~3.3v?

chienline made it!(author)2016-08-10

Never leave a defined pin floating (not connected). Unconnected pin can be interfered by the outside circuit. The electromagnetic field from other nearby electronics such as a power supply or computer or even the Arduino circuit itself can feed some voltage in it, in your case there is 1.6v and the *2 give you a reading around 3.3v. Even your hand touching the Arduino can interfere the unconnected pin.

The best workaround for this is giving a 10K or 47K resistor between A0 and GND to serve as pull-down resistor. Whenever there is no external voltage fed into the pin, the pull-down resistor will drag it to the Ground (GND) and gives you zero volt :)

afagard made it!(author)2016-08-11

Ah yes also thought it was something like that because when I put my finger on it the voltage changed. I'm having issues with my Arduino Micro powered by 5v. The issue is that once the battery drops below 5v, the whole measurement system becomes incorrect. Do you know why that is?

chienline made it!(author)2016-08-11

I guess your Arduino is 5v version, not a 3.3v isn't it? Arduino itself needs 5v to run and the external board like an LCD will also eat up the battery. So when your battery goes below 5v, the reading will not be accurate because it is lack of power to do so. It should share the power between other used pins and also the external LCD. Arduino can handle input voltage up to 12v, so you can pick a 3 cells lipo battery, that is 11.1v for longer use. 2 cells lipo has 7.4v is juicy enough for your arduino and some external boards attached on it :)

Gegtor made it!(author)2016-08-06

I have weird bug when my battery voltage is higher voltage value drops

can you help me?

int sensorValue = analogRead(A2);

float voltage = sensorValue * (5.00 / 1023.00);

i deleted *2 because then voltage was like 6 volts and my battery was 3,93

chienline made it!(author)2016-08-06

You are right by deleting *2 in the sketch. In this project I am using a 7.4V battery while Arduino pin can only read up to 5V. That's why we use voltage divider resistors to get the value half of my battery voltage. Then we calculate it back with *2 in the sketch.

In your case, where the battery voltage is not more than 5V, you don't need a voltage divider resistors. Simply connect Battery (-) to Arduino GND, and Battery (+) to Arduino A0 (or A2 in your explaination), then remove the *2 in the sketch :)

Gegtor made it!(author)2016-08-07

Ohh Thanks :D

julian_d made it!(author)2016-08-04

I love it, thank you so much!!

I had to tweak the 1023 number a little bit to get the correct voltage. I ended up on 1005. I used my multimeter for reference.

Works like a charm :-)

2016-08-04 23.10.16.jpg
chienline made it!(author)2016-08-06

Good job. Yes, the analog input to the Arduino has a range of 0 to 1023, but the circuit path and Arduino internal circuit do have interference, so teaking the value and syncing the results with our voltmeter is one way to get better result value :)

farithz made it!(author)2016-05-24

i wanna ask, i want to build a project that will run on water control by a remote control. The thing is, i want the indicator display its voltage on my remote control not on the robot. can anyone help me out?

chienline made it!(author)2016-05-24

It is possible. You can send the voltage reading through bluetooth serial to your phone instead of printing it on the LCD.
The problem is you need to custom your phone application to view it on your phone screen. Maybe the MIT AppInventor can help. I am too still learning how to create Android app :)

farithz made it!(author)2016-06-24

hi author, how can i transfer the voltage reading to the LCD? is there a special device for it?
Because i think it's a lot easier to know the voltage reading on the LCD instead phone.
Sorry for too much question, i'm new in this kind of stuff.
thanks in advance :)

chienline made it!(author)2016-06-25

In this instructable I did connect it to LCD through I2C didn't I? Or do you mean LCD TV? Then that would need a lot of work to be done. We need to learn how data is transfered through HDMI cable for example. Or you need a wifi shield to communicate if you have wifi enabled smart tv ^_^
But I think you don't need that much effort just to know how much power remains on your batteries :D

About This Instructable




Bio: Just an ordinary person who loves #thinking and #tinkering
More by chienline:Carabiner ShootoutUnusual Uses of Ice Cube TrayMusic Notes Cube
Add instructable to: