LEGO Compatible Street Light and LED-Brick

by JohnThinger in Circuits > LEDs

1767 Views, 14 Favorites, 0 Comments

LEGO Compatible Street Light and LED-Brick

A LEGO Compatible Street Light (and LED-Brick)

This instructable shows how to build a LEGO compatible Street Light and an LED brick using snippets of a WS2812B LED strip, and it shows how to drive these LEDs with a small microcontroller. As an advantage over other street lights, it can be used to set different colors and intensities – and it does some “rainbow-lighting”.

Supplies

Supplies.jpg

For building the lanterns you will need:

-         3x microswitch

-         1x perfboard 2 cm x 8 cm (6 x 28 holes)

-         1x DIP-8 socket

-         1x Attiny85-20PU microcontroller

-         1x WS2812B LED strip (with 144 LEDs/m)

-         1x 0.14….0.25 mm2 wire ( » 1 m)

-         1x 3D printer with some filament (or print service)

-         1x 40 pin female Dupont header (optional)

-         2x 1 pin male Dupont header (optional)

-         2x 3 pin male Dupont header (optional)

-         Some jumper wires and an Arduino Uno (or an ISP) for programming the Attiny

Print the Lantern and the Bricks

Bricks.jpg
Print Preview.jpg
Scratching.jpg

Attached, you find 5 STL files:

  • Lantern: This is the street light.
  • Perfboard Brick: This will be the holder of the perfboard with circuit we are going to make. For sure, you can place the perfboard outside your LEGO scene or you may “hide” it in a different case made of LEGO bricks. This is just a simple LEGO compatible brick for keeping the microcontroller within the scene as you probably want to use the pushbuttons to change the light intensity or color.
  • Lantern Cable Brick: With this optional 4x2 brick, you can fix the cables coming from the lantern to the ground plate if you want to hide the cables.
  • Cable Guide Brick: Another optional 4x2 brick for “guiding” the cables over longer distances.
  • LED Brick: This is an alternative brick that can carry two LEDs. It might be useful if you want to build the “stem” of the lantern from standard LEGO 2x1 bricks, or if you want to integrate LED lights in other structures like a wall of a LEGO house.

In the pictures you will see more details on the intended use of these bricks.

After some approaches, I found that printing all parts upside down (with the knobs to the build plate) yields the optimal results in terms of tolerances which is important to make the bricks snap to original LEGO elements. Print all parts with a layer height of 0.2 mm, 2mm wall thickness, 25% infill, support, and a brim. The brim is important for the street lights, in particular.

Please note: If the bricks are too tight to snap on other LEGO bricks or plates, use a sharp knife and scratch a bit of material from the connectors like shown above. 

Electrical Circuit - the Board

Attiny.png
Circuit - 001.jpg
Circuit - 002.jpg
Circuit - 003.jpg
Circuit - 005.jpg

Cut a segment with 13 holes from the perfboard and solder the connections, the headers and the DIP-8 socket as shown in the diagrams and pictures.

In the middle of the board, you see the Attiny and the three pushbuttons. The pushbuttons are connected to the digital inputs D0, D2, and D4. The circuit will be able to drive two LED strips independently using the digital outputs D1 and D3.

While the first diagram (named “Overview”) shows all connections on the front side (including the power and ground lines as well as the connections to the LEDs), the wiring is really done on the backside of the board. Hence, please place the headers, the socket, and the microswitches on one side as shown in the diagram marked with the label “Front” and solder all connections as shown on the diagram with label “Back”. The “Back” diagram shows the board as you will see it during soldering (i.e. mirrored to the front side).

Start with the solder tracks. Use some copper or sliver wire to do the longer ones. Short connections can be done directly using solder tin. After the tracks are established, you must bridge power and GND to both sides using short shielded cables as you will cross other connections or MCU pins (see red and black cables in the pictures).

Please note: The diagrams include the Attiny85 for a better understanding of the wiring. In the real world, please solder the DIP-8 socket here as shown in the photos. You will need it for inserting and removing the Attiny after/before (re-)programming.
Please note: As show in the diagrams, I also recommend headers for connecting the LEDs. I am using pieces that I have cut from a 40 pin female header. Then I crimped male headers to the cables going to the LEDs (see next step). If you do not have any need for flexibility, however, you can omit the headers and solder the cables coming from the LEDs to the board directly.
Please Note: Do not confuse the numbers of the digital outputs with the pin numbers of the Attiny. If in doubt, please refer to the attached Attiny pinout diagram. 

The perfboard can now be pushed into the printed “Perfboard Brick”. 

Electrifying the Lanterns

WS2812b.jpg
IMG_3513.JPEG
IMG_3519_copy.jpg
IMG_3497.JPEG

For the street lights you need pieces of two LEDs from the LED strip. You can cut the LED strips at any position. However, on the 144 LED/m strips, there is not much place between each LED, so carefully cut them in a way that you will still see about half a millimeter of the contacts after the cut is done. I found the strips are very “forgiving”, so even you do not have really much space, soldering the cables is not that hard. Just make sure that you always solder the cables to the input of each LED, i.e. keep an eye on the arrows that are printed on the strips. Start soldering by adding some solder to each contact of the snippet of the LED strips. Then solder the wires.

If you want to add a plug on the end of the cables (that goes to the female headers on the board), make sure to crimp or solder it after you have pushed the cable through the tube of the lantern. (This is, in fact, obvious as you won’t get neither the connectors nor the LEDs through the tube... ...however, I finished the cabling twice before “adding the printed part to the cable” … 😮).

As we have seen the diagrams of the previous step, our board has two outputs, so it can theoretically drive only two street lights. Hence, if you need more lights, you will need to make some Y-adapter for all three connections (5V, GND and the control signal). In the example shown on the photos, I have done this by crimping two wires in one pin. As an alternative, you can solder them or buy ready-made adapters like this one

Finally, push the connectors into the corresponding headers on the board (if you did not solder them directly). In the same way, make a connection to a 5V power supply using either directly soldered cables or single pin Dupont connectors.

Programming

The Attiny does not feature an USB port and hence it cannot be connected to a PC directly. Instead, you will need an ISP or an Arduino Uno acting as ISP. There is a perfect description on how to do this here. Please follow this guideline and select your ISP and the Attiny85 board in the Arduino IDE accordingly.

We use the Adafruit NeoPixel library for running the LEDs, so after starting the Arduino IDE please go to the “Tools” menu, select “Manage Libraries...”, and make sure this library is installed.

Now it is time to open the attached LEGO_LEDs.ino file. As you already know from the circuit diagram, we are able to drive two LED strips separately on D1 and D3. While you can use this to make more diverse lighting setups, the code, however, will send the same output to both “channels” with the current configuration.

The program is straightforward:

The set-up routine initializes both LED outputs. It assigns a maximum number of 32 LEDs as defined in the macro “LED_COUNT”

The “loop” is watching the button states:

  • If no button is pressed and the device was just switched on, it will change the color of all connected LEDs every 10 milliseconds (see lines 93 and 94 in the code). Colors will cycle through the entire spectrum like a rainbow. The brightness of this rainbow can be defined in the macro LED_BRIGHTNESS.
  • As soon as any button is pressed, the device will switch to constant light. Pressing a button will increase the intensity of one of the three components of the LEDs (red, green, blue). The first button increases the intensity of the red component, the second button the green, and the third button the blue component. Each component will be increased from dark to fully lit in 4 steps each, after which it will go off again. This way you can mix your individual light color.
  • If you press the first both buttons together, the device goes back to the “rainbow mode”.

Downloads

The Real Use of Addressable LEDs

LED Brick.jpg
Rainbow.jpg

You might have wondered why the entire design is based on addressable LED strips when we are using the same color on each LED. There are two reasons for that:

  1. The WS2812b LED strips are easy to handle during soldering, assembly, wiring and coding.
  2. They are cheap.

But, for sure, you can do much more with our tiny circuit, e.g. if you want to illuminate a LEGO house with different light colors or light states (i.e.: on, off or dimmed) in each room of a house. This is why I included the alternative 4x2 LED Brick that can be integrated in walls. Again, you can add snippets of two LEDs in each brick and connect them the same way as the lanterns, i.e. you only solder cables on the input of each “mini strip”. Or, you can solder another cable on the output of one “mini strip” and connect it to the input of the next “mini strip” in another LED brick. The introduction video shows this for a series of four bricks. As for the lanterns, they will all show the same color and intensity as soon as one of the buttons is pressed, but you will notice that they will present a "waving" rainbow in the initial “rainbow mode”. To activate this, please set the macro MAKE_RAINBOW_WAVE to true in line 24 of the code.

Please note: That code is limiting each output to addressing 32 LEDs (i.e. 16 bricks) in the macro LED_COUNT. Increase this value, if you need more LEDs/bricks.
Please note: In my pictures, I have always soldered all three wires (+5V, signal, and GND) on the input and the output side of the strip segments in the bricks. You must do so for the (white) signal wire if you want to have different colors on each LED. Depending on your design, however, it might be easier to do this only with the signal line and to draw the +5V and GND lines always from a central power source. This way, you will have only four instead of six wires at each brick.
Please note: The speed of the rainbow is affected by three elements: lines 89 and 104 define how quick the colors change, i.e. if you want to have a slower rainbow effect, either increase the delay in line 104 or reduce the constant added to the "hue" in line 89. Furthermore, the constant hex value in the lines 93 and 94 defines how much difference there will be in the colors between two LEDs. Increase the original value of 0x750 to make the changes more radical and reduce it to make the color more similar between the single LEDs.
hue += 0x50; // Line 89.
...
   pixels1.setPixelColor(i, pixels1.gamma32(pixels1.ColorHSV(hue+i*0x750, 255, LED_INTENSITY))); // Line 93.
   pixels2.setPixelColor(i, pixels2.gamma32(pixels2.ColorHSV(hue+i*0x750, 255, LED_INTENSITY))); // Line 94.
...
delay(10); // Line 104.

Further Extensions

Final.jpg

As you will have noticed, the perfboard is already pretty “packed” with elements, so if you want to address more LEDs / LED strips separately, you will run into out-of-space problems. For sure, this can be compensated by just using a perfboard with a few more holes (or by getting a proper custom PCB), but there will be another obstacle as there is only one digital output pin left on the Attiny. This is pin 1 (i.e. D5) which should not be used as it acts as RESET pin in the normal configuration on the Attiny, and this is needed for programming the microcontroller.

However, If you increase the size of the board or squeeze the elements a bit more, there is a simpler way to “free” two digital output pins: Add (different) resistors behind the microswitches and connect them all to one input pin using that pin as analog input. Then you are ready to use the remaining pins as digital outputs for addressing more LEDs.

As one more hint, you may have seen that the circuit does not include an electrolytic capacitor between 5V and GND. If you spot any instabilities in the circuit, it could be a good idea to add a 50…100µF capacitor here. As most power supplies are stabilized and we only drive some LEDs, however, it should not be necessary to add it.

Finally, I wish you a happy enlightenment!