Overview
The LED blinks once per second, every second. Turning the potentiometer changes how that second is split: the LED stays on for 200 ms at one end of the dial and 800 ms at the other, and is off for the rest. The raw potentiometer reading streams to the Serial Monitor so you can watch the input while you turn it.
You will need
- Arduino Uno R3 (or compatible) and USB cable
- 10 kΩ potentiometer with legs on a 5 mm pitch
- LED (any colour) 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 goes between pin 11 and pin 12, which are neighbours on the header. Pin 12 is set LOW so it serves as the LED's ground; pin 11 does the blinking. Never push a bare LED straight into these sockets. Without a resistor the LED draws far more than the 20 mA a pin should supply and can damage both the LED and the microcontroller. Put a 220–330 Ω resistor in series with either leg, or use an LED that has a resistor built in. The long leg (anode) goes toward pin 11.
Diagrams
The sketch
int potentiometerReading;
int onDurationMs;
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);
onDurationMs = map(potentiometerReading, 0, 1023, 200, 800);
Serial.println(potentiometerReading);
digitalWrite(11, HIGH);
delay(onDurationMs);
digitalWrite(11, LOW);
delay(1000 - onDurationMs);
}How the code works
map(potentiometerReading, 0, 1023, 200, 800) rescales the 0–1023 reading
linearly to 200–800 ms. Because the off time is 1000 - onDurationMs, the total is always
1000 ms. The pot is read once per cycle, so a change takes effect at the start of the next blink.
Review result: no changes were needed. We checked the pin setup, the mapping range, and that the on and off delays always add to one second.
What you should observe
- The LED blinks at a steady rate of one flash per second.
- Turning the knob toward the A0 end shortens the flash (down to 200 ms); toward the A4 end lengthens it (up to 800 ms).
- Open the Serial Monitor at 9600 baud: one number from 0 to 1023 appears per blink.