Project showcase

Arduino Addons : Battery Level Indicator © GPL3+

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

  • 3,619 views
  • 12 comments
  • 30 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

Arduino Bike Blink Lights

by Sam

  • 448 views
  • 2 comments
  • 8 respects

Control RGB LED by Dragging – Arduino 101 & App Inventor

Project tutorial by CAVEDU Education and DFRobot

  • 212 views
  • 0 comments
  • 4 respects

Smart Garden

Project showcase by patel Dipen

  • 764 views
  • 1 comment
  • 7 respects

WiDC: Wi-Fi-Controlled FPV Robot

Project tutorial by Igor Fonseca Albuquerque

  • 4,981 views
  • 3 comments
  • 32 respects

Sienci Mill One - Simple and Affordable Desktop CNC

Project tutorial by Sienci Labs Team

  • 7,671 views
  • 2 comments
  • 37 respects

MEGA BREAD - Atari Joystick Linking for Robotics Control

Project in progress by Pigeon-Kicker

  • 298 views
  • 3 comments
  • 6 respects
Add projectSign up / Login