Introduction
LED bar-graph displays are much popular in battery level indication, water level indicator applications. Most of the inverter units have LED bar-graph display on its front panel. As we have seen in previous application we used only one LED to indicate battery level. With reference to above application we are showing voltage level on LED bar-graph display. Bar-graph display has multiple LEDs 8 or 10 LEDs in a column. One terminal is common and other terminals are used for giving supply. It is available in common cathode and common anode, with different color and size options.
Problem Statement
In this example we use 10 LED bar-graph to show voltage level from 0 to 5V. Zero volt corresponds to all led off and 5V to all LEDs on. As we know that to operate 10 LED’s we need 10 IO Lines but in all our examples we focus on minimum IO lines utilization. For this example we use low cost 74HC595 8-bit shift register with latch. Refer its datasheet for more information. We need only three IO lines to control this shift register output. Shift register take input in serially Data, Clock. Third line we need is “Latch” when we are putting data in shift register it will not affect previous status of its output until we give latch pulse.
Circuit Connections of Bargraph Display with Arduino
Before we move to bargraph display connection with arduino, Lets understand Bargraph display pin connections. Pin no 1 can be identified by the bevel, normally 330 Ohm to 1 K Ohm resistor is used for current limiting at 5V supply. For 12V supply use 4.7K Ohm current limiting resistor. From the figure 3.2 you can clearly understand that bargraph displays are simply LED’s connected in a row.
Let’s understand pins of 74HC595 8-bit shift register. It has eight outputs QA to QH, Operating supply voltage is from 2 to 6V, we connect Vcc (Pin 16) to 5V. Pin 8 is ground.
SER Pin 14: At this pin we give data to be shifted in the shift register. It is Data Pin.
OE Pin 13: It is active low pin, when we connect it to ground (logic 0) the outputs are enabled, when this pin is at logic 1, outputs are in tri-state.
RCLK Pin 12: At rising edge of input pulse Contents of Shift Register transferred to output latches. It is Latch Pin.
SRCLK Pin 11: Clock input pin, data is shifted in when clock pulse is given.
SRCLR Pin 10: Active low pin when this pin becomes low shift register is cleared. Connect it to Vcc (Logic 1).
QH Pin 9: Serial Data out used to connect multiple shift registers in series. Useful when we want to connect more than 8 LED’s.
Arduino Code for Voltage Bargraph Display
/* Displays Voltage 0 to 5V in 10 Steps on Bargraph www.circuits4you.com */ //Define 74HC595 Connections with arduio const int Data=6; const int Clock=7; const int Latch=5; const int LED0=3; const int LED1=4; //============================================================= // Setup //============================================================= void setup() { // initialize the digital pin as an output. pinMode(Data, OUTPUT); pinMode(Clock, OUTPUT); pinMode(Latch, OUTPUT); pinMode(LED0, OUTPUT); pinMode(LED1, OUTPUT); AnimateDisplay(); //Animate once } //============================================================= // Loop //============================================================= void loop() { int Voltage=analogRead(A0); Voltage = Voltage / 102; //Scaling of 0 to 5V i.e. 0 to 1023 to 0 to 10 (in 10 steps). You can use map command also DisplayBar(Voltage-2); //Control bottom Two LEDs if(Voltage>0){digitalWrite(LED0,HIGH);} else{digitalWrite(LED0,LOW);} if(Voltage>1){digitalWrite(LED1,HIGH);} else{digitalWrite(LED1,LOW);} delay(200); } //============================================================= // Generates Bargraph //============================================================= void DisplayBar(char d) { int i; digitalWrite(Data,HIGH); //Put Number of LED's to turn on for(i=0;i<d;i++) { digitalWrite(Clock,LOW); delay(1); digitalWrite(Clock,HIGH); delay(1); } digitalWrite(Data,LOW); //Put remaining Zeros to keep LED's off for(i=0;i<(8-d);i++) { digitalWrite(Clock,LOW); delay(1); digitalWrite(Clock,HIGH); delay(1); } //Latch the data digitalWrite(Latch,LOW); delay(1); digitalWrite(Latch,HIGH); } //============================================================= // Animate Display //============================================================= void AnimateDisplay() { int i; //Bargraph goes upwards digitalWrite(LED0, HIGH); //First Two LEDs delay(100); digitalWrite(LED1, HIGH); delay(100); for(i=1;i<9;i++) //Display rising bargraph { DisplayBar(i); delay(100); } //Bargraph goes downwords for(i=8;i>=0;i--) //Display falling bargraph { DisplayBar(i); delay(100); } digitalWrite(LED1, LOW); //Turn off First Two LEDs delay(100); digitalWrite(LED0, LOW); delay(100); } //=============================================================
Results
Turn the variable resistor to vary voltage on ADC Channel A0 and observe that Bargraph shows the voltage level according to voltage value. In this example we used five IO lines to control display, three IO lines to control 8-bit shift register and 2 for remaining LEDs. The advantage of this you can make blinking of bottom LED’s easily.