Displaying Battery Life on a Liquid Crystal Display (LCD)

7,999

34

1

About: Spectre Tech will be out of commission for the next couple years to focus on development. If you like the following examples of what Spectre Tech has to offer, please follow and wait for new exciting projects!

Intro: Displaying Battery Life on a Liquid Crystal Display (LCD)

This Instructable is to provide a way of displaying the life of a battery on a LCD. This can be useful if you have a project that is powered from batteries. It'll provide an indication whether you need to change out your batteries. The code may also be adjusted to include an alarm or warning LED. The possibilities are up to you!

Step 1: Connecting LCD, Arduino and Battery Source (Wiring Diagram)

WARNING: DO NOT CONNECT GREATER THAN 5V TO THE ARDUINO'S ANALOG PINS. THIS COULD POTENTIALLY DESTROY THE MICROCONTROLLER OF THE ARDUINO.

Components Required:

Arduino Uno

Battery (0-5V)

(1) 10K Resistor

(1) 16x2 LCD (16 Pin)

Jumper Wires

Connect in accordance with the diagram above.

Step 2: Displaying Battery Life Using an Image

This first code displays battery life using a byte image on an LCD. It displays battery life at 100%, 75%, 50%, 25%, and blinks when 10% or less.

Step 3: Displaying Battery Life As a Percentage

This sketch allows you to display as a percentage on the LCD. The range is from 0% to 100%.

Step 4: Displaying Voltage As Read on a Multimeter

The last way is to actually display the exact voltage on the LCD.

If you look at line 16 in the image above, you'll notice the line of code as:

float volts = (voltReading/204.6);

To break this part down is crucial for using different voltage sources:

(1) float volts will display the voltage value in a decimal fashion. If you want a whole number, replace float with int.

(2) Depending on the voltage your reading, the number you use to divide is decided by the maximum of the actual voltage source you are measuring. As you can see the number is 204.6. This number was created by taking 1023 (the maximum reading of a fully charged battery) and divided by the maximum voltage of the battery you are using. In this case, I used a 5V battery so I used 1023/5 = 204.6. You then use 204.6 to divide by. If you use a 3V source, then 1023/3 = 341. Then you would divide by 341 to display battery voltage ranging from 0V to 3V vice 0V to 5V.

Share

    Recommendations

    • Electronics Tips & Tricks Challenge

      Electronics Tips & Tricks Challenge
    • Optics Contest

      Optics Contest
    • Audio Contest 2018

      Audio Contest 2018

    Discussions

    0
    None
    beic

    Question 3 months ago

    Nice article indeed, but iIf I have a voltage divider and I want to check 12v and 24v, what value need to use? Or can you give me the calculation formula? Thx!