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 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

void setup()
{
lcd.begin (16,2); //My LCD was 16x2
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
lcd.home (); // go home

pinMode(led_pin, OUTPUT);
digitalWrite(led_pin, LOW);
}

void loop()
{
printVolts();
}

void printVolts()
{
float voltage = sensorValue * (5.00 / 1023.00) * 2; //convert the value to a true voltage.
lcd.setCursor(0,0);
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 :)

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.
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.<br><br>If you don't need the battery indicator then your 6V battery can goes directly into VIN pin which can handle up to 12V.<br><br>How will you bring down the voltage to get more current? Dropping the voltage to 3V will shut down the Arduino doesn't it?
<p>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!<br><br>Thanks</p><p>Glen</p>
That's great. You're welcome ^^
Sir I need the various camand for various voltage level what can I do
<p>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.</p><p>You should take between the first and the second resistors CLOSEST TO GROUND (negative of battery) those are <strong>R5</strong> and <strong>R6</strong> in the picture and wire it to Arduino analog pin A0.</p><p>Concentrate. If you plug somewhere at where I mark with red <strong>A</strong> to<strong> E,</strong> then BOOM!! you will lost your Arduino pin, or worst, the whole Arduino :(</p><p>Because the voltages there are higher than that 5V Arduino pin can handle.</p><p>Don't forget to change the sketch with<strong> *6</strong> to convert into true voltage :</p><blockquote>float voltage = sensorValue * (5.00 / 1023.00) * 2; //convert the value to a true voltage.</blockquote><p>to </p><blockquote>float voltage = sensorValue * (5.00 / 1023.00) * 6; //convert the value to a true voltage.</blockquote><p>With 6 resistors, you can measure battery up to 30V. Just remember to concentrate on wiring the A0 pin, that is near the Ground. ^^</p>
Thanks alot sir for this project <br>i used it without lcd change it to serial <br>i have a problem reading the values <br>when i put 3.7v battery it gives me 4.6<br>when i used 4.1v battery it gives me 3.9v <br>what should i do ?
<p>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 &quot;<strong>//convert the value to a true voltage</strong>&quot; and remove the &quot; <strong>* 2</strong>&quot;.</p>
I know i have done all of these <br>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<br>wht ahould i do ?
<p>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 ;)</p>
<p>I made it Sir Thank you</p>
You are welcome ^^
<p>I made one with LED. I was wondering what needs to be cahnged to use a 12V battery. Any advices?</p>
​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.<br>Let's say the voltage divider circuit is now :<br>BatteryPossitive -- R1 -- R2 -- R3 -- BatteryNegative/GND<br>Run a jumper wire from between R2 -- R3 to Arduino A0.<br>Then you need to change the code from &quot;*2&quot; to &quot;*3&quot; where we calculate back to RealVoltage to be shown on LCD.<br><br><br>Hope this help ^^
Thank you, I did it and it worked perfectly!
You are welcome ^^
<p>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</p>
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.
float voltage = sensorValue * (5.00 / 1023.00); please explain this formula how u got this ?
<p>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 &quot;800&quot; (eight hundred). We need a voltage from that reading so it is : 800/1023 * 5 V = 3.91 V.</p><p>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.</p>
Thank u
<p>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 ?</p><p>If not , can you give me some recommendation circuit </p>
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:<br><br>float voltage = sensorValue * (5.00 / 1023.00) * 2; //convert the value to a true voltage.<br><br>to this one:<br><br>float voltage = sensorValue * (5.00 / 1023.00); //convert the value to a true voltage.<br><br>That is removing &quot;*2&quot; because your battery's voltage is below 5V and can be handled by Arduino pin directly without voltage divider.
<p>Great tutorial, thank you :) could you explain me two thing please :</p><p>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? </p><p>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?</p><p>Thank you</p>
<p>Congratulation you have made it :)</p><p>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.</p><p>It is important to use the same value resistors and connect your A0 at the middle of those resistors. It means we <strong>divide the battery voltage into half for A0 to read</strong> (max 5V), then we <strong>double the reading in the sketch</strong> 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.</p><p>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.</p><p>If you plug A0 after resistor2, you will read zero voltage because your A0 is now connected to Ground.</p>
<p>I have used two 4.75 Kohm resistors. But I cannot get any output in the display.It is only glowing nothing else.</p><p>where I need to change the code.</p>
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).
<p>is there anyone who can point me in the direction of something that can tell how much power is left while im using it<br><br>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. <br><br>any one can point me in the right direction would be great?</p>
<p>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 :</p><p>lcd.print((sensorValue * (5.00 / 1023.00) * 2)/8*100);</p><p>Supposing my 7.4V battery can be fully charged to 8 volts ^^ </p><p>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 ^^</p>
<p>is there a reason why this might start rolling the voltage down?</p>
rolling the voltage down? I don't get what you mean by that. Could you please explain a little bit?
<p>the voltage is dropping slowly in increments of .01 volts</p>
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.
So from what i understand you cam read higher voltages by adding more resistors? How woukd you read a 22.2v lipo for example? <br><br>Is there any way to out but the signal over bluetooth to an OLED display in say a controller?
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.<br><br>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?<br>I would say you build an android controller app so you can read the message sent from bluetooth and dispay it in your app :)
<p>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 &quot;trust&quot; 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?</p>
<p>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.</p><p>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.</p><p>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 :</p><blockquote>float voltage = sensorValue * (5.00 / 1023.00) * 3;</blockquote><p>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 :)</p>
<p>Completely understand now! Thanks ;) Side note: do you know why when A0 is disconnected with this script running the board still reports ~3.3v?</p>
<p>Never leave a <strong>defined pin</strong> 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 <strong>*2</strong> give you a reading around 3.3v. Even your hand touching the Arduino can interfere the unconnected pin.</p><p>The best workaround for this is giving a 10K or 47K resistor between A0 and GND to serve as <strong>pull-down resistor</strong>. 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 :)</p>
<p>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?</p>
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 :)
<p>I have weird bug when my battery voltage is higher voltage value drops</p><p>can you help me?</p><p>int sensorValue = analogRead(A2);</p><p> float voltage = sensorValue * (5.00 / 1023.00);</p><p>i deleted *2 because then voltage was like 6 volts and my battery was 3,93</p>
<p>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.</p><p>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 :)</p>
<p>Ohh Thanks :D</p>
<p>I love it, thank you so much!!</p><p>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.</p><p>Works like a charm :-)</p>
<p>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 :)</p>
<p>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?</p>
It is possible. You can send the voltage reading through bluetooth serial to your phone instead of printing it on the LCD.<br>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 :)
hi author, how can i transfer the voltage reading to the LCD? is there a special device for it?<br>Because i think it's a lot easier to know the voltage reading on the LCD instead phone. <br>Sorry for too much question, i'm new in this kind of stuff.<br>thanks in advance :)
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 ^_^<br>But I think you don't need that much effort just to know how much power remains on your batteries :D