In this beginner-friendly Arduino project, you'll learn how to create an LED bar graph that responds to a potentiometer. Using nine LEDs, a 50k-ohm potentiometer, and core programming concepts like map() and for loops, this project from the Arduino Project Handbook is perfect for honing your electronics skills.
What You'll Need
- Arduino Uno
- 9 LEDs (any color)
- 9 220-ohm resistors
- 1 50k-ohm potentiometer
- Breadboard and jumper wires
How It Works
The potentiometer acts as a variable voltage divider, feeding an analog signal to the Arduino. The map() function scales the potentiometer's reading (0–1023) to a range of 0–9, determining how many LEDs light up. A for loop then turns on the corresponding number of LEDs, creating a bar graph that visually represents the potentiometer's position.
Wiring Instructions
- Connect each LED's anode (long leg) to Arduino digital pins 2 through 10 through a 220-ohm resistor.
- Connect each LED's cathode (short leg) to the ground rail.
- Wire the potentiometer: one outer leg to 5V, the other outer leg to GND, and the center wiper to analog pin A0.
Code Example
int potPin = A0;
int ledPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10};
void setup() {
for (int i = 0; i < 9; i++) {
pinMode(ledPins[i], OUTPUT);
}
}
void loop() {
int potValue = analogRead(potPin);
int ledLevel = map(potValue, 0, 1023, 0, 9);
for (int i = 0; i < 9; i++) {
if (i < ledLevel) {
digitalWrite(ledPins[i], HIGH);
} else {
digitalWrite(ledPins[i], LOW);
}
}
}
Testing
Upload the code to your Arduino. As you turn the potentiometer, the LEDs should light up sequentially from left to right, forming a bar graph that indicates the potentiometer's position.
This project is an excellent introduction to analog input, mapping values, and controlling multiple outputs. Once mastered, you can expand it to use different sensors or increase the number of LEDs for finer resolution.