COLOR CODED

PIPER MAKE EDUCATOR RESOURCES SERIES

To do this project, you will need a Piper Make Extended Starter Kit. Get yours here:

Color us impressed with this tutorial using a color sensor!

To get started, head to Piper Make and hit this icon:

Time: 60 minutes

Age Range: 8+

Difficulty: Advanced

In this project, students will use the color sensor to see how sensors “read” and report color. This project teaches not only the coding elements of if/then statements and interfacing with the color sensor, but also more fundamental principles of how color is seen in the world around them. The experience culminates with students writing code that allows them to map colors to different words/letters to create a “secret code” which can be shared using the export and import features of our Piper Make interface.

Note: There are step by step instructions for the students to follow in the tutorials included in each project on Piper Make. These provide directions both for writing code and for building the electronic circuits. The tutorials are well-defined and most students will be able to follow them with little assistance required.

LEARNING OBJECTIVES

Students will:

 

  • Practice coding loops and computational thinking
  • Demonstrate how computer hardware and software work together as a system to accomplish tasks
  • Review key electronics and programming understandings:
    • wire and pin positions for specific inputs and outputs.
    • loops: running the same sequence multiple times
    • events: while a pin’s condition is on or off, another action happens
  • Create programs that use variables to store and modify data.
  • Create programs that include events, loops, and conditionals.
  • Decompose problems into smaller, manageable tasks which may themselves be decomposed.
  • Create programs by incorporating smaller portions of existing programs, to develop something new or add more advanced features.
  • Test and debug a program or algorithm to ensure it accomplishes the intended task.

STANDARDS ALIGNMENT

CA Computer Science Standards

3-5.CS.2: Demonstrate how computer hardware and software work together as a system to accomplish tasks.

3-5.CS.3: Determine potential solutions to solve simple hardware and software problems using common troubleshooting strategies.

3-5.DA.9: Use data to highlight and/or propose relationships, predict outcomes, or communicate ideas.

3-5.AP.11: Create programs that use variables to store and modify data.

3-5.AP.12: Create programs that include events, loops, and conditionals.

3-5.AP.13: Decompose problems into smaller, manageable tasks which may themselves be decomposed.

3-5.AP.14: Create programs by incorporating smaller portions of existing programs, to develop something new or add more advanced features.

3-5.AP.17: Test and debug a program or algorithm to ensure it accomplishes the intended task.

 

Core Science Standards Alignment

4-PS4-2: Develop a model to describe that light reflecting from objects and entering the eye allows objects to be seen.

MS-PS4-2: Develop and use a model to describe that waves are reflected, absorbed, or transmitted through various materials.

LANGUAGE OBJECTIVES

CCSS.ELA.L.W.3.8: Recall information from experiences or gather information from print and digital sources; take brief notes on sources and sort evidence into provided categories.

CCSS.ELA.L.W.3.10: Write routinely over extended time frames (time for research, reflection, and revision) and shorter time frames (a single sitting or a day or two) for a range of discipline-specific tasks, purposes, and audiences.

CA ELD.3.C.11: Supporting own opinions and evaluating others’ opinions in speaking and writing

CA ELD.3.C.12: Selecting and applying varied and precise vocabulary and language structures to effectively convey ideas

MICHIGAN INTEGRATED TECHNOLOGY COMPETENCIES FOR STUDENTS (MITECS)

Standards Alignment

1B-CS-02 Model how computer hardware and software work together as a system to accomplish tasks. Subconcept: Hardware & Software; Practice 4.4

1B-CS-03 Determine potential solutions to solve simple hardware and software problems using

common troubleshooting strategies. Subconcept: Troubleshooting; Practice 6.2

1B-DA-07 Use data to highlight or propose cause-and-effect relationships, predict outcomes, or

communicate an idea. Subconcept: Inference & Models; Practice 7.1

1B-AP-09 Create programs that use variables to store and modify data. Subconcept: Variables; Practice 5.2

1B-AP-10 Create programs that include sequences, events, loops, and conditionals. Subconcept: Control; Practice 5.2

1B-AP-11 Decompose (break down) problems into smaller, manageable subproblems to facilitate the program development process. Subconcept: Modularity; Practice 3.2

1B-AP-12 Modify, remix, or incorporate portions of an existing program into one’s own work, to develop something new or add more advanced features. Subconcept: Modularity; Practice 5.3

1B-AP-15 Test and debug (identify and fix errors) a program or algorithm to ensure it runs as intended. Subconcept: Program Development; Practice 6.1, 6.2

 

Core Content Standards

4-PS4-2: Develop a model to describe that light reflecting from objects and entering the eye allows objects to be seen.

MS-PS4-2: Develop and use a model to describe that waves are reflected, absorbed, or transmitted through various materials.

 

Language Objectives

Michigan ELA, Grade 3-8, Research, 8: Recall information from experiences or gather information from print and digital sources; take brief notes on sources and sort evidence into provided categories.

Michigan ELA, Grade 3-8, Range of Writing, 10: Write routinely over extended time frames (time for research, reflection, and revision) and shorter time frames (a single sitting or a day or two) for a range of discipline-specific tasks, purposes, and audiences.

WIDA ELD Standards

ELD-SI.K-3.Argue:

  • Ask questions about others’ opinions
  • Support own opinions with reasons
  • Clarify and elaborate ideas based on feedback
  • Defend change in one’s own thinking
  • Revise one’s own opinions based on new information

 

ELD-SC.2-3.Argue.Interpretive:

Interpret scientific arguments by

  • Identifying potential evidence from data, models, and/or information from investigations of phenomena or design solutions
  • Analyzing whether evidence is relevant or not
  • Distinguishing between evidence and opinions

CONCEPTS

Students use sequences and simple loops to make a program spell out letters in the display when the RGB values are entered into the code. Color Coded is a great step for learning how to create programs that include sequences, events, loops, and conditionals.

PARTS

Raspberry Pi Pico, breadboard, charging cable, the Color Sensor

GPIO SETUP

Red: VCC (Voltage Input) - 3.3V Power, Black: GND - Ground, Yellow: SCL (Serial Clock Line) - GP21, Green: SDA (Serial Data Line) - GP20

OVERVIEW OF STEPS

Step 1: Color Sensor

You’re going to need a Color Sensor for this project—which you might have on hand if you’re one of our earliest Monthly Makers Club members OR if you have an Extended Starter Pack. If not, don’t worry -- head over to playpiper.com and search for the Sensor Explorer to get three snazzy sensors.

If you’ve got your Color Sensor though, let’s get started! We’re going to write some super secret messages using color!

Step 2: What does it do?

Before we start using our sensor, let’s go over how we normally see color and how our sensor tries to copy that.

Think about the shirt you have on right now and pick a color on there. It’s pretty easy to tell what color it is right? But what if I told you that color was actually what our eyes processed after white light hit your shirt and only the color you see was bounced off?

White light is a mix of every color and most objects reflect only a few colors back - the rest are absorbed.

If you’re wearing a blue shirt, the red wavelengths and the green wavelengths and so on all got absorbed by the shirt and only the blue reflected back! Our eyes detect that using cells in the back of the eye called rods and cones.

The Color Sensor works this way, too. It emits a white light and then measures the red, green, and blue wavelengths that bounce back. Based on the amount of red, green, and blue light that bounces back, we can figure out what color the sensor is "looking at."

Click NEXT.

Step 3: Connect your sensor

Let’s start by connecting our Color Sensor. Remember, the DIGITAL VIEW is a handy way to see the GPIO pin locations. Here’s what each of those ports on the sensor connect to:

Red: VCC (Voltage Input) - 3.3V Power
Black: GND - Ground
Yellow: SCL (Serial Clock Line) - GP21
Green: SDA (Serial Data Line) - GP20

Important note: You MUST turn on the switch on the side of the sensor to generate the white light the Color Sensor uses to sense which wavelengths of light reflect back to the sensor.

You’ll see the light turn on when everything is wired up correctly and the switch is in the correct position.

Step 4: Color variable

Let’s start by getting our Color Sensor to do its thing—namely, sensing color! Most colors can be coded using combinations of Red, Green, or Blue. These are called RGB values.

Let’s start by storing the RGB value from the color sensor block into a Variable. This will let us use the value several times in our program without having to read the sensor again each time.

Click the Create variable button in the Variables menu and name it sensorColor.

Drag out the set sensorColor block from the variables menu and place the color sensor block from the Sensing menu in there.

Click NEXT.

Step 5: Graphing

We want to be able to use the DATA visualizer to look at the data from the Color Sensor. This will let us see the same color the sensor is seeing.

To send data to the DATA tab at the bottom of the screen, we need to use a graph block from the Actions menu.

What do you usually think of when you think of a graph? Is it a bunch of bars or maybe points like this?

On the graph block, select color data from the menu and then place it below your variable block. Drag out a sensorColor block from the Variable menu and place it in the graph block.

Then, place the set sensorColor and graph color data blocks in a repeat forever block from the Loops menu. Finally, change the wait time on the loop to 1 second.

Click NEXT.

Step 6: Try it out!

Open the DATA tab at the bottom of the screen. Then, click the CONNECT and START buttons to run your program.


If you lightly press your Color Sensor against a colored piece of paper or other object, the graph in the DATA tab will display the color that the Color Sensor is seeing. It will also show the RGB values, and the individual red, green, and blue sensor readings:

Click STOP, then click NEXT.

Step 7: Color logic

Great! Now that we have our variable, where the data will come from, and how the data will be shown, we have to set up our program to interpret the data for us.

To do this, we’re going to compare the RGB values coming in from the sensor to known RGB values of different colors. Basically, If the RGB values are close to the RGB values for pink, we want our program to say "Pink".

Step 8: A few more ifs

Do you remember when you made an if-else if block in the Reaction Game tutorial?

We want our program to be able to identify five different colors, so we are going to build an if-else if-else if-else if-else if block!

To start, click theblue gear icon on the if block. A new menu will appear. Drag an else if block straight over and connect it under the if. Do this three more times:

Click theblue gear icon again to close the menu, then click NEXT.

Step 9: Compare conditional

Now let’s get our program to interpret those RGB values for us!

Let’s start by comparing an RGB value from a specific color (like Pink!) to the RGB value from the sensor. Drag out a compare _ to _ block from the Logic menu. and place it in the first opening of the _ = _ block in the if block:

Next, we want to compare a color block from the Values menu to the sensorColor variable we set up before. Drag those blocks into the compare block. Then drag out a number value block from the Values menu and add it to the other side of the _ = _ block.

Click NEXT.

Step 10: Making a comparison

If the RGB values are more than 70% similar, it’s a pretty good bet that the color being sensed is the one defined in your color block.

To test if the color is similar enough, change the "=" to a greater than ">" and change 0 to 70:

Now go ahead and change that color block to red. Now if the color "red" block and the sensorColor block are similar enough, then you’re probably sensing something red!

Let’s drag out a print statement and make the program print "red" when something red is detected:

Click NEXT.

Step 11: Print color

Let’s do the same thing for four other colors—blue, green, yellow, and pink. Duplicate the blocks and add them into the rest of the big if block.

Change the colors in the color blocks first. Then go ahead and change the print statements and label to say "Yellow", "Blue", "Green", "Pink":

When your code looks like the picture above, you’re ready to rock! Click NEXT.

Step 12: Graphing RGB

Open the CONSOLE tab at the bottom of the screen.

Click START and find things that you can scan with your Color Sensor. Is your Color Sensor able to match the color you see?

If not, you may need to adjust the colors in the color blocks - you can also use the DATA tab to see what color the Color Sensor is seeing to help you make those adjustments!

When you're happy with your program, click STOP, then click NEXT.

Step 13: Hello world

Remember that the thing being printed in the console is coded by your print statements, which you can change around to spell out different things if you would like. Map different words onto different colors, like "hello" onto red and "world" onto world.

You can make your program "say" a whole sentence by scanning colors in the right order!

After you've changed the print statements, click NEXT.

Step 14: Start and scan

Now click START and put your sensor over something red and then over something blue. Do you see the readout on your console as "Hello World"?

What other coded messages can you create?

Click EXIT to return to the home screen and try out more tutorials!