Maker Challenge RGB Color Mixing

Quick Look

Grade Level: High school; also scalable for middle school

Time Required: 2 hours (wild guess!)

Subject Areas: Science and Technology

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
Copyright © 2006 Wintermute, Wikimedia Commons {PD} https://commons.wikimedia.org/wiki/File:AdditiveColorMixingII.png

Maker Challenge Recap

Students move through the engineering design process as they 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.

Maker Materials & Supplies

Worksheets and Attachments

Visit [www.teachengineering.org/makerchallenges/view/spfun_rgbcolor_maker1] to print or download.

Subscribe

Get the inside scoop on all things TeachEngineering such as new site features, curriculum updates, video releases, and more by signing up for our newsletter!
PS: We do not share personal information or emails with anyone.

More Curriculum Like This

High School Lesson
What Makes Up a Color?

As a part of the research and revise step of the Legacy Cycle, this lesson provides students with information they will need later on to be able to average pixels to simulate blurring in the peripheral plane of vision. Students learn why image color becomes important as we distort the outer boundari...

Kickoff

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 (){

Resources

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?

Copyright

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

Contributors

Brian Huang; Sabina Schill

Supporting Program

SparkFun Education

Last modified: August 16, 2023

Free K-12 standards-aligned STEM curriculum for educators everywhere.
Find more at TeachEngineering.org