20 LED Bar-Graph Voltmeter Using Arduino Mega

Simple 20 LED Segment Bar-Graph Voltmeter , each LED display 0.25V, this circuit can measure 5V directly or it can measure higher voltage using resistor divider.
Turns on a series of blue LEDs based on the value of an analog voltage input. This is a simple way to make a bar graph display. Though this graph uses 20 LEDs, you can use any number by changing the LED count and the pins in the array. This method can be used to control any series of digital outputs that depends on an analog input.
Potentiometer is connected to Analog pin A0 of Arduino Mega, VCC and GND
LED Connected to digital pin of Arduino Mega D22, D23, D24, D25, D26, D27, D28, D29, D30, D31, D32, D33, D34, D35, D36, D37, D38, D39, D40, D41
Note : Circuit can measure 5V DC voltage, High voltage can be measure using resistor divider.
The bar graph – a series of LEDs in a line, such as you see on an audio display – is a common hardware display for analog sensors. It’s made up of a series of LEDs in a row, an analog input like a Potentiometer, and a little code in between. You can buy multi-LED bar graph displays fairly cheaply, like this one. This tutorial demonstrates how to control a series of LEDs in a row, but can be applied to any series of digital outputs.



Arduino Code
/*
* 20 LED Bargraph Meter , Code writen for arduino mega, project consist
20 blue LED, ULN2003 X 3 as LED driver, code, schematic, PCB layout
available at our website www.twovolt.com
*/
// these constants won’t change:
const int analogPin = A0; // the pin that the potentiometer is attached to
const int ledCount = 20; // the number of LEDs in the bar graph
int ledPins[] = {
22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41
}; // an array of pin numbers to which LEDs are attached
void setup() {
// loop over the pin array and set them all to output:
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
pinMode(ledPins[thisLed], OUTPUT);
}
}
void loop() {
// read the potentiometer:
int sensorReading = analogRead(analogPin);
// map the result to a range from 0 to the number of LEDs:
int ledLevel = map(sensorReading, 0, 1023, 0, ledCount);
// loop over the LED array:
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
// if the array element’s index is less than ledLevel,
// turn the pin for this element on:
if (thisLed < ledLevel) {
digitalWrite(ledPins[thisLed], HIGH);
}
// turn off all pins higher than the ledLevel:
else {
digitalWrite(ledPins[thisLed], LOW);
}
}
}