Skip to content

An Arduino beginner project that demonstrates how to create an LED bar graph using multiple LEDs controlled by a potentiometer. The project uses analog input mapping to light LEDs in sequence, similar to a volume level indicator.

Notifications You must be signed in to change notification settings

sarvacX/Arduino-LED-Bar-Graph-Potentiometer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

📊Arduino LED Bar Graph with Potentiometer

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.


🎯 Introduction / Objective

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

⚙️ Components Used

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.

🔌 Circuit Diagram / Wiring

LED Connections

  • Arduino Pins 2–10220Ω resistorLED anode (+)
  • LED cathode (–)GND

Potentiometer Connections

  • Center pinArduino A0
  • One outer pin+5V
  • Other outer pinGND

🔄 Note: Swapping the outer pins reverses the direction of LED increase/decrease.

🧩 Breadboard View

Breadboard View

📐 Schematic View

Schematic Diagram

⚙️ How It Works

This project uses a potentiometer to control how many LEDs are turned ON, creating a visual LED bar graph.

Step-by-Step Explanation

  1. The potentiometer provides an analog voltage between 0V and 5V.
  2. Arduino reads this voltage as a value between 0 and 1023 using analogRead().
  3. The map() function converts this value into a range of 0 to 9 (number of LEDs).
  4. A for loop checks each LED:
    • If its position is less than the mapped value, the LED turns ON.
    • Otherwise, the LED stays OFF.
  5. As the potentiometer knob is turned, LEDs light up or turn off in sequence, forming a bar graph effect.

🧠 Simple Example

Potentiometer Position LEDs ON
Low 1–2 LEDs
Medium 4–6 LEDs
High All LEDs

🔄 Simple Logic Flow

Start -> Read Potentiometer (0–1023) -> Map value to LED count (0–9) -> Turn ON LEDs up to mapped value -> Turn OFF remaining LEDs -> Repeat

💻 Code Explanation

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
    }
  }
}

🎬 Demo / Result

▶️ Watch Demo Video

🧩 Challenges and Learning

🔹 Challenges Faced

  • Fixing LED wiring when only one LED lit up
  • Understanding how map() converts ranges

🔹 What I Learned

  • 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

🚀 Next Steps / Enhancements

  • 🔊 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

About

An Arduino beginner project that demonstrates how to create an LED bar graph using multiple LEDs controlled by a potentiometer. The project uses analog input mapping to light LEDs in sequence, similar to a volume level indicator.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages