Overview
The LED blinks with equal on and off times. The potentiometer chooses one of five speeds: 1000, 800, 600, 400 or 200 ms per phase. The slowest setting gives one blink every two seconds, the fastest 2.5 blinks per second.
You will need
- Arduino Uno R3 and USB cable
- 10 kΩ potentiometer (5 mm leg pitch)
- LED and a 220–330 Ω resistor, or an LED module with a built-in resistor
Wiring
| Uno pin | Connects to | Notes |
|---|---|---|
| A0 | Potentiometer outer leg | Sketch sets A0 as an OUTPUT, LOW. This is the pot's 0 V end. |
| A2 | Potentiometer wiper (middle leg) | Analog input. Reads 0–1023. |
| A4 | Potentiometer other outer leg | Sketch sets A4 as an OUTPUT, HIGH. This is the pot's 5 V end. |
| 11 | LED anode (long leg) through a 220–330 Ω resistor | The blinking output. |
| 12 | LED cathode (short leg, flat side) | Sketch sets pin 12 as an OUTPUT, LOW, so it acts as the LED's ground. |
How the pins are arranged
This project powers the potentiometer from analog pins instead of the 5V and GND sockets. A 10 kΩ
potentiometer has three legs about 5 mm apart, which matches every second socket on the Uno's analog
header. Push its outer legs into A0 and A4 and its wiper into A2. The
sketch sets A0 as a LOW output (0 V) and A4 as a HIGH output (5 V), so the pot sees a full 0–5 V
span and the wiper on A2 reads anywhere from 0 to 1023.
This works because a 10 kΩ pot draws only about 0.5 mA, far below what a pin can supply. Do not use this trick with a pot under about 5 kΩ, and keep in mind that A4 is also the I²C data line (SDA): the pot and an I²C device cannot share it. See Using analog pins as digital outputs for the details.
The LED sits between pins 11 and 12 exactly as in Variable-Duty LED Blinking: pin 11 drives the anode through a 220–330 Ω resistor and pin 12, held LOW, is the cathode's ground. A bare LED without a resistor must not be plugged straight into the sockets.
Diagrams
The sketch
int potentiometerReading;
int phaseDurationMs;
void setup() {
pinMode(A2, INPUT);
pinMode(A0, OUTPUT);
pinMode(A4, OUTPUT);
digitalWrite(A0, LOW);
digitalWrite(A4, HIGH);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
digitalWrite(12, LOW);
Serial.begin(9600);
}
void loop() {
potentiometerReading = analogRead(A2);
Serial.println(potentiometerReading);
int stepIndex = map(potentiometerReading, 0, 1024, 0, 5);
phaseDurationMs = 1000 - stepIndex * 200;
digitalWrite(11, HIGH);
delay(phaseDurationMs);
digitalWrite(11, LOW);
delay(phaseDurationMs);
}How the code works
map(…, 0, 1024, 0, 5) splits the reading into five equal bands (0–4), the same
technique as the five-position servo. The phase length is
1000 - stepIndex * 200: 1000, 800, 600, 400 or 200 ms.
The pot is read once per full blink, so at the slowest speed a change can take up to two seconds to show.
Review result: no changes were needed.
What you should observe
- The LED's on and off times are always equal.
- Turning the knob changes the speed in five distinct steps, not smoothly.
- The Serial Monitor (9600 baud) prints the reading once per blink.