Circuit Creation

LED Pattern Control using Potentiometer

In this project, you will learn how to control multiple LEDs using a potentiometer. As you rotate the knob, LEDs turn ON step-by-step, creating a smooth bar-style pattern. This project is perfect for understanding analog input and multi-output control.

Beginner

Components Required

Circuit Connections

Follow these steps to connect the potentiometer and LEDs with Arduino:

  1. Connect potentiometer middle pin to A0.
  2. Connect other pins to 5V and GND.
  3. Connect LEDs to pins 3, 4, 5, 6, 7 using resistors.
  4. Connect LED cathodes to GND.
LED Pattern Circuit

The potentiometer controls how many LEDs turn ON, forming a progressive lighting pattern.

Arduino Code

                
int potPin = A0;
int leds[] = {3,4,5,6,7};

void setup() {
  for(int i=0;i<5;i++){
    pinMode(leds[i], OUTPUT);
  }
}

void loop() {
  int value = analogRead(potPin);
  int level = map(value, 0, 1023, 0, 5);

  for(int i=0;i<5;i++){
    if(i < level){
      digitalWrite(leds[i], HIGH);
    } else {
      digitalWrite(leds[i], LOW);
    }
  }

  delay(50);
}
                
                

Code Explanation

LED Array

The LED pins are stored in an array, allowing easy control using loops.

Analog Input

The potentiometer value is read using analogRead(), which gives values from 0 to 1023.

Mapping Values

The map() function converts the input into 5 levels, each representing an LED.

Pattern Logic

LEDs turn ON progressively depending on the potentiometer position, creating a bar pattern effect.

Common Mistakes & Troubleshooting

What You Learned