An Arduino beginner project that demonstrates how to create an LED bar graph using multiple LEDs controlled by a potentiometer, similar to a volume or level indicator.
This project demonstrates how to read an analog input using a potentiometer and display the result visually using a row of LEDs (LED bar graph).
As the potentiometer knob is rotated:
- Turning one way → more LEDs light up
- Turning the other way → LEDs turn off in sequence
| Component | Quantity | Description |
|---|---|---|
| Arduino UNO | 1 | Microcontroller board |
| Breadboard | 1 | For prototyping |
| LEDs | 9 | Used to form the LED bar graph |
| Resistors (220Ω) | 9 | Current limiting for LEDs |
| Potentiometer (50kΩ) | 1 | Used as analog input control |
| Jumper Wires | As needed | Circuit connections |
💡 Note: The project originally specifies a 50 kΩ potentiometer, but a 47 kΩ potentiometer was used by me.
This does not affect functionality, as both values behave almost the same in this application.
- Arduino Pins 2–10 → 220Ω resistor → LED anode (+)
- LED cathode (–) → GND
- Center pin → Arduino A0
- One outer pin → +5V
- Other outer pin → GND
🔄 Note: Swapping the outer pins reverses the direction of LED increase/decrease.
This project uses a potentiometer to control how many LEDs are turned ON, creating a visual LED bar graph.
- The potentiometer provides an analog voltage between 0V and 5V.
- Arduino reads this voltage as a value between 0 and 1023 using
analogRead(). - The
map()function converts this value into a range of 0 to 9 (number of LEDs). - A
forloop checks each LED:- If its position is less than the mapped value, the LED turns ON.
- Otherwise, the LED stays OFF.
- As the potentiometer knob is turned, LEDs light up or turn off in sequence, forming a bar graph effect.
| Potentiometer Position | LEDs ON |
|---|---|
| Low | 1–2 LEDs |
| Medium | 4–6 LEDs |
| High | All LEDs |
Start -> Read Potentiometer (0–1023) -> Map value to LED count (0–9) -> Turn ON LEDs up to mapped value -> Turn OFF remaining LEDs -> Repeat
const int analogPin = A0; // Pin connected to the potentiometer
const int ledCount = 9; // Number of LEDs
int ledPins[] = {2,3,4,5,6,7,8,9,10}; // Pins connected to the LEDs
void setup() {
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
pinMode(ledPins[thisLed], OUTPUT); // Set LED pins as OUTPUT
}
}
void loop() {
int sensorReading = analogRead(analogPin); // Read analog input (0–1023)
// Map the sensor value to the number of LEDs
int ledLevel = map(sensorReading, 0, 1023, 0, ledCount);
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
if (thisLed < ledLevel) {
digitalWrite(ledPins[thisLed], HIGH); // Turn LED ON
} else {
digitalWrite(ledPins[thisLed], LOW); // Turn LED OFF
}
}
}- Fixing LED wiring when only one LED lit up
- Understanding how
map()converts ranges
- How to convert analog values into useful output ranges
- Using arrays and loops to control multiple outputs
- How LED bar graphs are used in audio level meters
- 🔊 Replace potentiometer with a microphone to create an audio VU meter
- 📟 Add an OLED/LCD display to show numeric values
- 🌈 Use RGB LEDs for color-based level indication

