Single LED as Voltage Level Indicator

Introduction

In many circuits we need to display battery voltage level, most of the battery operated device need indication for battery level such as solar lamp, charger circuits. LEDs are most popular to show status of system such as power on/off, Level indication Low, High, Medium etc. LEDs are available in various sizes and colors, they are simple to use and offer design flexibility. Let’s start with our first example LED as voltage level indications. This can be useful in battery level indication applications.

What we learn?

  1. How to read battery voltage using arduino?
  2. How to display battery voltage level?
  3. How to operate single LED to show different voltage levels?

Problem Statement

We are using single led to indicate the voltage levels at three different conditions.

Voltage vs LED status

Voltage input LED state
No voltage (0V) Off
Voltage below 0.5V to 3.3V Slow Blink
Voltage above 3.3V to 4V Fast Blink
Voltage above 4V On

LED Connections with Arduino

            From problem statement we know that we have a LED on Arduino and Measurement of DC voltage from ADC channel, Let us consider we are using on board LED (pin 13) and we are applying onboard voltage to ADC channel A0 through a potentiometer.

Arduino Battery Level Indicator
Tutorial on how to use single led as voltage level indicator with arduino.

Arduino Code for Voltage Indicator

/*
  Voltage Level Indication using Blink
  1. < 0.5V - LED Off
  2. 0.5 to 3.3V - Slow Blinking
  3. 3.3 to 4V - Fast Blinking
  4. >4V - LED On
  www.circuits4you.com 
*/
const int LED=13;        //LED connections
const int VoltageIn=A0;  //Inpput voltage pin

void setup() {                
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  pinMode(LED, OUTPUT);       
}

void loop() {
  
  double Voltage=analogRead(VoltageIn);
  
  Voltage = (5.0/1024.0) * Voltage;  //Convert Digital value 0- 1024 into 0 to 5V scale
  
  if(Voltage < 0.5)
  {
    digitalWrite(LED,LOW);  //Turn off LED for 0V
  }
  if((Voltage >= 0.5) && (Voltage < 3.3))    //&& is used for logical Anding
  {
    digitalWrite(LED,HIGH);    //Turn on LED
    delay(500);               //1 Sec Delay as wee need slow blink
    digitalWrite(LED,LOW);     //Turn off LED
    delay(500);               //1 Sec Delay
  }
 
  if((Voltage >= 3.3) && (Voltage < 4.0))    //Fast Blinking
  {
    digitalWrite(LED,HIGH);    //Turn on LED
    delay(100);               //1 Sec Delay as wee need slow blink
    digitalWrite(LED,LOW);     //Turn off LED
    delay(100);               //1 Sec Delay
  }
  
   if(Voltage >= 4.0)
  {
    digitalWrite(LED,HIGH);  //Turn on LED for > 4V
  }
}

Result:

By turning the potentiometer generate different voltages conditions and observe LED status.

Leave a Reply