Large Size Bar-Graph Voltage Monitor Using Arduino Mega and 20 Segment 3W White LED

Simple 20 LED  Bar-Graph Voltmeter , each LED display 0.25V, this circuit can measure 5V directly or its can measure higher voltage range using resistor divider. 

Example circuit for resistor divider. If choose Z1=10K and Z2-10K it can measure 0-10V.

Turns on a series of 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.

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.

Download Arduino Code

Download PDF Schematic

Watch Video Of This Project



Arduino Code


/*
* 20 LED Bargraph Meter , 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);
}
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *