
Video
Circuit Diagram

Source Code
1int ledPins[] = {2, 3, 4, 5, 6, 7};
2int potValue;
3
4void setup() {
5 for(int i = 0; i < 6; i++) {
6 pinMode(ledPins[i], OUTPUT);
7 }
8}
9
10void loop() {
11 for(int i = 0; i < 6; i++) {
12 potValue = analogRead(A0);
13 digitalWrite(ledPins[i], HIGH);
14 delay(potValue);
15 digitalWrite(ledPins[i], LOW);
16 }
17}FAQ
What values does `analogRead` return?▾
The Uno's analog inputs read 0–5 V with 10-bit resolution and return a value between 0 and 1023. As the potentiometer is turned from one end to the other, the value changes from 0 to 1023.
How do we convert the potentiometer reading to speed?▾
Using the `map()` function, you can convert the 0–1023 range to any delay range you want (e.g., 20–500 ms): `map(value, 0, 1023, 20, 500)`. When this value is used inside `delay()`, the speed changes instantly.
How do you connect the leads of a potentiometer?▾
The two outer pins are connected to 5 V and GND, and the middle pin (wiper) is connected to an analog input (e.g., A0). If you connect the outer pins in reverse, only the rotation direction will reverse; the circuit will not be damaged.
Changes in speed are detected with a delay—why?▾
If the potentiometer is read only at the beginning of the loop, the new value is not applied until all the LEDs have lit up. If you include the reading within each LED step, the speed changes instantly.
