3D-Printed Art

This is a 3D-printed piece of art, a “Voronoi” lamp designed by Nik Markellov. Nik has generously made his design available for free on Thingiverse.com. I’ve extended his design by adding a set of three Arduino-controlled RGB LEDs to create a changing color pattern. Here’s what the completed lamp looks like.

IMG_2700

Creating the LED assembly isn’t difficult, but you’ll need to have some experience using a fine-tipped soldering iron. Just a few parts are needed for this: I used an Arduino Nano, three LEDs, and nine 270 ohm resistors. That’s it! I ordered common anode LEDs from Amazon, but you can use either a common anode or cathode type, the only difference is whether you connect the LEDs to +5V or ground on the Arduino. As an aside, you choose the correct value resistor depending on the “forward voltage” specification of the LEDs you’re using and the voltage of your power supply (+5V DC in the case of this project using an Arduino). Here’s a good article if you want to learn more.

IMG_2672

Start this project by soldering a common +5V rail to the corresponding pin on the Arduino Nano. In this picture, it’s the bare copper wire attached on the Nano on the left.

Next, separate the 5V pin from the three Red, Green and Blue pins on the RGB LEDs. Usually, the 5V (or ground, depending on the type of the LED) pin is identified by being a little longer than the other three leads.

Solder the 270 ohm resistors to each of the Red, Green and Blue leads, and solder wires to to the other ends of the resistors so that the three LEDs are at different heights above the Arduino Nano. This vertically “staggers” the three LEDs as you’ll see in the completed design.

IMG_2675

I connected the first LED (the highest position LED) red lead to pin 4, the green lead to pin 5 and the blue lead to pin 6 of the Arduino. Repeat this pattern for the second and third LEDs, using Arduino pins 7, 8, and 9 for the 2nd (middle height) LED and pins 10, 11 and 12 for the 3rd LED.

IMG_2676

With the LED array assembled, transfer the sketch below to your Arduino and install the assembly in the square cavity open at the base of the lamp. This code will cycle the color of each LED. You can increase the value of the delay() function call at the bottom of the loop() method if you want to slow down the color transitions.

// define pinouts
const int LED1redPin = 4;
const int LED1greenPin = 5;
const int LED1bluePin = 6;

const int LED2redPin = 7;
const int LED2greenPin = 8;
const int LED2bluePin = 9;

const int LED3redPin = 10;
const int LED3greenPin = 11;
const int LED3bluePin = 12;

void setup() 
{
      // Start off with the LED off.
     setColourRgb(0,0,0);
}

void loop() 
{
     unsigned int rgbColour[3];

     // Start off with red.
     rgbColour[0] = 255;
     rgbColour[1] = 0;
     rgbColour[2] = 0;

     // Choose the colours to increment and decrement.
     for (int decColour = 0; decColour < 3; decColour += 1) 
     {
            int incColour = decColour == 2 ? 0 : decColour + 1;

            // cross-fade the two colours.
           for(int i = 0; i < 255; i += 1) 
           {
                   rgbColour[decColour] -= 1;
                   rgbColour[incColour] += 1;

                   setColourRgb(rgbColour[0], rgbColour[1], rgbColour[2]);

                  delay(100);
           }
     }
}

void setColourRgb(unsigned int red, unsigned int green, unsigned int blue) 
{
        analogWrite(LED1redPin, red);
        analogWrite(LED1greenPin, green);
        analogWrite(LED1bluePin, blue);

        analogWrite(LED2redPin, blue);
        analogWrite(LED2greenPin, red);
        analogWrite(LED2bluePin, green);

        analogWrite(LED3redPin, green);
        analogWrite(LED3greenPin, blue);
        analogWrite(LED3bluePin, red);

}