Arduino Project Hub
Project showcase

Arduino Addons : Battery Level Indicator © GPL3+

A RealTime Battery Indicator For Your Project Without Extra Components Or Using Any Analog I/Os

  • 1,841 views
  • 6 comments
  • 23 respects

Components and supplies

Apps and online services

About this project

Several Times I Had Wished I Have a Battery Indicator In My Project That Is Powered By Battery 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 That 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 And 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 To Have It .

Enjoy

Download Code

Schematics

Schema
Lcd keypad shield diagram pinout wiring configuration schematics exfbetirpa

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));
  }
}
//read internal voltage
long readVcc() {
  long result;
  // Read 1.1V reference against AVcc
  ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  delay(2); // Wait for Vref to settle
  ADCSRA |= _BV(ADSC); // Convert
  while (bit_is_set(ADCSRA, ADSC));
  result = ADCL;
  result |= ADCH << 8;
  result = 1126400L / result; // Back-calculate AVcc in mV
  return result;
}

Comments

Similar projects you might like

An Arduino-Powered Easter Egg Printer

Project showcase by ELEKS

  • 1,281 views
  • 0 comments
  • 18 respects

Automatic Fear 1.0

Project tutorial by Alexis Santiago Allende

  • 291 views
  • 1 comment
  • 5 respects

End-Effector and Control Logic for Robot

Project showcase by Team PowerBerry

  • 3,157 views
  • 2 comments
  • 24 respects

Pi Time - A Fabric Arduino Clock

Project showcase by Team Chris And Jessica Hogan

  • 2,999 views
  • 2 comments
  • 14 respects

Arduino Toolboxes : Analog Level Visualizer

Project showcase by Arduino World

  • 4,234 views
  • 14 comments
  • 20 respects

Robotic Arm Control Using Bluetooth, Arduino and Android App

Project tutorial by Team http://lovelyideas.in/

  • 741 views
  • 1 comment
  • 9 respects
Add projectSign up / Login