Displaying Voltage on LCD with Arduino


Measuring the voltage of a single Li-Ion cell is the basis of any battery management system (BMS), like the one we’re designing for the school’s electric go-kart. This being our thesis – we are a team of three students of Electrical Engineering in our final year – sets some conditions on the design an implementation process. Obviously, we have to build a system, which reliably does what it has to do:

  • control the charging an balancing process (monitor voltage, current, temperature)
  • protect the battery form damage (over-charge and over-discharge)
  • calculate capacity and assess battery health
  • control an LCD display on the vehicle
  • communicate with a C# program

The first condition is time-efficiency. Since it’s an evening school, most of us have a job and some of us a family too. In our free time – I mean what remains after work, attending lectures and family -, we not only have to work on our thesis, but we also have to study for all the tests and exams throughout these final two semesters. We have to use our time well, doing the most in the least amount of time.

The second condition is a consequence of the first one: we have to find the simplest possible way to achieve what we want. There are a lot of cool, smart and advanced solutions possible with today’s technology. The problem is, that building or even just implementing them would be very time consuming. One good example is balancing. We’d love to build a nice, modern active-balancing system with flyback-converters and everything, but understanding and building such a system would take too much time for us. A passive-balancing system is not as advanced, yet gets the job done just as well and it can be built much more easily.

All of these reasons make the Arduino a perfect candidate. There are a lot of additional hardware (shields), libraries and tutorials available for this platform, making it relatively easy to build almost anything, BMS included.

So lets see, how the first step, which is measuring voltage, can be done. I go a little further than that and output the results on a 16×2 LCD display. Wiring the LCD is pretty easy, I won’t go into the details. Just watch this video, that’s how I did it.

I’m using the Arduino Mega 2560 form Sunfounder, becuase it’s got the most analog inputs and costs only about 18 € on Amazon. All the other stuff, including the LCD, came with a Raspberry Pi 2 kit I bought earlier. I just hooked up the LCD and a 50 kOhm poti to control the contrast and displayed the voltage of a 18650 Li-Ion battery (ignore the LED and the resistor on the right side, they just sit there in case I need them for something).

The only trick in the code is getting the voltage right. The battery is connected to one of the analog inputs and the voltage is converted to an integer from 0 to 1023 by the Arduino’s analog digital converter (ADC). This means, that the ADC’s resolution is 1024. It can measure voltage form 0 to 5 Volts in 1024 steps. So if you want to know the voltage, you have to convert the ADC’s output from the number it spits out to a number you can understand. You can do it by dividing this number by 204.8, which you get from dividing the resolution by the range: 1024 / 5. I just rounded it to 205 in the code, which you can see below:

#include <LiquidCrystal.h> // the LCD library

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // initiate pins
float volt;
int sensePin = 0; // analog input 0 is where the positive pole of battery is connected. The negative is connected to ground.

void setup() {
  analogReference(DEFAULT); // default reference is 5 V
  lcd.begin(16, 2); // set the size of the display

void loop() {
  volt = analogRead(sensePin) / 205.0; // reading and calculating voltage
  lcd.setCursor(0, 0); // set the cursor to the 1st row, 1st character
  lcd.print("Spannung: ");
  lcd.setCursor(0, 1); // set the cursor to the 2nd row, 1st character
  lcd.print(" V");
  delay(500); // do the whole thing over in every half second

It’s amazing how easy it is to measure something and display it on an LCD with the Arduino. Just wire it up, include the library, write the code and you’re done. Need to measure more, than 5 Volts? You can do it with a voltage divider. Want to measure current up to 30 A? No problem with a Hall effect sensor like the ACS712. There’s a great video about it too. Then, you can do almost anything by programming your logic and controlling all those inputs and outputs!


I enjoy microcontroller programming (AVR), programming in C/C#, playing with electronics, the Raspberry Pi and Arduino. My other passion is for IT - virtualization, PowerShell, servers and so on.

Tagged with: ,
Posted in Arduino

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Enter your email address to follow this blog and receive notifications of new posts by email.

Join 167 other followers

%d bloggers like this: