int potPin = A0; // Potentiometer connected to analog pin A0
int ledPins[] = {2, 3, 4, 5, 6}; // Digital pins for the LEDs
int ledRanges[] = {0, 200, 400, 600, 800, 1000}; // LED ranges
int numLeds = sizeof(ledPins) / sizeof(ledPins[0]); // Number of LEDs
void setup() {
Serial.begin(9600); // Initialize serial communication at 9600 baud
for (int i = 0; i < numLeds; i++) {
pinMode(ledPins[i], OUTPUT); // Set LED pins as output
}
}
void loop() {
int potValue = analogRead(potPin); // Read the analog value from the potentiometer
for (int i = 0; i < numLeds; i++) {
if (potValue >= ledRanges[i] && potValue < ledRanges[i + 1]) {
digitalWrite(ledPins[i], HIGH); // Turn on the LED for the corresponding range
} else {
digitalWrite(ledPins[i], LOW); // Turn off the LED if not in its range
}
}
delay(100); // Wait for a short time before reading again
}