Maker Challenge: RGB Color Mixing

Contributed by: SparkFun Education

A diagram shows the overlap of red, blue and green circles resulting in the colors of cyan, yellow, magenta and white in the various overlapping areas.
You can mix colors to make any new color you want!
Copyright © 2006 Wintermute, Wikimedia Commons {PD}

Maker Challenge Recap

Students write Arduino code and use a “digital sandbox” to create new colors out of the three programming primary colors: green, red and blue. They develop their own functions, use them to make disco light shows, and vary the pattern and colors of their shows. The digital sandbox is a hardware and software learning platform powered by a microcontroller that can interact with real-world inputs like light, while at the same time controlling LEDs and other outputs.

More Curriculum Like This

Introduction to Arduino: Getting Connected and Blinking LEDs

Students learn how to connect Arduino microcontroller boards to computers and write basic code to blink LEDs. Provided steps guide students through the connection process, troubleshooting common pitfalls and writing their first Arduino programs. Then they independently write their own code to blink ...

Build Your Own Arduino Light Sculpture! Part 2

In the companion activity, students experimented with Arduino programming to blink a single LED. During this activity, students build on that experience as they learn about breadboards and how to hook up multiple LEDs and control them individually so that they can complete a variety of challenges to...

Building Arduino Light Sculptures

Students gain practice in Arduino fundamentals as they design their own small-sized prototype light sculptures to light up a hypothetical courtyard. They program Arduino microcontrollers to control the lighting behavior of at least three light-emitting diodes (LEDs) to create imaginative light displ...

High School Maker Challenge
Build Your Own Arduino Light Sculpture! Part 1

Students create projects that introduce them to Arduino—a small device that can be easily programmed to control and monitor a variety of external devices like LEDs and sensors. They are given three challenges—to modify an LED blinking rate until it cannot be seen, to replicate a heartbeat pattern an...

Maker Materials & Supplies


Bleh… white. So boring! Let’s add some color to this digital sandbox. Let's look at making some cool colors with a special device on your digital sandbox called the RGB LED. It's a special device that is basically three LEDs—red, green and blue—all integrated into a single package! It's pretty cool.
In art class, you probably learned about primary colors, and how you can mix them to produce any other color that exists. While the artsy primary colors you might be familiar with are red, yellow and blue, in electronics (and programming in general) our primary colors are red, green and blue. If we can control the three LEDs individually, we can start making all kinds of cool colors! Let's get started!

Let’s begin with this simple piece of code (see Figure 1). Type this in and upload it to your digital sandbox.

Code uploaded in the digital sandbox. Includes a void setup and void loop.

What does is this example code do? What color is the LED?

Notice that we introduced a new command called analogWrite(). It looks a lot like the digitalWrite() function, except that we can specify the intensity of the brightness with a value instead of just ON and OFF!

The analogWrite() command in the digital sandbox: analogWrite([pin], [value]);

analogWrite() uses two arguments—a pin and a value that can be specified as a number from 0 to 255. This is pretty cool, but it only works on a few of the pins on the Arduino. These pins are 3, 5, 6, 9, 10 and 11. Luckily, the three pins that the RGB LED are connected to are pins 9, 10 and 11!

In our example, we get a standard blink of an orange-ish color by mixing 225 of red with 150 of green. Let’s make some other colors by playing with the analog inputs. How do you make purple, orange, salmon or crimson? How about two new colors? Create each color and record the RGB values for each. And, give your custom colors their own names!

Do you find yourself copying a lot of the same code blocks? Clean up your code by writing your own function. A function is a block of code that can be re-used and called by name. Why might engineers make use of functions? When engineers develop programs, they save time and space by creating functions so that they can more easily create code to direct complex machines. Let's call our function purple(). Add this code to the very end of your program:

The purple() function in the digital sandbox

Does this look familiar? Now, let's change your code. This is what your code should look like:

Modified code in the digital sandbox. Includes a purple() and void purple (){


Maker Time

Now, let's make a disco light show. Think about what colors you want to add to your show and determine their RGB values. Then, write functions for each color and modify the delays so that you get a blinking or fading pattern to blend between the various colors. What does your pattern do? Could you create a pattern to match music?

As a challenge: Combine the repeat loops, fading example, and the RGB LED to create a lightscape that alternates from red to blue to green to red.

Suggest students record the RGB values of their colors in a table like this:

A three column, six-row table to record the RGB (red, green, blue) values for the colors purple, orange, salmon, crimson and others.

Wrap Up

As a class, have students share, compare and reflect on their disco shows:

  • Which colors did you show and why? How did you change your functions to create new colors?
  • What applications might engineers find for color-changing LEDs?
  • What would you improve or change if you were to re-write your code?


Brian Huang; Sabina Schill


© 2016 by Regents of the University of Colorado; original © 2014 SparkFun Education

Supporting Program

SparkFun Education

Last modified: May 4, 2017