Project showcase

A realtime battery indicator for your project without extra components or using any analog I/Os.

• 71,276 views
• 112 respects

## Components and supplies

 Arduino UNO
×1
 LCD 16x2 Shield
×1

## Apps and online services

 Arduino IDE

Several times I've wished I had a battery indicator in my battery-powered projects, but it uses so many custom characters in the LCD and sacrifice analog input for voltage indication and components and connections. So we decided to do it the smart way and push the Arduino to its limits "as we always do" and get the maximum out of it.

In this project we use only one custom character from the LCD. So you still have seven free custom characters to use in your project. We also used the trick of reff voltage to get the input voltage from the Arduino without using any analog inputs or components, looks like the complete package.

All you have to is add the function that displays the indicator in the loop function and add the place where you wanted to display it and you are ready.

Enjoy

## Code

##### Battery indicatorC/C++
```#include <LiquidCrystal.h>
// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup() {
// Initialize LCD
lcd.begin(16 , 2);
}

void loop() {
// load battery icon on position 15,0
batterylevel(15,0);

}
//draw battery level in position x,y
void batterylevel(int xpos,int ypos)
{
//read the voltage and convert it to volt
double curvolt = double( readVcc() ) / 1000;
// check if voltge is bigger than 4.2 volt so this is a power source
if(curvolt > 4.2)
{
byte batlevel[8] = {
B01110,
B11111,
B10101,
B10001,
B11011,
B11011,
B11111,
B11111,
};
lcd.createChar(0 , batlevel);
lcd.setCursor(xpos,ypos);
lcd.write(byte(0));
}
if(curvolt <= 4.2 && curvolt > 4.0)
{
byte batlevel[8] = {
B01110,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
};
lcd.createChar(0 , batlevel);
lcd.setCursor(xpos,ypos);
lcd.write(byte(0));
}
if(curvolt <= 4.0 && curvolt > 3.8)
{
byte batlevel[8] = {
B01110,
B10001,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
};
lcd.createChar(0 , batlevel);
lcd.setCursor(xpos,ypos);
lcd.write(byte(0));
}
if(curvolt <= 3.8 && curvolt > 3.6)
{
byte batlevel[8] = {
B01110,
B10001,
B10001,
B11111,
B11111,
B11111,
B11111,
B11111,
};
lcd.createChar(0 , batlevel);
lcd.setCursor(xpos,ypos);
lcd.write(byte(0));
}
if(curvolt <= 3.6 && curvolt > 3.4)
{
byte batlevel[8] = {
B01110,
B10001,
B10001,
B10001,
B11111,
B11111,
B11111,
B11111,
};
lcd.createChar(0 , batlevel);
lcd.setCursor(xpos,ypos);
lcd.write(byte(0));
}
if(curvolt <= 3.4 && curvolt > 3.2)
{
byte batlevel[8] = {
B01110,
B10001,
B10001,
B10001,
B10001,
B11111,
B11111,
B11111,
};
lcd.createChar(0 , batlevel);
lcd.setCursor(xpos,ypos);
lcd.write(byte(0));
}
if(curvolt <= 3.2 && curvolt > 3.0)
{
byte batlevel[8] = {
B01110,
B10001,
B10001,
B10001,
B10001,
B10001,
B11111,
B11111,
};
lcd.createChar(0 , batlevel);
lcd.setCursor(xpos,ypos);
lcd.write(byte(0));
}
if(curvolt < 3.0)
{
byte batlevel[8] = {
B01110,
B10001,
B10001,
B10001,
B10001,
B10001,
B10001,
B11111,
};
lcd.createChar(0 , batlevel);
lcd.setCursor(xpos,ypos);
lcd.write(byte(0));
}
}
long result;
// Read 1.1V reference against AVcc
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
delay(2); // Wait for Vref to settle
result = 1126400L / result; // Back-calculate AVcc in mV
return result;
}
```

• 7 projects
• 84 followers

April 15, 2017

#### Members who respect this project

and 104 others

See similar projects
you might like

#### Solar Charged Battery Powered Arduino Uno

Project in progress by Igor Fonseca Albuquerque

• 153,958 views
• 224 respects

#### Arduino Toolboxes : Analog Level Visualizer

Project showcase by Arduino World

• 14,521 views
• 38 respects

• 67,926 views
• 171 respects

#### Simple Arduino Battery Capacity Tester

Project showcase by sim-flynn-13

• 34,899 views
• 39 respects

#### Solar Panel Sun Tracker - Phone Charger

Project tutorial by FIELDING

• 99,309 views