Bench NotesUno handbook

Five-Speed Symmetrical LED Blinking

A potentiometer picks one of five blink speeds; on and off times are always equal.

BeginnerLEDResistorPotentiometerSerial

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 pinConnects toNotes
A0Potentiometer outer legSketch sets A0 as an OUTPUT, LOW. This is the pot's 0 V end.
A2Potentiometer wiper (middle leg)Analog input. Reads 0–1023.
A4Potentiometer other outer legSketch sets A4 as an OUTPUT, HIGH. This is the pot's 5 V end.
11LED anode (long leg) through a 220–330 Ω resistorThe blinking output.
12LED cathode (short leg, flat side)Sketch sets pin 12 as an OUTPUT, LOW, so it acts as the LED's ground.
Wiring for Five-Speed Symmetrical LED BlinkingArduino Uno A0 (driven LOW) to 10 kΩ potentiometer outer leg 1; Arduino Uno A2 (input) to 10 kΩ potentiometer wiper (middle); Arduino Uno A4 (driven HIGH) to 10 kΩ potentiometer outer leg 2; Arduino Uno D11 to LED anode (+, long leg) through 330 Ω; Arduino Uno D12 (driven LOW) to LED cathode (−, short leg).Connections (each line is one wire)Arduino Uno10 kΩ potentiometerLEDA0 (driven LOW)outer leg 1A2 (input)wiper (middle)A4 (driven HIGH)outer leg 2D11anode (+, long leg)330 ΩD12 (driven LOW)cathode (−, short leg)
Original wiring diagram. Each line is one jumper wire; boxes on a line are series resistors.

How the pins are arranged

Read before wiring

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

Header placementA 10 kilohm potentiometer with its outer legs in A0 and A4 and its wiper in A2. The sketch drives A0 LOW and A4 HIGH so the pot gets 0 and 5 volts. An LED with a series resistor between pin 11 (anode) and pin 12 (cathode); pin 12 is held LOW so it acts as ground.Arduino Uno R3 — parts plugged straight into the headerGND13121110A0A1A2A3A410 kΩ potentiometerA0 = LOW (0 V), A2 = wiper, A4 = HIGH (5 V)LED with series resistor: anode to 11, cathode to 12
Same header placement as the variable-duty project.
Blink speed by bandBand 0 (slowest): on 1000 ms, then off 1000 ms; Band 2: on 600 ms, then off 600 ms, then on 600 ms, then off 200 ms; Band 4 (fastest): on 200 ms, then off 200 ms, then on 200 ms, then off 200 ms, then on 200 ms, then off 200 ms, then on 200 ms, then off 200 ms, then on 200 ms, then off 200 ms.Band 0 (slowest)ON 1000 msoff 1000 msBand 2ON 600 msoff 600 msON 600 msBand 4 (fastest)ON 200 msoff 200 msON 200 msoff 200 msON 200 msoff 200 msON 200 msoff 200 msON 200 msoff 200 ms0 ms2000 ms
Two seconds of output at three of the five settings.

The sketch

five_speed_symmetric_led_blink.ino
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.