A simple but powerful start to my Lego city. My minifigs like to work and play around the clock, so we need lighting.


– Turn on and off the lights


– 12v LED lighting will require a transistor to manage the external power supply

– Wiring (I have a big city)


– Raspberry Pi (or any NodeJS host)

– Arduino (I used the Mega 2560 but any will do)

– 12v LEDs (or an LED strip)

– 12v power supply

– breadboard

– NPN power transistor

– 220 Ohm resistors

– 1k Ohm resistor


We basically need to provide 12 volts to our various LEDs. Using a power transistor will allow us to switch larger power with smaller quantities. This makes it possible to use a 3.3v GPIO pin to supply the 12v for the lights. The schematic below uses the 5 volt supply on the board, but we will connect an external 12v source instead.

Use an NPN Power Transistor, one 1k resistor, and 220 Ohm resistors for the LEDs. Connect the LEDs in parallel to 5 volts using 220 Ohm resistors. Connect the BASE (transistor’s left leg) through a 1k resistor to pin 9, the COLLECTOR (middle leg) to the ground legs of the LEDs and the EMITTER (right leg) to ground.”

The schematic and other details are available via Fritzing.org, which is a great place to find simple circuits for Arduino or similar controllers.



This is a topic all by itself, but here are some major hints for wiring Lego.

12v LED strips


These are great because they include the resistors built-in for 12v operation. There is adhesive on the backside, which attaches perfectly to a 6 stud Lego plate. Now you can easily attach this within buildings with ease!


mini LED


These mini LEDs will need an inline resistor which is normally included. These bulbs are great for bright individual effects, such as street lighting. You can either use the breadboard for your resistor or solder inline for a more permanent installation.

micro LED

The micro LEDs are really REALLY small. The actual bulb looks like the root of your hair! These are perfect for small applications, where you can actually close two Lego bricks together over the bulb. Just be very careful when wiring, as the leeds can easily be pulled off the bulb.



Basics: Lets just turn on the lights.



var five = require("johnny-five");
var board = new five.Board();

board.on("ready", function() {
 var cityLed = new five.Led(8); //general city lighting

 // Add devices to REPL (optional)
 cityLed: cityLed

 console.log("Turned on City Lights!");

Now Save and Run!

node citylights-basic.js

You should see something like this on your console, and the lights should turn on!

root@thethingbox:~/IoL# node citylights-basic.js 

1441842312279 Device(s) /dev/ttyACM0  

1441842312363 Connected /dev/ttyACM0  

1441842315337 Repl Initialized  

>> Turned on City Lights!

To turn off the lights, we can write directly on the command line using REPL. This is cool because you can make functions or actual devices accessible while the program is running. This will come in handy for testing throughout your projects.

Just type cityLed.off() to turn off the lights. You can access all of its properties in this way. There will be a bunch of text after the command which can be ignored for now.

root@thethingbox:~/IoL# node citylights-basic.js 

1441842312279 Device(s) /dev/ttyACM0 

1441842312363 Connected /dev/ttyACM0 

1441842315337 Repl Initialized 

>> Turned on City Lights!


{ board: 

 { timer: 

 { _idleTimeout: -1,

 _idlePrev: null,

 _idleNext: null,

 _idleStart: 1441842312365,

 _monotonicStartTime: 184267586,

 _onTimeout: null,


Lights Out!