March 16, 2026
Description
Have you always wanted a traffic light at your home ? Well now you can make one!
DIY WS2812B Traffic Light with ESP32 (24 LEDs per color)
This tutorial shows how to build a realistic traffic light using an ESP32, WS2812B LEDs, and the FastLED library.
Materials Needed :
Soldering iron and supplies
M3/M4 20mm long screws 4x-8x and nuts (used to attach panels together)
4mm drill bit if M4 screws don't fit
Screws or double sided adhesive tape for mounting to the wall
Super glue / Hot glue for keeping wires/diffuser/lid in place
ESP32 development board
WS2812B LED strip: 72 LEDs total (24 green, 24 amber, 24 red)
Power supply: 5V, ≥2A recommended or you can use esp32 5v output for limited brightness
3pin wire
Round , black 3pin wire for nicer look (6mm round)
Diffuser colors for traffic light colors (orange/red/green) or use white pla and adjust color hue
USB/C cable to plug in esp32
esp32 case of your choice (search on makerworld)
Step 1: Install Arduino IDE and Libraries
Download Arduino IDE: arduino.cc/software
Add ESP32 board support:
Preferences → Additional Board URLs:
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
Tools → Board → Board Manager → search ESP32, install
Install FastLED library:
Sketch → Include Library → Manage Libraries → search FastLED, install
Step 2: Wiring the LEDs
ESP32 Pin LED Strip
D4 Data input wire (green)
GND LED GND (white)
5V LED 5V (red)
Important:
72 LEDs × 60 mA max per LED → up to ~4.3A at full white → DO NOT power all from ESP32 5V at full white power
in the code provided brightness is limited to 120 , which is safe for this project . Use external 5V 2–3A supply if you want it brighter and edit code .
Step 3: Code
Use the following FastLED code for 24 LEDs per color, active brightness 120, standby PWR ~4%:
#include <FastLED.h>
#define LED_PIN 4
#define NUM_LEDS 72
#define BRIGHTNESS 120
CRGB leds[NUM_LEDS];
// LED sections
#define GREEN_START 0
#define GREEN_COUNT 24
#define ORANGE_START 24
#define ORANGE_COUNT 24
#define RED_START 48
#define RED_COUNT 24
enum State { GREEN, GREEN_BLINK, ORANGE, RED, RED_ORANGE };
State currentState = GREEN;
unsigned long previousMillis = 0;
int blinkCount = 0;
bool blinkState = false;
void setup() {
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
FastLED.setMaxPowerInVoltsAndMilliamps(5, 2000); // Limit to 2A
startupAnimation();
}
void loop() {
unsigned long currentMillis = millis();
switch(currentState) {
case GREEN:
setBaseColors();
setBright(GREEN_START, GREEN_COUNT, CRGB::Green);
if (currentMillis - previousMillis >= 10000) { previousMillis = currentMillis; blinkCount = 0; currentState = GREEN_BLINK; }
break;
case GREEN_BLINK:
if (currentMillis - previousMillis >= 500) {
previousMillis = currentMillis;
blinkState = !blinkState;
setBaseColors();
if (blinkState) setBright(GREEN_START, GREEN_COUNT, CRGB::Green);
FastLED.show();
blinkCount++;
if (blinkCount >= 8) { currentState = ORANGE; previousMillis = currentMillis; }
}
break;
case ORANGE:
setBaseColors();
setBright(ORANGE_START, ORANGE_COUNT, CRGB(255,255,0)); // Amber
if (currentMillis - previousMillis >= 3500) { previousMillis = currentMillis; currentState = RED; }
break;
case RED:
setBaseColors();
setBright(RED_START, RED_COUNT, CRGB::Red);
if (currentMillis - previousMillis >= 10000) { previousMillis = currentMillis; currentState = RED_ORANGE; }
break;
case RED_ORANGE:
setBaseColors();
setBright(RED_START, RED_COUNT, CRGB::Red);
setBright(ORANGE_START, ORANGE_COUNT, CRGB(255,255,0));
if (currentMillis - previousMillis >= 2000) { previousMillis = currentMillis; currentState = GREEN; }
break;
}
}
void setBaseColors() {
// Standby ~4% brightness
for (int i = GREEN_START; i < GREEN_START + GREEN_COUNT; i++) leds[i] = CRGB(0,10,0);
for (int i = ORANGE_START; i < ORANGE_START + ORANGE_COUNT; i++) leds[i] = CRGB(10,10,0);
for (int i = RED_START; i < RED_START + RED_COUNT; i++) leds[i] = CRGB(10,0,0);
}
void setBright(int start, int count, CRGB color) {
for (int i = start; i < start + count; i++) leds[i] = color;
FastLED.show();
}
void startupAnimation() {
setBaseColors(); FastLED.show(); delay(400);
setBright(RED_START, RED_COUNT, CRGB::Red); delay(600);
setBaseColors(); setBright(ORANGE_START, ORANGE_COUNT, CRGB(255,255,0)); delay(600);
setBaseColors(); setBright(GREEN_START, GREEN_COUNT, CRGB::Green); delay(600);
setBaseColors(); FastLED.show();
}
Step 4: Test Your Traffic Light
Upload code to ESP32
LEDs perform startup animation: red → amber → green
Cycles: green → green blink → amber → red → red+amber → green
Standby LEDs glow faintly (~4%) for realism
Tips & Notes
For longer strips or full brightness white, ALWAYS use external 5V supply
Adjust BRIGHTNESS for active LED intensity
Adjust setBaseColors() values for background glow
For any adjustments please ask your favourite ai , paste this code in and tell it what you want to change .
License:
Standard Digital File License