Guides · 14 min read

Arduino LED Projects: 25 Ideas from Traffic Light to LED Cube

Arduino LED projects from easy to advanced: 25 ideas with a board, LED, resistor and time table, plus tested code for a traffic light, Knight Rider and WS2812B.

Arduino LED projects are the fastest and most fun way into electronics: with one LED, one resistor and a few lines of code your first circuit is running in five minutes. LEDs aren't just for day one, either. With the same logic you can build a traffic light, a Knight Rider scanner, an electronic die, lights that dance to music, colourful WS2812B animations and a 27-LED cube. Every new project teaches you one more programming idea: digital output, arrays, loops, PWM, timing with millis(), reading buttons and making decisions from sensors.

In this guide we've collected 25 LED projects, sorted from easy to hard, in a single table. For each one you'll see which board it works on (Arduino Uno, ESP32 or Raspberry Pi Pico), which LED and how many ohms of resistance to use, and roughly how long it takes. Then we walk through compiled, tested code for six of them: a traffic light, a breathing LED, four effects on one button, a WS2812B rainbow, a PWM wave on the ESP32 and a Knight Rider with a fading tail on the Pico.

Red, yellow, blue, green and white 5 mm LEDs
Most of these projects use 5 mm LEDs: the long leg (anode) goes to the resistor and the pin, the short leg (cathode) goes to GND.

Before you start: parts and the right resistor

Almost all 25 projects use parts from the same box. An Arduino Uno starter kit covers most of them, and you can pick up the rest (WS2812B ring, 74HC595, MAX7219 module) as you go. The one rule that really matters is a series resistor for every single-colour LED. You find its value with a simple formula: R = (Vsupply − VLED) / I. On a 5 V Arduino Uno pin, a red LED (about 2.0 V) at 15 mA gives (5 − 2) / 0.015 = 200 Ω; the nearest standard value, 220 Ω, gives about 13.6 mA and keeps both the LED and the pin comfortable. If you'd rather not do the maths by hand, use the LED resistor calculator, and for the details read how to calculate an LED resistor.

PartQtyUsed in projects
Arduino Uno (or Nano)1All of them; most also work on ESP32 and Pico
5 mm LEDs (red, yellow, green, blue, white)10–151–18
220 Ω resistors (330 Ω for the Pico)10–15One per single-colour LED
Push buttons2–35, 7, 14, 15 and the effects sketch
10 kΩ potentiometer19 and 13
LDR and 10 kΩ resistor110
Common-cathode RGB LED116
IR receiver (VS1838B) and remote117
74HC595 shift register and 8 × 470 Ω118
WS2812B ring (24 LEDs) or strip119–21
MAX7219 8x8 matrix module1–422
Breadboard and jumper wires1 setAll of them
Never connect an LED to a pin without a resistor. On an Arduino Uno the recommended current per pin is 20 mA (40 mA absolute maximum), and the total across all pins should stay under 200 mA. ESP32 pins are also happy at around 20 mA. The Raspberry Pi Pico's pins are set to a 4 mA drive strength by default; draw more and the output voltage sags, which is why the Pico uses 330 Ω. Each WS2812B LED can draw 60 mA at full white, so power more than about 10 of them from a separate 5 V supply, not from the board's 5V pin.

25 Arduino LED projects: board, LED, resistor and time table

The times in the table are roughly how long it takes to build the circuit, write the code and test it with the parts already on your desk; if it's your first time, multiply by one and a half. The resistor column is for a 5 V Arduino Uno. On an ESP32, red, yellow and green LEDs run a little dimmer with the same resistor; on the Pico, switch to 330 Ω. Every board listed in the board column can do the project directly; only the pin numbers change.

No.ProjectBoardLEDResistor (5 V)Time
1Blink with an external LEDUno, ESP32, Pico5 mm red220 Ω10 min
2Two-LED flip-flopUno, ESP32, Pico2 × 5 mm2 × 220 Ω15 min
3SOS in Morse codeUno, ESP32, Pico5 mm white220 Ω20 min
4Traffic lightUno, ESP32, PicoRed, yellow, green3 × 220 Ω30 min
5Pedestrian crossing with buttonUno, ESP32, Pico5 × 5 mm5 × 220 Ω + button45 min
6Police lightsUno, ESP32, PicoRed + blue2 × 220 Ω20 min
7Toggle an LED with a buttonUno, ESP32, Pico5 mm220 Ω + button30 min
8Breathing LED (PWM)Uno, ESP32, Pico5 mm220 Ω20 min
9Potentiometer dimmerUno, ESP32, Pico5 mm white220 Ω + 10 kΩ pot20 min
10LDR night lightUno, ESP32, Pico5 mm white220 Ω + LDR + 10 kΩ30 min
11LED chaserUno, ESP32, Pico8 × 5 mm8 × 220 Ω30 min
12Knight Rider scannerUno, ESP32, Pico8 × 5 mm red8 × 220 Ω40 min
13LED bar graphUno, ESP328–10 LEDs or an LED bar220 Ω (per LED)45 min
14Electronic dieUno, ESP327 × 5 mm7 × 220 Ω + button1 h
15Reaction time gameUno, ESP32, Pico2 × 5 mm2 × 220 Ω + 2 buttons1 h
16RGB LED colour mixingUno, ESP32, PicoCommon-cathode RGB3 × 220 Ω30 min
17LEDs controlled by a remoteUno, ESP323 × 5 mm3 × 220 Ω + IR receiver45 min
188 LEDs from 3 pins with a 74HC595Uno, ESP32, Pico8 × 5 mm8 × 470 Ω1 h
19WS2812B rainbow ringUno, ESP32, Pico24-LED WS2812B ring330 Ω data + 1000 µF30 min
20WS2812B cometUno, ESP32, PicoWS2812B strip330 Ω data + 1000 µF45 min
21Sound-reactive VU meterUno, ESP32WS2812B strip330 Ω + sound sensor2 h
22Scrolling text on an 8x8 matrixUno, ESP32MAX7219 matrixBuilt into the module1.5 h
23LEDs controlled from your phone (Wi-Fi)ESP323 × 5 mm3 × 150–220 Ω1 h
2412 V RGB LED stripUno, ESP3212 V 5050 strip3 MOSFETs + 220 Ω and 10 kΩ1.5 h
253x3x3 LED cubeUno27 × 5 mm9 × 220 Ω + 3 transistors4–6 h

Level 1: from a single LED to a traffic light (projects 1–8)

The first eight projects teach digital outputs and timing. You can do them back to back on one breadboard without rebuilding the circuit: put the LED cathodes (short legs) on the breadboard's negative rail and wire their resistors to the pins starting at D2. Leave D0 and D1 unconnected; those two pins are used when you upload code over USB, and an LED on them can break the upload.

  • 1. Blink with an external LED: Blink an LED on the breadboard once a second instead of the one on the board. It's the project where you meet digitalWrite() and delay(); legs and polarity are covered in what is an LED.
  • 2. Two-LED flip-flop: Two LEDs take turns; while one is on, the other is off. Drop the delay to 10 ms and your eye thinks both are lit at once. That's the first step towards multiplexing, the trick used in LED cubes and matrices.
  • 3. SOS in Morse code: Send three short, three long and three short flashes using short (200 ms) and long (600 ms) blinks. It teaches you to move repeated code into a function and pass it parameters.
  • 4. Traffic light: Light the red, yellow and green LEDs in the order of a real junction. Start with the code below; pedestrian and junction versions are in the Arduino traffic light guide.
  • 5. Pedestrian crossing with a button: Use three LEDs for cars and two for pedestrians. When someone presses the button, the car light goes through yellow to red and the green walking light comes on. For button wiring, see how to connect a button to Arduino.
  • 6. Police lights: The red and blue LEDs flash quickly three times each, then swap sides. Short 50 ms delays and two nested for loops give a convincing emergency-light effect.
  • 7. Toggle an LED with a button: Each press flips the LED's state. Here you learn to catch the moment the button is pressed and to filter out contact bounce (debouncing); you'll reuse both ideas in every project with a button.
  • 8. Breathing LED: analogWrite() slowly raises and lowers the brightness, like the sleep light on a laptop. It only works on the PWM pins marked ~ (3, 5, 6, 9, 10, 11 on the Uno); the idea is explained in what is PWM.

Traffic light code (project 4)

Connect the red LED to D2, yellow to D3 and green to D4, each through a 220 Ω resistor. The sketch uses a small function that sets all three LEDs and then waits, so every phase of the light is a single line and changing the timings is easy.

C++ (Arduino IDE)
1// Proje 4: Trafik lambası / Traffic light
2const int RED = 2;      // kırmızı LED, 220 Ω ile / red LED via 220 Ω
3const int YELLOW = 3;   // sarı LED / yellow LED
4const int GREEN = 4;    // yeşil LED / green LED
5
6void setup() {
7  pinMode(RED, OUTPUT);
8  pinMode(YELLOW, OUTPUT);
9  pinMode(GREEN, OUTPUT);
10}
11
12// Üç LED'i ayarla ve bekle / set all three LEDs and wait
13void light(int r, int y, int g, unsigned long ms) {
14  digitalWrite(RED, r);
15  digitalWrite(YELLOW, y);
16  digitalWrite(GREEN, g);
17  delay(ms);
18}
19
20void loop() {
21  light(HIGH, LOW, LOW, 5000);    // kırmızı 5 s / red 5 s
22  light(LOW, LOW, HIGH, 4000);    // yeşil 4 s / green 4 s
23  for (int i = 0; i < 3; i++) {   // yeşil 3 kez yanıp söner / green flashes 3 times
24    light(LOW, LOW, LOW, 300);
25    light(LOW, LOW, HIGH, 300);
26  }
27  light(LOW, HIGH, LOW, 2000);    // sarı 2 s / yellow 2 s
28}

The green light flashes three times before it goes out, as it does in Austria and several other countries; if you don't want that, just delete the for loop. Red lasts much longer at a real junction, but for a model, short timings keep onlookers interested. The only weakness of this code is delay(): while the board is waiting it can't look at a button. When you add a pedestrian button, switch to timing with millis().

Breathing LED and dimmer code (projects 8 and 9)

This sketch combines two projects: the LED on D9 breathes slowly, and the potentiometer on A0 sets the peak brightness of each breath. Connect the pot's outer legs to 5V and GND and its middle leg (wiper) to A0. The brightness isn't taken straight from the counter but from the counter squared, because your eye doesn't see brightness linearly and notices small changes at low levels far more. Thanks to the squared curve, the breath opens slowly, then faster, and looks much more natural.

C++ (Arduino IDE)
1// Projeler 8-9: Nefes alan LED + potansiyometreyle tepe parlaklık
2// Projects 8-9: breathing LED + pot sets the peak brightness
3const int LED_PIN = 9;     // PWM pini (~) / PWM pin (~)
4const int POT_PIN = A0;    // potansiyometre orta bacak / pot wiper
5
6void setup() {
7  pinMode(LED_PIN, OUTPUT);
8}
9
10// Karesel eğri: göz düşük parlaklıkta daha hassastır / squared curve: the eye is more sensitive at low levels
11void setLevel(int i, int peak) {
12  analogWrite(LED_PIN, (long)i * i / 255 * peak / 255);
13}
14
15void loop() {
16  int peak = map(analogRead(POT_PIN), 0, 1023, 10, 255);   // tepe parlaklık / peak brightness
17  for (int i = 0; i <= 255; i++) {                          // yavaşça aç / fade in
18    setLevel(i, peak);
19    delay(6);
20  }
21  for (int i = 255; i >= 0; i--) {                          // yavaşça kapat / fade out
22    setLevel(i, peak);
23    delay(6);
24  }
25  delay(400);                                               // nefes arası / pause between breaths
26}

Level 2: sensors and multi-LED projects (projects 9–17)

  • 9. Potentiometer dimmer: Read 0–1023 with analogRead(), scale it to 0–255 with map() and use it as the LED brightness. What is a potentiometer covers the wiring and the reading code in detail.
  • 10. LDR night light: The LED switches on by itself when the room gets dark. The LDR and a 10 kΩ resistor form a voltage divider; leaving a gap of a few counts between the on and off thresholds (hysteresis) stops flicker at dusk. Details in the LDR light sensor guide.
  • 11. LED chaser: A single light runs from left to right across eight LEDs. It teaches you to put pin numbers in an array and walk through it with a for loop; the same code works unchanged with 4 or 12 LEDs.
  • 12. Knight Rider scanner: The light bounces back and forth between the two ends, just like the front of KITT, the talking car from Knight Rider. For a speed pot and a fading tail, see the Knight Rider and LED chaser guide.
  • 13. LED bar graph: A bar of 8 or 10 LEDs fills up according to a potentiometer or sensor reading. It's the basis of battery, volume and water-level indicators; a single map() line turns the reading into the number of LEDs to light.
  • 14. Electronic die: Press the button and seven LEDs show the pips of a die face, with random() picking a number from 1 to 6. Because opposite pips always light together, you can drive all 7 LEDs from only 4 pins: the centre pip, two diagonal pairs and the middle-row pair.
  • 15. Reaction time game: The LED lights up at a random moment, and the faster the player hits the button, the better. The time measured with millis() is printed to the Serial Monitor; add a second button and it becomes a two-player race. Most people react in 200–300 ms.
  • 16. RGB LED colour mixing: Mix the red, green and blue chips inside one LED with PWM to get hundreds of colours. For the difference between common anode and common cathode, read how to use an RGB LED.
  • 17. LEDs controlled by a remote: Switch LEDs on and off and change their brightness with the buttons of a TV remote. With the IRremote library you read each button's code and use it in a switch-case; the steps are in IR receiver and remote.

Four effects on one button: chaser, scanner, filling bar and twinkle

This sketch combines projects 11, 12 and 13 in one circuit and moves to the next effect every time you press the button. Connect eight LEDs to D2–D9 through 220 Ω resistors, one leg of the button to D12 and the other to GND. Because it uses the internal pull-up resistor (INPUT_PULLUP), no external resistor is needed: the pin reads HIGH when the button is released and LOW while it's pressed.

C++ (Arduino IDE)
1// Projeler 11-13: Tek butonla 4 LED efekti / 4 LED effects with one button
2const int LEDS[] = {2, 3, 4, 5, 6, 7, 8, 9};   // soldan sağa LED pinleri / LED pins, left to right
3const int N = sizeof(LEDS) / sizeof(LEDS[0]);
4const int BUTTON = 12;                         // buton GND'ye / button to GND (INPUT_PULLUP)
5const unsigned long STEP_MS = 80;              // efekt hızı / effect speed
6
7int effect = 0;               // 0 yürüyen, 1 karaşimşek, 2 dolan bar, 3 yıldız / 0 chase, 1 scanner, 2 bar, 3 twinkle
8unsigned long counter = 0;    // efekt adımı / effect step
9unsigned long lastStep = 0;
10unsigned long lastPress = 0;
11bool lastButton = HIGH;
12
13// Yalnız bir LED'i yak / light only one LED
14void showOnly(int idx) {
15  for (int i = 0; i < N; i++) digitalWrite(LEDS[i], i == idx ? HIGH : LOW);
16}
17
18void setup() {
19  for (int i = 0; i < N; i++) pinMode(LEDS[i], OUTPUT);
20  pinMode(BUTTON, INPUT_PULLUP);
21  randomSeed(analogRead(A5));                  // boş analog pinden tohum / seed from a floating analog pin
22}
23
24void loop() {
25  bool now = digitalRead(BUTTON);
26  if (now == LOW && lastButton == HIGH && millis() - lastPress > 200) {   // basma anı + debounce / press edge + debounce
27    effect = (effect + 1) % 4;
28    counter = 0;
29    lastPress = millis();
30  }
31  lastButton = now;
32
33  if (millis() - lastStep < STEP_MS) return;   // zamanı gelmediyse çık / not time yet
34  lastStep = millis();
35
36  switch (effect) {
37    case 0:                                    // yürüyen LED / chaser
38      showOnly(counter % N);
39      break;
40    case 1: {                                  // karaşimşek 0..7..1 / scanner 0..7..1
41      int pos = counter % (2 * N - 2);
42      showOnly(pos < N ? pos : 2 * N - 2 - pos);
43      break;
44    }
45    case 2: {                                  // dolan ve boşalan bar / filling and emptying bar
46      int lvl = counter % (2 * N);
47      int lit = lvl <= N ? lvl : 2 * N - lvl;
48      for (int i = 0; i < N; i++) digitalWrite(LEDS[i], i < lit ? HIGH : LOW);
49      break;
50    }
51    case 3:                                    // rastgele yıldız / random twinkle
52      digitalWrite(LEDS[random(N)], random(2));
53      break;
54  }
55  counter++;
56}

The key idea of this code is that it never uses delay(). On every pass, loop() reads the button first, then uses millis() to check whether 80 ms have passed since the last step; if not, it returns straight away. That way a button press is never missed, whatever step the effect is on. The 200 ms window filters out contact bounce. One round of the scanner is 2 × 8 − 2 = 14 steps; the return path skips the last and first LED so the end LEDs don't stay on twice as long. To change the speed, play with STEP_MS or read it from a potentiometer.

Level 3: addressable LEDs, matrices, strips and an LED cube (projects 18–25)

  • 18. 8 LEDs from 3 pins with a 74HC595: A shift register creates eight outputs from just three Arduino pins, and you can chain two chips for 16 LEDs. Because the chip's total current limit is low, each LED gets 470 Ω. Wiring and code are in the 74HC595 shift register guide.
  • 19. WS2812B rainbow ring: Colours rotate continuously around a 24-LED ring. Each LED has its own driver chip inside, so one data pin is enough; everything else is in the WS2812B NeoPixel guide.
  • 20. WS2812B comet: A bright head races along the strip with a tail that fades out behind it. Dimming every LED by a quarter at each step creates the tail all by itself.
  • 21. Sound-reactive VU meter: The loudness picked up by a sound sensor becomes a bar that fills from green to red on the strip. The complete build is in music-reactive LEDs.
  • 22. Scrolling text on an 8x8 matrix: Line up four MAX7219 modules and scroll your name or the time with the MD_Parola library. The driver limits the current itself, so the LEDs don't need resistors; see MAX7219 LED matrix.
  • 23. LEDs controlled from your phone: The ESP32 joins your home network and serves a web page, and you switch LEDs with buttons on your phone. If you want to drive WS2812B LEDs without writing any code, see how to install WLED.
  • 24. 12 V RGB LED strip: Drive a 12 V 5050 strip under kitchen cabinets or behind a desk with three MOSFETs; the Arduino only controls the gates, the power supply provides the current. Details in RGB LED strip control.
  • 25. 3x3x3 LED cube: With 27 LEDs, 9 columns and 3 layers, the cube teaches multiplexing and soldering at the same time. Light the layers one after another fast enough and your eye sees the whole cube lit at once; the build steps are in the LED cube guide.

WS2812B rainbow and comet code (projects 19 and 20)

WS2812B NeoPixel 24-LED RGB ring
A 24-LED WS2812B ring: every LED has a driver chip inside, and all 24 are controlled from a single data pin.

Connect the ring's DIN to D6 through a 330 Ω resistor, 5V to 5 V and GND to GND; if you use a separate power supply, its GND and the Arduino's GND must be joined. Install the Adafruit NeoPixel library from the Library Manager. The sketch shows a rainbow for 10 seconds and a blue comet for 10 seconds; you can change the colours and durations inside loop().

C++ (Arduino IDE)
1// Projeler 19-20: WS2812B gökkuşağı ve kuyruklu yıldız / WS2812B rainbow and comet
2#include <Adafruit_NeoPixel.h>
3
4const int DATA_PIN = 6;      // DIN, 330 Ω üzerinden / DIN via 330 Ω
5const int NUM_LEDS = 24;     // 24'lü halka / 24-LED ring
6Adafruit_NeoPixel ring(NUM_LEDS, DATA_PIN, NEO_GRB + NEO_KHZ800);
7
8void setup() {
9  ring.begin();
10  ring.setBrightness(60);    // 0-255, akımı sınırlar / limits the current
11  ring.show();               // hepsini söndür / all off
12}
13
14// Halka boyunca dönen gökkuşağı / rainbow rotating around the ring
15void rainbowFor(unsigned long ms) {
16  unsigned long start = millis();
17  uint16_t hue = 0;
18  while (millis() - start < ms) {
19    for (int i = 0; i < NUM_LEDS; i++) {
20      uint16_t h = hue + (uint32_t)i * 65536 / NUM_LEDS;
21      ring.setPixelColor(i, ring.gamma32(ring.ColorHSV(h)));
22    }
23    ring.show();
24    hue += 256;
25    delay(20);
26  }
27}
28
29// Parlak baş, sönen kuyruk / bright head, fading tail
30void cometFor(uint32_t color, unsigned long ms) {
31  unsigned long start = millis();
32  int head = 0;
33  while (millis() - start < ms) {
34    for (int i = 0; i < NUM_LEDS; i++) {       // her adımda %25 söndür / dim every LED by 25%
35      uint32_t c = ring.getPixelColor(i);
36      uint8_t r = (c >> 16) & 0xFF, g = (c >> 8) & 0xFF, b = c & 0xFF;
37      ring.setPixelColor(i, r * 3 / 4, g * 3 / 4, b * 3 / 4);
38    }
39    ring.setPixelColor(head, color);           // baş tam renkte / head at full colour
40    ring.show();
41    head = (head + 1) % NUM_LEDS;
42    delay(40);
43  }
44}
45
46void loop() {
47  rainbowFor(10000);                           // 10 s gökkuşağı / 10 s rainbow
48  cometFor(ring.Color(0, 120, 255), 10000);    // 10 s mavi kuyruklu yıldız / 10 s blue comet
49}
24 LEDs at full white draw 24 × 60 mA = 1.44 A, almost three times the 500 mA a computer's USB port supplies. setBrightness(60) in the code cuts the brightness to about a quarter and keeps the current safe. For longer strips, use a separate 5 V supply, add a 1000 µF capacitor across the strip's power leads and don't skip the 330 Ω resistor on the data line.

LED projects with the ESP32: PWM on every pin

Most projects in the table also run on an ESP32, but watch out for three differences. First, the ESP32 runs at 3.3 V: with 220 Ω a red LED gets about 6 mA, while blue and white LEDs, whose forward voltage (about 3.1 V) is very close to 3.3 V, stay dim; use 47–68 Ω for those. Second, GPIO 6–11 are wired to the board's flash memory and 34–39 are input-only, so connect LEDs to pins like 18, 19, 21, 22, 23, 25, 26 and 27. Third, PWM comes from the LEDC unit and almost every pin can output it. The code below sends a flowing wave of light across three LEDs on GPIO 18, 19 and 21 and compiles on both the 2.x and 3.x versions of the ESP32 core. If the board is new to you, start with what is an ESP32.

C++ (Arduino IDE)
1// ESP32: 3 LED'de PWM ışık dalgası (çekirdek 2.x ve 3.x) / PWM light wave on 3 LEDs (core 2.x and 3.x)
2const int PINS[] = {18, 19, 21};   // LED'ler 150-220 Ω ile / LEDs via 150-220 Ω
3const int FREQ = 5000;             // PWM frekansı (Hz) / PWM frequency (Hz)
4const int RES = 8;                 // 8 bit: 0-255
5
6void pwmWrite(int idx, int duty) {
7#if ESP_ARDUINO_VERSION_MAJOR >= 3
8  ledcWrite(PINS[idx], duty);      // 3.x: pin numarasıyla / by pin number
9#else
10  ledcWrite(idx, duty);            // 2.x: kanal numarasıyla / by channel number
11#endif
12}
13
14void setup() {
15  for (int i = 0; i < 3; i++) {
16#if ESP_ARDUINO_VERSION_MAJOR >= 3
17    ledcAttach(PINS[i], FREQ, RES);
18#else
19    ledcSetup(i, FREQ, RES);       // kanal i / channel i
20    ledcAttachPin(PINS[i], i);
21#endif
22  }
23}
24
25void loop() {
26  float t = millis() / 1000.0;
27  for (int i = 0; i < 3; i++) {
28    float s = (sin(t * 2.0 - i * 2.1) + 1.0) / 2.0;   // her LED 120° geride / each LED 120° behind
29    pwmWrite(i, (int)(s * s * 255));                  // karesel eğri / squared curve
30  }
31  delay(10);
32}

LED projects with the Raspberry Pi Pico and MicroPython

On the Pico all pins are 3.3 V too, and every GP pin can output PWM. The on-board LED is on GP25 on the Pico; on the Pico W it's driven through the Wi-Fi chip, so you use it as Pin("LED"). In MicroPython you set brightness from 0 to 65535 with duty_u16(). The code below runs a Knight Rider with a fading tail on six LEDs connected to GP9–GP14 through 330 Ω: at each step the head LED lights at full brightness and the others drop to a little under half of their previous level. Save it to the Pico as main.py with Thonny and it runs by itself at every power-up; for the first setup, see what is the Raspberry Pi Pico.

MicroPython
1# Pico: 6 LED'de kuyruklu karaşimşek (GP9-GP14) / Knight Rider with a fading tail on 6 LEDs
2from machine import Pin, PWM
3import time
4
5PINS = [9, 10, 11, 12, 13, 14]            # LED'ler 330 Ω ile / LEDs via 330 Ω
6leds = []
7for p in PINS:
8    pwm = PWM(Pin(p))
9    pwm.freq(1000)                         # 1 kHz, titreme görünmez / no visible flicker
10    leds.append(pwm)
11
12level = [0] * len(leds)                    # her LED'in parlaklığı / brightness of each LED
13order = list(range(len(leds))) + list(range(len(leds) - 2, 0, -1))   # 0..5..1
14
15while True:
16    for head in order:
17        level[head] = 65535                # baş tam parlak / head at full brightness
18        for i, pwm in enumerate(leds):
19            pwm.duty_u16(level[i])
20            level[i] = level[i] * 45 // 100   # kuyruk her adımda söner / the tail fades each step
21        time.sleep_ms(70)

Common mistakes and how to fix them

SymptomCauseFix
The LED doesn't light at allThe LED is backwards, or both legs are in the same breadboard rowLong leg to the resistor, short leg to GND; put the legs in different rows
The LED is very dimpinMode(OUTPUT) is missing, or the resistor is far too big (e.g. 10 kΩ)Add pinMode in setup(); 220 Ω is red-red-brown
analogWrite() doesn't change the brightnessThe LED is on a non-PWM pinUse pin 3, 5, 6, 9, 10 or 11 on the Uno
The code won't uploadAn LED or button is on D0/D1Leave those two pins unused and start the circuit at D2
One press is detected several timesMechanical contact bounceDetect the press edge and add a 50–200 ms debounce window
WS2812B shows random colours or stays darkNo common GND, the strip is wired from the DOUT end, or the pin in the code is wrongJoin the grounds, connect at the DIN end where the arrows start, check DATA_PIN
The board keeps resettingToo many LEDs are powered from the board's 5V pinLower the brightness or use a separate 5 V supply
If you're missing parts or want to try a circuit before building it, you can simulate most of these projects in the browser: Wokwi and Tinkercad support LEDs, buttons, potentiometers and WS2812B parts. Running the code there first makes it much easier to tell a backwards LED from a bug in the sketch once you build the real thing.

Which project should you start with?

If you've never used an Arduino, do projects 1, 4, 7 and 8 in that order; by the end of a weekend you'll know digital output, button reading and PWM. If you have some experience, use 11, 14 and 15 to practise arrays, random numbers and millis(). Looking for a school project or a gift? Projects 19, 21 and 25 get the biggest reactions, and an LED cube always draws a crowd at a science fair. For more inspiration, browse our Arduino project ideas.

Many of the projects on this list are ready to build in the BlueGrays app: you can put together the traffic light, police lights, Knight Rider, LDR night light, RGB colour fade and WS2812B animations step by step, with circuit diagrams, parts lists and commented code.

Frequently asked questions

What resistor should I use for Arduino LED projects?

For single-colour 5 mm LEDs on a 5 V Arduino Uno, 220 Ω is the most common and safest choice; it lets about 13 mA through a red LED. On an ESP32 use 150–220 Ω for red, yellow and green LEDs, and 330 Ω on a Raspberry Pi Pico. For an exact value, use R = (V − Vf) / I.

How many LEDs can I connect to an Arduino?

In theory the Uno's 20 pins (D0–D13 and A0–A5) can drive 20 LEDs, but the total current must stay under 200 mA and D0/D1 should stay unused; with 220 Ω, lighting 12–14 LEDs at once stays within safe limits. For more, use a 74HC595 shift register, a MAX7219 driver or a WS2812B strip that runs hundreds of LEDs from one pin.

What happens if I connect an LED without a resistor?

Nothing limits the current, so the LED and the pin draw far too much. The LED shines very brightly at first, then dims or dies completely, and the Arduino pin can be permanently damaged by exceeding its 40 mA absolute maximum. A circuit that seems to work for a few minutes is not a safe circuit.

Can WS2812B LEDs be powered from the Arduino's 5V pin?

For a few LEDs at low brightness, yes; on a USB-powered Uno the total current should stay under 500 mA. Each LED can draw 60 mA at full white, so beyond 8–10 LEDs use a separate 5 V supply, join the grounds and limit the brightness with setBrightness().

What is the easiest Arduino LED project for beginners?

Blink with an external LED and the traffic light are the easiest; with one LED, a resistor and a few wires they take 10–30 minutes. After that, the button toggle and the breathing LED teach button reading and PWM, which you'll use in almost every later project.

Why doesn't analogWrite work on every pin?

On the Arduino Uno, hardware PWM only exists on the pins marked ~: 3, 5, 6, 9, 10 and 11. On other pins analogWrite() turns the LED off for values below 128 and fully on above that, with nothing in between. On the ESP32 and Raspberry Pi Pico, almost every GPIO pin can output PWM.

See all projects