Traffic Light

by agolyakoff in Circuits > LEDs

42 Views, 0 Favorites, 0 Comments

Traffic Light

traffic-light-result.jpg
Светофор-ночник, панорамный вид.

A miniature, fully working traffic-light model for your desk or bedroom. It runs a real 7-phase red→yellow→green cycle on two opposing directions, has a "caution" flashing-yellow standby mode, runs off a rechargeable 18650 cell charged over USB-C, and can double as a night light. Everything — enclosure, PCBs, and firmware — is open: 3D-printable case, two small PCBs you can have fabbed by any board house or make yourself, and ~1KB of AVR C++ running on an ATtiny13A. Every other part is off-the-shelf, available from the usual marketplaces.

Source files — 3 separate repositories

Everything referenced in this build lives across three independent GitHub repos (not one mono-repo) — every link in this article points straight at one of these three:

  1. TrafficLights_3D_Model — SolidWorks source, STL files (stl/), and pre-sliced print profiles (gcode/)
  2. TrafficLights_PCB — Altium projects for both boards (TrafficLights/ = main controller, LedsPanel/ = LED panel), schematics, Gerbers, BOMs
  3. TrafficLights_Attiny13_firmware — the ATtiny13A firmware source (TrafficLight13.cpp) plus build.bat/flash.bat

Difficulty: Difficult

Time:

  1. ~26 hours unattended printing
  2. Base ~10h + Top ~1h
  3. Front panels ~9h
  4. Reflector stands ~5h
  5. PCB-Holder clamps ~1h
  6. ~6 hours active work
  7. placing/soldering components onto both PCB types ~4h, assuming you ordered bare boards from a fab
  8. soldering the buttons/battery wiring + crimping connectors ~1h
  9. wiring the harness and assembling the case ~1h
  10. if you etch/mill the PCBs yourself instead of ordering them, add
  11. ~8h for the main board
  12. ~8h for the 4 LED boards

Total: ~6 (or ~22) hours active work + ~26 hours unattended printing.

Cost:

  1. ~$18.30 in parts
  2. ~$10 for bare PCBs (1 order for the controller board, 1 order for the 4 LedsPanel boards — at the usual ~$5/order from PCBWay or similar, not counting shipping)
  3. ~$2.50 in filament

Total: ~$30.80, not counting shipping. If you etch/mill the PCBs yourself instead, you'll still need copper-clad board plus etching chemicals or milling tools, so it won't end up much cheaper.

Supplies

PCBs:

  1. TrafficLights_v2 controller PCB (qty 1):
  2. Gerbers in pcb/TrafficLights/Manufacturing
  3. LedsPanel PCB (qty 4 per unit):
  4. Gerbers for a single board: pcb/LedsPanel/Manufacturing_x1
  5. Gerbers for a 4-up panel: pcb/LedsPanel/Manufacturing_x4

Electronics + hardware, priced (per complete unit, prices approximate as of mid-2026):

  1. ATtiny13A-SU (qty 1, $1.08) — Main logic MCU. Mouser search
  2. TC4056A (qty 1, $0.035) — Li-ion battery charger IC. LCSC search · Mouser search
  3. DW01A (qty 1, $0.014) — Battery protection (over-charge/discharge/short-circuit). LCSC search · Mouser search
  4. FS8205A (qty 1, $0.10) — Battery protection (over-charge/discharge/short-circuit). LCSC search · Mouser search
  5. ME2188C50M5G (qty 1, $0.077) — 5V boost converter IC. LCSC search · Mouser search
  6. BSS84 (qty 1, $0.05) — Power-path switching P-MOSFET. Mouser search
  7. BAT760-7 (qty 1, $0.056) — Power-path Schottky diode. Mouser search
  8. LESD5D5.0CT1G (qty 1, $0.006) — USB-C ESD protection diode. LCSC search · Mouser search
  9. Inductor, 22µH 0603 (MHCI06030-220M-R8) (qty 1, $0.096) — Boost converter inductor. LCSC search · Mouser search
  10. Capacitor, 10µF polarized (C3) (qty 1, $0.06) — Boost converter input filter capacitor. LCSC search · Mouser search
  11. Capacitor, 100µF polarized (C4) (qty 1, $0.056) — 5V rail filter capacitor. LCSC search · Mouser search
  12. Capacitor, 22µF polarized (C5) (qty 1, $0.19) — 5V rail filter capacitor. LCSC search · Mouser search
  13. Capacitor, 100nF 0603 (C1, C2, C6) (qty 3, $0.006 ($0.002 ea)) — Decoupling capacitor. LCSC search · Mouser search
  14. Resistor, 0Ω jumper 0805 (R0) (qty 1, $0.001) — USB-C VBUS jumper (0Ω link). Mouser search
  15. Resistor, 100R 0603 1% (R6) (qty 1, $0.001) — Battery-protection IC support resistor. LCSC search · Mouser search
  16. Resistor, 150R 0603 1% (R3) (qty 1, $0.001) — Charge-status LED current limiter (red). LCSC search · Mouser search
  17. Resistor, 1K 0603 1% (R7) (qty 1, $0.001) — Battery-protection IC support resistor. LCSC search · Mouser search
  18. Resistor, 2K4 0603 1% (R5) (qty 1, $0.001) — Charger IC current-set resistor. LCSC search · Mouser search
  19. Resistor, 5K1 0603 1% (R1, R2) (qty 2, $0.001 (~$0.0005 ea)) — USB-C CC configuration pull-down. LCSC search · Mouser search
  20. Resistor, 9K1 0603 1% (R4) (qty 1, $0.001) — Charge-status LED current limiter (green). LCSC search · Mouser search
  21. Resistor, 10K 0603 1% (R8) (qty 1, $0.001) — Battery-protection IC support resistor. LCSC search · Mouser search
  22. Resistor, 10K 1206 1% (R9, R10) (qty 2, $0.001 (~$0.0005 ea)) — Mode-button / reset pull-up resistor. LCSC search · Mouser search
  23. Resistor, 470R 1206 1% (R12, R14) (qty 2, $0.003 (~$0.0017 ea)) — LED current-limiting resistor (yellow). Mouser search
  24. Resistor, 680R 1206 1% (R11, R16) (qty 2, $0.003 (~$0.0017 ea)) — LED current-limiting resistor (red). Mouser search
  25. Resistor, 4K7 1206 1% (R13, R15) (qty 2, $0.003 (~$0.0017 ea)) — LED current-limiting resistor (green). Mouser search
  26. LED, 5mm THT green (GNL-5012GD) (qty 4, $0.44 ($0.11 ea)) — Traffic signal LED. Mouser search · AliExpress search
  27. LED, 5mm THT red (GNL-5012ED) (qty 4, $0.44 ($0.11 ea)) — Traffic signal LED. Mouser search · AliExpress search
  28. LED, 5mm THT yellow (GNL-5012YD) (qty 4, $0.44 ($0.11 ea)) — Traffic signal LED. Mouser search · AliExpress search
  29. USB-C receptacle, 6-pin SMD (qty 1, $0.027) — USB-C power input. LCSC search · Mouser search
  30. JST XH 2.54mm 2-pin THT header (B2B-XH-A(LF)(SN)) (qty 2, $0.047 ($0.0233 ea)) — Board-side connector (battery / power button). LCSC search · Mouser search
  31. JST SH 1.0mm 2-pin THT header (BM02B-SRSS-TB) (qty 1, $0.078) — Board-side connector (mode button). LCSC search · Mouser search
  32. JST SH 1.0mm 6-pin THT header (BM06B-SRSS-TB) (qty 8, $1.38 ($0.173 ea)) — Board-side connector (LED panel link — 4 on main board + 1 per LedsPanel). LCSC search · Mouser search
  33. Pin header, 2.54mm 6-pin 2-row (ISP) (qty 1, $0.25) — ISP programming header. Mouser search
  34. JST SH 1.0mm 2-pin cable (qty 1, $0.12) — Mode button signal cable. AliExpress search
  35. JST XH 2.54mm 2-pin cable (qty 2, $0.26 ($0.13 ea)) — Power button / battery signal cable. AliExpress search
  36. JST SH 1.0mm 6-pin cable, ~80mm (qty 4, $1.56 ($0.39 ea)) — LED panel interconnect cable. AliExpress search
  37. Pushbutton, 12mm momentary, backlit (qty 2, $1.30 ($0.65 ea)) — Mode-select / power-status button. AliExpress search
  38. Resistor, 4.7kΩ (THT) (qty 2, $0.07 ($0.035 ea)) — Button backlight current limiter. Mouser search
  39. 18650 Li-ion cell, protected (qty 1, ~$4) — Main power cell. AliExpress search
  40. Lens, PMMA, D20mm, 60° (qty 12, $4.80 ($0.40 ea)) — LED diffuser lens. AliExpress search
  41. M3 heat-set threaded insert (qty 14, $0.66 ($0.047 ea)) — Case fastening. AliExpress search
  42. Screw, M3×6 pan head (qty 8, $0.13 ($0.016 ea)) — Case fastening. AliExpress search
  43. Screw, M3×12 countersunk (qty 5, $0.10 ($0.02 ea)) — Case fastening. AliExpress search
  44. Screw, M3×20 countersunk (qty 5, $0.15 ($0.03 ea)) — Case fastening. AliExpress search
  45. Washer, M3 plain (optional) (qty 8, $0.21 ($0.026 ea)) — Case fastening. AliExpress search

Estimated total: ~$18.30 / unit (parts only — excludes bare PCB fab, filament, and shipping).

Printed parts: Base, Top, PCB-Holder ×4, Reflectors, Front Planes.

  1. STL: 3d/stl/
  2. Pre-sliced: 3d/gcode/

Material/print-time/settings for each part are in Steps 1–5 below, not repeated here.

Tools:

  1. 3D printer (or a print service) — ABS, PETG, or "SBS" depending on the profile you pick
  2. Soldering iron (for the SMD board bring-up, if you're assembling rather than ordering it built)
  3. USBasp programmer (or an Arduino Nano wired as one) + avr-gcc toolchain
  4. Small Phillips/hex screwdriver for M3 fasteners

Print the Base

printed_parts_base.jpg

Black parts, printed in eSUN ABS+HS:

  1. Base — this step
  2. Top — Step 2
  3. Front Panels — Step 3

Recommended print settings, same for all three parts, not repeated in Steps 2–3:

  1. extruder 250°C
  2. bed 110°C
  3. layer height 0.2mm
  4. 6 perimeters
  5. 5 solid top/bottom layers
  6. 20% infill
Why black for the case, not the reflectors?
These parts are deliberately printed in black (or another dark, opaque filament) so the case itself doesn't leak LED light through the walls at night — light is only meant to escape through the lens holes in the Front Panels. If you print the structural parts in anything translucent, expect the whole case to glow, not just the signal lenses.


~10 hours, 38g (~15.5m) STL: 3d/stl/TrafficLights.v2-Base.STL · 3MF: 3d/gcode/TrafficLights.v2-Base.3mf

Print the Top

printed_parts_top.jpg

Same black ABS+HS settings as Step 1.

~1 hour, 9g (~4m) STL: 3d/stl/TrafficLights.v2-Top.STL · 3MF: 3d/gcode/TrafficLights.v2-Top.3mf

Print the Front Panels

printed_parts_front_panels.jpg

Same black ABS+HS settings as Step 1.

Three plain panels, one with the USB-C cutout. At the settings above, printing all 4 takes ~9 hours, 52g (~20.5m).

STL:

  1. 3d/stl/TrafficLights.v2-Front_x3.STL — 3 copies of the plain panel bundled in one file (not 3 complete units — you need this file once)
  2. 3d/stl/TrafficLights.v2-Front_USB_x1.STL — the 4th (USB-cutout) panel, only 1 needed

3MF (all 4 at once):

  1. 3d/gcode/TrafficLigths.v2_Front_Planes_All.3mf
Slicer tweak for the Front Panels specifically: at layer 13 (2.4–2.6mm) turn on ironing for top surfaces, then from layer 14 up (>2.6mm) drop to 0.1mm layer height. This smooths out the contour of the panels' sun-visor-style hoods over the lenses.

Print the PCB-Holders

step04_pcb_holders.jpg

Despite the name, the "PCB-Holder" parts aren't for the controller board — they're the small clamps that hold each LedsPanel board onto its lamp-rail stand (2 screws per clamp, one clamp per panel).

White/light-colored parts (PCB-Holder, this step; Reflectors, Step 5) use SBS or another low-shrinkage material (PETG etc.). Recommended print settings, same for both, not repeated in Step 5:

  1. layer height 0.2mm
  2. 6 perimeters
  3. 5 solid top/bottom layers
  4. 20% infill
  5. for SBS specifically: extruder 250°C / bed 90°C
Why white for these parts? They work as reflectors for the signal LEDs — you could paint the inside of the lens cups with silver paint instead, but plain white plastic is good enough; that's what the original build used.
Low shrinkage matters too: the LEDs are soldered onto the board first, then the printed cups have to slip over them — if you use a higher-shrinkage material, the holes may not line up and you'll need to rework the fit by hand.

(one unit's worth) — ~1 hour 10 minutes, 9g (~3.5m) STL: 3d/stl/TrafficLights.v2-PCB-Holder_x4.STL · 3MF: 3d/gcode/TrafficLights.v2-PCB-Holder_x4.3mf

Print the Reflectors

step05_reflectors.jpg

Same white/SBS settings as Step 4.

(top/bottom + top-only variants — one unit's worth) — ~5 hours, 38g (~15.5m) STL: 3d/stl/TrafficLights.v2-Reflector-Top-Bottom_x2.STL + 3d/stl/TrafficLights.v2-Reflector-Top.STL + 3d/stl/TrafficLights.v2-Reflector.STL · 3MF: 3d/gcode/TrafficLights.v2-Reflectors_All.3mf

Filament totals, one complete unit:

  1. Black (eSUN ABS+HS): 100g (~40m) — ~$1.50 at ABS+HS's typical ~$15/kg
  2. White (SBS): 50g (~20m) — ~$0.95 estimated (no solid per-kg SBS price found; ~$20/kg assumed,
  3. Total filament: ~150g (~60m), ~$2.50

Melt the M3 Brass Inserts Into the Reflector Stands

step06_brass_nuts_1.jpg
step06_brass_nuts_2.jpg
step06_brass_nuts_3.jpg
step06_brass_nuts_4.jpg

Heat-set the M3 brass threaded inserts into the printed reflector stands (from Step 5) with a soldering iron or dedicated heat-set tip, before assembly — much easier to do now than once the LEDs and lenses are in place.

Order the Controller Board

mainboard_back.png
mainboard_front.png

Send the Gerbers to a board house, or use them to etch/mill the board yourself: pcb/TrafficLights/Manufacturing/

Schematic/BOM/3D preview are in the board's Doc/ folder:

  1. TrafficLights/Doc
  2. ActiveBOM.BomDoc

Order the LedsPanel Boards

ledspanel_back.png
ledspanel_front.png

Gerbers:

  1. pcb/LedsPanel/Manufacturing_x1/ for one board at a time (you need 4 per unit)
  2. pcb/LedsPanel/Manufacturing_x4/ for a 4-up panel

Schematic/BOM/3D preview are in the board's Doc/ folder:

  1. LedsPanel/Doc
  2. LedsPanel.BomDoc

Solder the Controller Board

01_main_pcb_top.jpg
02_main_pcb_bottom.jpg

Solder the components per the schematic in TrafficLights_v2.pdf.

Solder the LedsPanel Boards

03_led_panel_top.jpg
04_led_panel_bottom.jpg

Solder the components per the schematic in LedsPanel.pdf.

Flash the Firmware

usbasp-jumpers.jpg
usbasp-connected-via-6pin-adapter.jpg
usbasp-flashing-result.jpg

The firmware (firmware/TrafficLight13.cpp) targets the ATtiny13A directly — 1024 bytes flash, 64 bytes RAM. You'll need avr-gcc and a USBasp programmer (plugs into the same header used for ISP, shared with two of the LED I/O pins). The controller board needs to be soldered up first (Step 9) — flashing happens through its ISP header, with the ATtiny13A already in place.

Check the USBasp's own jumpers before connecting anything — this one has:

  1. a 3.3V/5V select jumper (JP2) — the ATtiny13A here runs off the board's 5V rail
  2. a slow-programming-speed jumper (JP3)

Connect it to the controller board's ISP header (a 6-pin IDC-to-2.54mm adapter is the easiest way to go from the USBasp's 10-pin header down to the board's 6-pin JST-style ISP pins):

build.bat REM compiles + links + prints the size report
flash.bat REM sets fuses (internal 9.6MHz osc) + writes the hex

That confirms the write succeeded, but it's flash.bat's output, not build.bat's — it doesn't show the actual size report (flash/RAM used vs. the 1024B/64B budget). Worth capturing that separately too: run build.bat and grab the avr-size line it prints.

More detail on how the state machine works (it's a single PROGMEM table driving all 10 lighting states) is in the firmware repo's README, or in even more depth in the original author's Habr article (in Russian), if you want to understand or modify it.

Fit the LED Panels Into Their Stands

05_led_stand_front.jpg
06_led_stand_back.jpg
07_led_stand_wired.jpg

The assembled stands look like this.

Wire the Buttons and Prep the Battery

08_top_buttons_wired.jpg

Two separate sub-assemblies shown together in one photo, since both need their wire ends crimped onto connectors (not attached to each other yet):

  1. The two buttons, wired into the Top part (with the backlight resistors), with their own connectors
  2. The battery, with its connector

Wire the Harness and Connect Everything

09_harness_connected.jpg
wiring_schematic.png

Everything plugs into the controller board here — all 4 LED stands, both buttons, and the battery:

All connectors here are keyed (they only go in one way), but that only protects you at the connector housing — it's still worth knowing which lines actually care about polarity:

Polarity matters:

  1. Battery → SW-BAT (JST XH 2.54mm, 2-pin)
  2. Button backlights (LED-based) → +5V and GND from the J-USBASP header, through two 4.7kΩ resistors, shared by both buttons in a small daisy chain — red/black wires and +5V/GND labels on the diagram
  3. 4× LedsPanel boards → the four 6-pin JST SH 1.0mm headers (+J-WE1, .J-WE2, +J-NS1, .J-NS2), ~80mm cross-wired cables, one per panel — see the diagram for which panel goes where

Polarity doesn't matter:

  1. Mode button signal (normally-open) → SW-CTL (JST SH 1.0mm, 2-pin) — it's just a switch contact that closes the loop, marked "polarity doesn't matter" on the diagram
  2. Power/status button signal (normally-open) → SW-PWR (JST XH 2.54mm, 2-pin) — same

Prep the Front Panels With Lenses

10_front_panels_with_lens.jpg

Set the Controller Assembly Into the Base

11_pcb_into_base.jpg

Fix the Front Panels One at a Time

12_first_panel_fixed.jpg
13_second_panel_fixed.jpg
14_third_panel_fixed.jpg
15_fourth_panel_prep.jpg

Fix the first three front panels onto the Base one at a time, screwing each down before moving to the next. Prepare the fourth panel — the one with the USB-C cutout — the same way, but don't fix it in place yet: it goes in later, in Step 19, after the battery is in.

Drop the Battery In

16_battery_installed.jpg

Install the Fourth Front Panel

17_fourth_panel_installed.jpg

Install the Top and Close the Case

18_top_installed.jpg

Assembly Video

Сборка Светофора.

Watch the assembly on YouTube if anything from Steps 9–20 is still unclear.

Using & Credits

Using it

  1. Power switch (the "state" button) cuts power completely — no standby drain.
  2. Short-press the mode button to toggle between the normal 7-phase cycle and the flashing-yellow caution mode.
  3. Charge over USB-C, 5V/500mA — the front LED shows charging (red) vs. ready (green).

Credits

  1. The firmware and circuit design are adapted from Archy_Kld's Habr article "Three eyes hang on a pole..." — see firmware/README.md for the full attribution and what was changed.