Battery level indicator

This device monitors battery voltage and shows it on 5 LED’s. Further development will include a use of AVR power saving functions. At this moment circuit uses 31mA. LED position vs. voltage:

  1. <= 12.05
  2. 12.06 – 12.25
  3. 12.26 – 12.45
  4. 12.46 – 12.65
  5. >= 12.66

Full lead acid battery has 12.7V and when it’s empty voltage is under 12.0V. Below is circuit diagram. All works just as planned. Simple math.

Here is Arduino code before power saving functions:

/* battLow2.ino
 * 
 * 
 */

void setup() {
  // initialize LED outputs
  pinMode(9,OUTPUT);
  pinMode(10,OUTPUT);
  pinMode(11,OUTPUT);
  pinMode(12,OUTPUT);
  pinMode(13,OUTPUT);

  // LED's to off state
  digitalWrite(9,HIGH);
  digitalWrite(10,HIGH);
  digitalWrite(11,HIGH);
  digitalWrite(12,HIGH);
  digitalWrite(13,HIGH);
}

void loop() {

  int val = analogRead(A5); // 0 to 1023

  // voltage divider input---56---22---gnd
  // (1023/17.727) * voltage
  if(val <= 695) {
    digitalWrite(9,LOW);
    digitalWrite(10,HIGH);
    digitalWrite(11,HIGH);
    digitalWrite(12,HIGH);
    digitalWrite(13,HIGH);
  } else if(val > 695 && val < 706) {
    digitalWrite(9,HIGH);
    digitalWrite(10,LOW);
    digitalWrite(11,HIGH);
    digitalWrite(12,HIGH);
    digitalWrite(13,HIGH);
  } else if(val >= 706 && val < 718) {
    digitalWrite(9,HIGH);
    digitalWrite(10,HIGH);
    digitalWrite(11,LOW);
    digitalWrite(12,HIGH);
    digitalWrite(13,HIGH);
  } else if(val >= 718 && val < 730) {
    digitalWrite(9,HIGH);
    digitalWrite(10,HIGH);
    digitalWrite(11,HIGH);
    digitalWrite(12,LOW);
    digitalWrite(13,HIGH);
  } else if(val > 730) { // 12.65
    digitalWrite(9,HIGH);
    digitalWrite(10,HIGH);
    digitalWrite(11,HIGH);
    digitalWrite(12,HIGH);
    digitalWrite(13,LOW);
  }
  
  delay(200);
}

After adding power saving things to code current consumption is only 18mA. It contains LED driving current and power dissipation of the linear regulator. AVR restarts every two seconds to make one ADC measurement.

/* battLow2.ino
 * 
 * Displays 12V lead acid battery voltage level on LED bar
 * 
 * Author: jpvarjonen@gmail.com
 * Copyright (C) 2019 Juha-Pekka Varjonen
 */

#include <avr/sleep.h>
#include <avr/wdt.h>
#include <avr/power.h>

void setup() {

  // power up every 2 seconds
  wdt_enable(WDTO_2S);
  // set sleep mode (not activated yet)
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  // disable things
  power_spi_disable();
  power_usart0_disable();
  power_twi_disable();
  power_timer0_disable();
  power_timer1_disable();
  power_timer2_disable();
  
  // initialize LED outputs
  digitalWrite(9,HIGH);
  digitalWrite(10,HIGH);
  digitalWrite(11,HIGH);
  digitalWrite(12,HIGH);
  digitalWrite(13,HIGH);
  pinMode(9,OUTPUT);
  pinMode(10,OUTPUT);
  pinMode(11,OUTPUT);
  pinMode(12,OUTPUT);
  pinMode(13,OUTPUT);

  int val = analogRead(A5); // 0 to 1023

  // disable ADC
  power_adc_disable();

  // voltage divider input---56---22---gnd
  // (1023/17.727) * voltage
  if(val <= 695) {
    digitalWrite(9,LOW);
  } else if(val > 695 && val < 706) {
    digitalWrite(10,LOW);
  } else if(val >= 706 && val < 718) {
    digitalWrite(11,LOW);
  } else if(val >= 718 && val < 730) {
    digitalWrite(12,LOW);
  } else if(val >= 730) { // 12.65
    digitalWrite(13,LOW);
  }

  // go to sleep (watchdog will restart)
  sleep_mode();
}

void loop() {
  // nothing here
}

Little improvement to circuit. Now it’s current consumption is only 11mA.