Demo 1: LED Binary Counter (8-bit)

Circuit Diagram

Arduino Uno Pin 2 ---[220Ω]---LED1---|>|---GND (LSB - Bit 0) Pin 3 ---[220Ω]---LED2---|>|---GND (Bit 1) Pin 4 ---[220Ω]---LED3---|>|---GND (Bit 2) Pin 5 ---[220Ω]---LED4---|>|---GND (Bit 3) Pin 6 ---[220Ω]---LED5---|>|---GND (Bit 4) Pin 7 ---[220Ω]---LED6---|>|---GND (Bit 5) Pin 8 ---[220Ω]---LED7---|>|---GND (Bit 6) Pin 9 ---[220Ω]---LED8---|>|---GND (MSB - Bit 7) Note: ---|>|--- represents LED with anode (+) on left, cathode (-) on right

Theory & Physics

LED Operation: Light Emitting Diodes are semiconductor devices that emit light when current flows through them in the forward direction. They exhibit a threshold voltage (Vf) that must be exceeded for conduction.

Key Parameters:
  • Forward Voltage (Vf): Red LEDs typically 1.8-2.2V, Green/Yellow 2.0-2.4V, Blue/White 3.0-3.6V
  • Forward Current (If): Standard LEDs operate at 10-20mA, optimal at ~15mA
  • Maximum Current: Typically 30mA continuous, 50mA peak
Binary Counting: This demo displays numbers 0-255 in binary notation, demonstrating positional number systems where each LED represents a power of 2.

Calculations

Resistor Value Calculation (Ohm's Law):
R = (Vsupply - Vf) / If

For a red LED:
- Vsupply = 5V (Arduino output)
- Vf = 2.0V (LED forward voltage)
- If = 15mA = 0.015A (desired current)

R = (5V - 2.0V) / 0.015A = 3.0V / 0.015A = 200Ω

We use 220Ω (standard value):
Actual current: I = (5V - 2.0V) / 220Ω = 13.6mA ✓ (safe)

Power Dissipation:
P = I² × R = (0.0136)² × 220 = 0.041W (41mW)
A standard 1/4W (250mW) resistor is more than adequate.

Arduino Code

// LED Binary Counter const int LED_PINS[] = {2, 3, 4, 5, 6, 7, 8, 9}; const int NUM_LEDS = 8; void setup() { for(int i = 0; i < NUM_LEDS; i++) { pinMode(LED_PINS[i], OUTPUT); } Serial.begin(9600); } void loop() { for(int count = 0; count <= 255; count++) { displayBinary(count); Serial.print("Count: "); Serial.print(count); Serial.print(" Binary: "); Serial.println(count, BIN); delay(500); } } void displayBinary(int num) { for(int i = 0; i < NUM_LEDS; i++) { int bit = (num >> i) & 1; // Extract bit i digitalWrite(LED_PINS[i], bit); } }

Use Cases

Demo 2: LED VU Meter (Audio Level Indicator)

Circuit Diagram

Arduino Uno Pin 2 ---[220Ω]---LED1---|>|---GND (Level 1 - Lowest) Pin 3 ---[220Ω]---LED2---|>|---GND (Level 2) Pin 4 ---[220Ω]---LED3---|>|---GND (Level 3) Pin 5 ---[220Ω]---LED4---|>|---GND (Level 4) Pin 6 ---[220Ω]---LED5---|>|---GND (Level 5) Pin 7 ---[220Ω]---LED6---|>|---GND (Level 6) Pin 8 ---[220Ω]---LED7---|>|---GND (Level 7) Pin 9 ---[220Ω]---LED8---|>|---GND (Level 8) Pin 10 ---[220Ω]---LED9---|>|---GND (Level 9) Pin 11 ---[220Ω]---LED10--|>|---GND (Level 10 - Peak) Optional: Analog Input Simulation A0 <--- Potentiometer/Audio Signal (0-5V)

Theory & Physics

VU Meter Principle: Volume Unit meters display signal amplitude using a bar graph representation. Each LED represents a threshold level.

Persistence of Vision: Human eyes can perceive changes at ~15-20 Hz. Rapid LED updates create smooth animation effects.

Signal Quantization: Converting continuous analog signals into discrete levels is fundamental to digital signal processing (DSP).

Calculations

Level Thresholds (10-level meter):
For ADC range 0-1023:
- Level 1: >102 (10%)
- Level 2: >204 (20%)
- Level 3: >307 (30%)
- ...
- Level 10: >921 (90%)

Threshold(n) = (1023 × n) / 10

Voltage per level:
ΔV = 5V / 10 levels = 0.5V per LED

Arduino Code

// LED VU Meter const int LED_PINS[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; const int NUM_LEDS = 10; const int ANALOG_PIN = A0; void setup() { for(int i = 0; i < NUM_LEDS; i++) { pinMode(LED_PINS[i], OUTPUT); } Serial.begin(9600); } void loop() { // Simulated VU meter with sine wave static unsigned long lastTime = 0; unsigned long currentTime = millis(); // Generate test signal (0-1023) float angle = (currentTime / 1000.0) * 2 * PI; // 1 Hz cycle int level = (int)((sin(angle) + 1.0) * 511.5); // 0-1023 // Display on LEDs displayLevel(level); // Alternatively, use actual analog input: // int level = analogRead(ANALOG_PIN); // displayLevel(level); delay(50); // Update rate: 20 Hz } void displayLevel(int value) { int numLit = map(value, 0, 1023, 0, NUM_LEDS); for(int i = 0; i < NUM_LEDS; i++) { digitalWrite(LED_PINS[i], i < numLit ? HIGH : LOW); } Serial.print("Level: "); Serial.print(value); Serial.print(" LEDs: "); Serial.println(numLit); }

Use Cases

Additional Technical Information

LED Current Limiting - Critical Safety

⚠️ WARNING: Never connect an LED directly to a power source without a current-limiting resistor! LEDs have very low internal resistance and will draw excessive current, causing immediate destruction.
LED Color Typical Vf Resistor for 5V Current @ 220Ω
Red 1.8-2.2V 150-220Ω 12.7-14.5mA
Yellow/Green 2.0-2.4V 180-220Ω 11.8-13.6mA
Blue/White 3.0-3.6V 100-150Ω 9.3-13.3mA

LED Physics Deep Dive

Semiconductor Bandgap: LEDs emit light when electrons transition from the conduction band to the valence band. The photon energy (and thus color) equals the bandgap energy:

E = hf = hc/λ

Where:
- E = Energy (Joules)
- h = Planck's constant (6.626 × 10⁻³⁴ J·s)
- f = Frequency (Hz)
- c = Speed of light (3 × 10⁸ m/s)
- λ = Wavelength (meters)

Example for Red LED (λ = 650nm):
E = (6.626 × 10⁻³⁴ × 3 × 10⁸) / (650 × 10⁻⁹)
E = 3.06 × 10⁻¹⁹ J = 1.91 eV

This matches the ~2V forward voltage drop!

PWM Dimming (Bonus)

LEDs can be dimmed using Pulse Width Modulation (PWM). Instead of reducing current (which can shift color), PWM rapidly switches the LED on/off. The duty cycle determines apparent brightness.

Duty Cycle: Percentage of time signal is HIGH
- 0% = OFF
- 50% = Half brightness
- 100% = Full brightness

Arduino's analogWrite(pin, value) uses 8-bit PWM (0-255) at ~490 Hz.