Introduction: Arduino Controlled RGB-LED-Lamp #phablabs

About: PHABLABS 4.0 is based on combining the World of Photonics (Science of light and light technologies) with the growing creative ecosystem of existing Fab Labs. The “Photonics Workshops” introduce a variety of fu…

Build your own RGB Lamp providing 3 bright light cones in red, green and blue (or other colors) which turn on and off in a row. The speed of the light show can be manually controlled by a turning knob which connects to a potentiometer (adjustable resistor). At low speed, the light cones visibly light up one after the other; at maximum speed they appear to shine at the same time, which generates some interesting color mixing: When you put your hands between the lamp and a white wall, new colors and colorful shadows appear!

Properties of this workshop:

Timeplanning: Total: 3h

1. Explaining of the photonics concept of 'colours' and 'basics of electronics': 20 minutes
2. Controlling and implementing electronics: 40 minutes
3. Programming the Wemos: 30 minutes
4. Checking the lamp: 20 minutes
5. Assembling the box: 40 minutes

Target audience: Young minds (10-14 years old)

Estimated cost: € 23

DISCLAIMER: By using this information you agree to be legally bound by these terms, which shall take effect immediately on your first use of the information. PHABLABS 4.0 consortium and its member organizations give no warranty that the provided information is accurate, up-to-date or complete. You are responsible for independently verifying the information. VUB cannot be held liable for any loss or damage that may arise directly or indirectly from the use of or reliance on the information and/or products provided. PHABLABS 4.0 consortium and its member organizations disclaim all responsibility to the maximum extent possible under applicable laws: All express or implied warranties in relation to the information and your use of it are excluded. All liability, including for negligence, to you arising directly or indirectly in connection with the information or from your use of it is excluded. This instruction is published under the Creative Commons licence CC-BY-NC.

Step 1: Colours

Light is an electromagnetic wave, which moves through space at a speed of about c=300,000 kilometers per second, which is a little more than 1,000,000,000 km/hour. Like every other wave (sound, water, …), it oscillates while it propagates, creating crests and troughs.

Photo 1: The distance between two successive crests is called the wavelength. Light oscillates very quickly, at a frequency of about f=600,000,000,000,000 times per second (600 THz) for green light, which results in a wavelength of =c/f= 500nm.

Photo 2: There is a wide range of electromagnetic waves, which differ only be their wavelengths. The photo shows the most important ones, ranging from radio waves with a wavelength of meters, over microwaves, light, X-rays and Gamma rays, which are emitted in radioactive processes. The ‘visible spectrum’, which contains all colors we see, is only a tiny part of the existing electromagnetic spec- trum. Its wavelengths range from 700nm (red) to 400nm (violet), with all rainbow colors in between.

Our eyes have 3 types of receptor, for red, green and blue. All other colors are mixing products in the eye. For example, yellow light does not have a special receptor in the human eye. But, its wave- length is between red and green and excites the red and the green receptors about the same as equal amounts of red and green do, see Figure 2. It also means that you can create yellow light by mixing red and green light! The human eye cannot see any difference between “true” yellow light and a suitable combination of red and green (or other colored) light. There are some colors which are not present in the spectrum in Figure 2, because they do not have their own unique wavelength. They can only be created from mixing colors. Those are, for example, magenta, which is similar to pink (a mixture of red and blue), white (a mixture of red, blue and green), and so on. Black, on the other hand, is just the absence of light.

Photo 3: The photo shows the color mixing of red, green and blue. Because our eyes have red, green and blue receptors, a computer screen or smartphone display also use red, green and blue light to create almost every possible color. You can see their individual color pixels when you look very closely.

Step 2: Electronic Basics

Voltage and Current

Photo 1: It is useful to compare an electrical circuit to something we have a better understanding of, like a water pipe system, see photo. A battery or solar cell like a water pump; they generate a pressure, which corresponds to the voltage. When you connect a pipe with one end to a water reservoir and with the other to a water pump, the pump generates pressure (voltage) and water current. The water current corresponds to an electrical current. The higher the pump pressure (voltage), the larger the resulting water flow (current). You can limit the water flow (current) by putting something in its way (a ball of hair in a clogged up shower drain) or make the tube thinner. Such a restriction corresponds to an electrical resistor.

Protecting LEDs

LEDs get destroyed when the current becomes too high. When we operate them with a given voltage, each LED needs their individual resistor to limit their current. Red LEDs need the least voltage and therefore the largest protective resistor. Resistors usually have colored rings which denote their value.

Photo 2: The encryption key.

When we connect the LEDs to the driver ULN2003, we need to take into account the driver’s inner resistor, which is like resistor already present in the IC. This means, that we need, in fact, smaller resistors than anticipated, which are best determined experimentally.

Here are the values we found:

LED=Red > Resistor = 5,6 Ohm > color ring code = green-blue-gold-gold
LED=Green > Resistor = 3,3 Ohm > color ring code = orange-orange-gold-gold
LED=Blue > Resistor = 4,7 Ohm > color ring code = yellow-violet-gold-gold

Depending on the LEDs you use, those values might differ. But don’t worry; it’s safe to operate your high-power-LEDs with the values given.

Step 3: Part List

Photonics parts:

*Red, Green and Blue 1W LED on starboard (‘LED’ stands for Light Emitting diode and generates light of certain color. A diode is a one-way-street for electrical current. When you turn around the diode, the current is blocked.)

*3 Lenses (The lenses we use concentrate the light provided by each LED. They are simply attached to the LED.)

Other parts:

*1 Wemos (A microcontroller, which can be pro- grammed as easily as an Arduino, will control the LEDs according to the uploaded ‘sketch’. This microcontroller also can be replaced by an ESP8266).

*1 ULN2003A (This integrated circuit (IC) is a ‘driver’ for the LEDs: the microcontroller does not provide enough current for the power-hungry LEDs, so we need an amplifier, which is controlled by a small current and provides a large cur- rent. That’s what the ULN2003A does.)

*1 Potentiometer: Some people call it 'rotary angle sensor' these days. A potentiometer is an adjustable resistor, with the resistance depending on the angle of rotation. It's widely used as a volume control in radios.

*1 Breadboard 170 pins and 1 small breadboard 55 pins

*Resistors 1 of 3.3 Ohm, 1 of 4.7 Ohm and 1 of 5.6 Ohm (Resistors limit the current in an electrical circuit. Here we need them for protecting the LEDs. Each LED-color needs a different resistor. A resistor has a set of colored rings on it which denote its electrical resistance; the larger its resistance, the more it limits the current.)

*Electric wires with pins

*USB A to USB B connector for programming and powering the WeMos.

*4 screws (M3 x 20mm) and 4 nuts (M3)

Tools (for example in Fab Labs):

*Laser cutter

*Soldering iron

*Computer for programming Wemos

Don't find the material you are looking for? Via this link you could buy all the photonics material needed for this workshop.

Step 4: Periphery

This project uses a WeMos to control 3 high-power LEDs, but a NodeMCU, an ESP8266 or similar will do as well. To keep the confusion at a reasonable level, we describe everything in terms of the WeMos. When using a different platform, the program environment needs to be adapted accordingly.

The WeMos is powered and programmed through a USB connection to a computer. Once it is pro- grammed, it can be powered by phone charger.

Photo 1: The WeMos is an Arduino based platform which can be directly programmed using a desktop or laptop and which can perform a large variety of tasks. Today, there are many variations of the Arduino platform coming in all sizes and peripheries. In our project, we choose the WeMos, which is a tiny, cheap and very powerful platform. There are many free Arduino tutorials available on the internet, which are perfect for any stage of advancement. In this tutorial, we therefore limit ourselves to those things necessary for building our WeMos controlled RGB-Lamp.

The metallic box is a shield for electromagnetic waves and contains the microcontroller and the WLAN transceiver, which allows the WeMos to wirelessly communicate. In the WeMos Lite, this shield is missing, which does not seem to pose a problem though. The curly printed wire outside this box on the left is its antenna. The WeMos is powered through the USBconnector on the bottom, which runs on 5 volts. Since the WeMos can only take 3.3 volts, there are additional components on the bottom of the board which provide this voltage.

Photo 2: The wiring of the WeMos to the periphery electronics

The WeMos switches its outputs D1, D2 and D3 on and off, executing the commands received from your smartphone. Those signals are fed to the driver IC ULN2003, where they are amplified. The ULN2003 powers the red, green and blue LEDs via protective resistors, without which the LEDs would burn up. All current circuits must be closed, so the ground (negative terminal) goes to the ULN2003, and the 5V positive terminal goes to each LED.

The potentiometer is connected to the 3,3V (!) positive terminal and ground. Its center terminal then provides a voltage of 0…3,3V, depending on the angular position of the turning knob. This voltage is fed to the analog input A0 of the WeMos and determines the speed at which the LEDs blink.

Step 5: Quick Start for the WeMos

For programming and controlling the Wemos, we use the Arduino IDE (Integrated development environment), which can be downloaded from

Photo 1: Open the Arduino IDE, go to 'Files' and click on 'Preferences'.
Copy the following line into the “Additional Boards Manager URLs” text box: and press OK to close the Preferences tab.

Photo 2: Select “Tools” and “Board”, and click on “Boards Manager…” in the pop-up menu. Navigate to “esp8266 by ESP8266 Community” and click into the field. This will install the programming environment we need, for the WeMos we use, or other boards included in this package as shown.

Photo 3: Finally, click again in Tools>Board and select the appropriate WeMos (D1 R2 & mini, Lite, or whatever you use) from the list.

Now our WeMos is ready to be programmed.

Step 6: The Sketch: Program Code

Photo 1: This is the sketch that controls the 3 LEDs. It is included with this workshop and will also be downloadable at It consists of 2 parts: the setup and an endless loop. In the setup function void setup(){…} the WeMos terminals D1, D2 and D3 are defined as outputs for the 3 LEDs and the terminal A0 is defined as input for the potentiometer. Further down, the function void loop() {…} switches off one LED and lights up the next, then waits for t milliseconds and moves on the next LED. The delay time t corresponds to the voltage at terminal A0, which is determined by the position of the potentiometer. There are many excellent basic and advanced tutorials on the web which explain everything in more detail.

Connect the WeMos to a free USB-port of your computer (Photo 2) and find out the name of this port, using the Device Manager (German: Geräte-ManageràAnschlüsse (COM/LPT)). In the IDE, select the port with ToolsàPort. Make sure the right type of WeMos is selected (ToolsàBoard …). Compile and upload the file using the button displaying an arrow pointing right. If everything goes well, the IDE should look like photo 3 after the upload.

Step 7: Building the RGB Lamp

We will build the circuit on a breadboard. Breadboards come in different sizes and have one more common rail. The large breadboards we use have a total of 17×10=170 points. Each 10-point-column consists of 2 segments with 5 mutually connected points each.

The high-power LEDs we use can handle about 100mA without cooling. With appropriate cooling, which is not part of this workshop, they can support more current. The WeMos module cannot provide such large currents; its output terminals are limited to about 12mA. This is why we need a driver, which is basically an amplifier for the low-power outputs of the WeMos. Here, we use the universal driver IC ULN2003A, which costs only a few cents and has 7 individual drivers. It also has 16 pins. There is a notch on one of the short edges. When this notch is on the left as in Fig. 10, the lower row is defined as pins 1…8, the upper row 16…9. As seen from the diagram, the pin numbers are counted counterclockwise.

Photo 1 & 2: When the notch is on the left, the 7 inputs (1B…7B) are on the bottom, the outputs (1C…7C) on the top. On the right are 2 additional terminals; we only need “E”, which is connected to ground.

Photo 3: First we solder about 12cm (4”) long insulated wires to the terminals. Again, use black wires for the negative and red or white wires for the positive LED terminal.

Photo 4: Then we prepare the potentiometer. The braided wire connector that comes with the potentiometer is too soft for the breadboard, so we don’t use it. Instead, we take 10cm long solid wires (0.5…0.6mm diameter) and solder them to the potentiometer terminals.

Now it’s time to mount everything on those breadboards. The following figure shows the first four steps. Photo 5: Always remember, 5 points in a row are connected, as marked by a cyan line in (a). Insert the ULN2003 across the bridge as shown. Make sure the U-shaped notch (marked here by a yellow ellipse) points towards the breadboard center. Then insert the WeMos controller symmetrically across the bridge, so that its USB port points outwards and its rightmost pins are inside the breadboard’s rightmost points. (c) Connect the WeMos ground (labelled “G” or “GND”) to the ULN2003 ground. (d) Connect the potentiometer terminals as shown: black to ground, red to 3.3 volts and green to the WeMos analogue input A0.

Now, connect WeMos outputs D1,D2,D3 with inputs 5,6,7 of the ULN2003 as shown in Photo 6 (a). Then we take the small breadboard. Like for the large breadboard, 5 points in each row are mutually connected. Insert the 3 different resistors as shown. The uppermost (green-blue-gold-gold) is for the red LED, the one in the middle (orange-orange-gold-gold) for the green and the one at the bottom (yellow-violet-gold-gold) for the blue one. Connect the red, green and blue LEDs as shown in (c) and (d).

Connect the LED-board to the main board as shown in Photo 7 (a,b,c). Before you proceed to (d), compare you complete setup up with the fritzing scheme to make sure all components are the right way around and everything is connect correctly. Then connect your WeMos to one of your computer’s USB sockets (d).

Step 8: Checking the Lamp

Connect the lamp to a USB socket. The 3 LEDs should light up. If they don’t, immediately disconnect the lamp from the USB socket and search for the error. When you turn the potentiometer the speed at which the LEDs blink should change.

Step 9: Building the Box

Now it’s time to build a box around it. A laser cutter cuts out the parts from a sheet of wood according to the program files attached. You can easily push out the single element. We use wood glue on same parts as indicated. The first steps are shown in photo 1 & 2.

Now that the box is finished, we insert the electronics. Photo 3 shows the steps. The large breadboard has a sticky bottom, just remove the protective foil (Photo 3a). Place the board into the box (b), make sure the WeMos USB-port aligns with the box opening and press down until it sticks to the ground. Insert the potentiometer (c) and plug its turning knob to its axis (d).

Now we install the LED and the lenses. Assemble the 3 lens kits as shown in Photo 4(a-c). In order to keep those lenses safely attached to the LEDs, we prepare an auxiliary plate; see Figure 24(d). Glue those corner pieces to the auxiliary plate as shown.

Insert the nuts in each corner hole (Photo 5a,b). Then put the boards with the screws on top of the LEDs (Photo 5 c,d), and carefully insert the screws (Photo 6a). Turn those screws not too tight, just enough to keep everything in place (Photo 6b).

Glue 4 more corner pieces to the cover lid (Photo 6c), and then, as soon as the glue is dry, carefully (!) close the box with the lid (Photo 6d).


Step 10: Operation of the Lamp.

Reconnect the lamp to the power supply. Is everything still working? If not, unplug immediately and search for the fault.

With the potentiometer you can select the speed of the light change. Point the lamp towards a white wall and look what the shadows look like when you put your fingers in between.

Where do those extra colors come from? If you don’t remember, look in Chapter 2 (Colors).

Step 11: End Result and Conclusion

What we learned?

In this workshop, we have learned how to build an
inexpensive RGB-lamp with the microcontroller WeMos. We learned how to program such a device with freeware software available on the internet, and how to build the peripheral electronics to safely operate high-power-LEDs. We also got acquainted with making our own tailored wooden box around the device using laser-cutting.

Concluding thoughts

Arduino-based systems are an inexpensive and easy way to solve all kinds of problems, that only a couple of years ago required extensive expert knowledge. Today, there is a huge Arduino community around the world who works on all kinds of open-source-projects and who are more than happy to share their knowledge and experience. You can use the introduction from this workshop to come up with and solve your own tasks.


PHABLABS 4.0 is a European project where two major trends are combined into one powerful and ambitious innovation pathway for digitization of European industry: On the one hand the growing awareness of photonics as an important innovation driver and a key enabling technology towards a better society, and on the other hand the exploding network of vibrant Fab Labs where next-generation practical skills-based learning using KETs is core but where photonics is currently lacking.

This workshop was set up by the Joanneum Research in close collaboration with Fab Lab Graz.