Search models, users, collections, and posts

Led traffic light with animation

GIF

Print Profile(1)

All
A1
P1S
H2S
X1 Carbon
A1 mini
X1
P1P
H2D Pro
P2S
H2C
H2D
X1E
X2D
A2L

0.28mm layer, 3 walls, 15% infill
0.28mm layer, 3 walls, 15% infill
Designer
11.3 h
7 plates
5.0(2)

Open in Bambu Studio
Boost
15
47
3
1
16
8
Released 

Bill of Materials

Maker's Supply Kits and Parts
Select all
WS2812B RGB LED Strip Light (1pcs) - KA001 / RGB(97809)
M4x20 BHCS Machine Screw (5PCS) - AA068
M4 Carbon Steel Hex Nut (10PCS) - AB028
100W USB-C Smart Soldering Iron Kit
Bambu Filaments
Select all
Black (10101) / Refill / 1kg
Pumpkin Orange (10301) / Refill / 1kg
Bambu Green (10501) / Refill / 1kg
Red (10200) / Refill / 1kg
Jade White (10100) / Refill / 1kg
List other parts
  • ESP32 x 1:
  • 3pin wire x 1:

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 .

 

 

Comment & Rating (3)

(0/1000)

License

This user content is licensed under a Standard Digital File License.

You shall not share, sub-license, sell, rent, host, transfer, or distribute in any way the digital or 3D printed versions of this object, nor any other derivative work of this object in its digital or physical format (including - but not limited to - remixes of this object, and hosting on other digital platforms). The objects may not be used without permission in any way whatsoever in which you charge money, or collect fees.