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

CSTA's K-12 Standards 

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

Next Generation Science 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.

CCSS ELA

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.

World-Class Instructional Design and Assessment (WIDA) English Language Proficiency 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

California's K-12 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.

Science 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.

Common Core English Language Arts

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.

California English Language Development Standards

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)

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

Michigan Science 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.

Michigan English Language Arts

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 English Language Development

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

Science Texas Essential Knowledge & Skills Grade 3

(b)(2) Scientific investigation and reasoning. The student uses scientific practices during laboratory and outdoor investigations. The student is expected to:
(A) plan and implement descriptive investigations, including asking and answering questions, making inferences, and selecting and using equipment or technology needed, to solve a specific problem in the natural world;

(b)(3) Scientific investigation and reasoning. The student knows that information, critical thinking, scientific problem solving, and the contributions of scientists are used in making decisions.

Science Texas Essential Knowledge & Skills Grade 4

(a)(1)(A) Within the physical environment, students know about the physical properties of matter including mass, volume, states of matter, temperature, magnetism, and the ability to sink or float. Students will differentiate among forms of energy including mechanical, light, sound, and thermal energy. Students will explore electrical circuits and design descriptive investigations to explore the effect of force on objects.

(b)(3) Scientific investigation and reasoning. The student uses critical thinking and scientific problem solving to make informed decisions. The student is expected to:

    (A) analyze, evaluate, and critique scientific explanations by using evidence, logical reasoning, and experimental and observational testing;

    (B) represent the natural world using models such as the water cycle and stream tables and identify their limitations, including accuracy and size; and

    (C) connect grade-level appropriate science concepts with the history of science, science careers, and contributions of scientists.

(b)(4) Scientific investigation and reasoning. The student knows how to use a variety of tools, materials, equipment, and models to conduct science inquiry. The student is expected to:

collect, record, and analyze information using tools, including calculators, microscopes, cameras, computers, hand lenses, metric rulers, Celsius thermometers, mirrors, spring scales, balances, graduated cylinders, beakers, hot plates, meter sticks, magnets, collecting nets, and notebooks; timing devices; and materials to support observation of habitats of organisms such as terrariums and aquariums.

Science Texas Essential Knowledge & Skills Grade 5

(a)(1) In Grade 5, scientific investigations are used to learn about the natural world. Students should understand that certain types of questions can be answered by investigations and that methods, models, and conclusions built from these investigations change as new observations are made. Models of objects and events are tools for understanding the natural world and can show how systems work. They have limitations and based on new discoveries are constantly being modified to more closely reflect the natural world.

(a)(3) Recurring themes are pervasive in sciences, mathematics, and technology. These ideas transcend disciplinary boundaries and include patterns, cycles, systems, models, and change and constancy.

(b)(6) Force, motion, and energy. The student knows that energy occurs in many forms and can be observed in cycles, patterns, and systems. The student is expected to:

    (A) explore the uses of energy, including mechanical, light, thermal, electrical, and sound energy;

    (B) demonstrate that the flow of electricity in closed circuits can produce light, heat, or sound;

    (C) demonstrate that light travels in a straight line until it strikes an object and is reflected or travels through one medium to another and is refracted;

Math Texas Essential Knowledge & Skills Grades 6-8

(1) Mathematical process standards. The student uses mathematical processes to acquire and demonstrate mathematical understanding. The student is expected to:

    (A) apply mathematics to problems arising in everyday life, society, and the workplace;

    (B) use a problem-solving model that incorporates analyzing given information, formulating a plan or strategy, determining a solution, justifying the solution, and evaluating the problem-solving process and the reasonableness of the solution;

    (C) select tools, including real objects, manipulatives, paper and pencil, and technology as appropriate, and techniques, including mental math, estimation, and number sense as appropriate, to solve problems;

ELA Texas Essential Knowledge & Skills Grade 3

(b) (1)Developing and sustaining foundational language skills: listening, speaking, discussion, and thinking--oral language. The student develops oral language through listening, speaking, and discussion. The student is expected to:

    (A) listen actively, ask relevant questions to clarify information, and make pertinent comments;

    (B) follow, restate, and give oral instructions that involve a series of related sequences of action;

    (C) speak coherently about the topic under discussion, employing eye contact, speaking rate, volume, enunciation, and the conventions of language to communicate ideas effectively;

    (D) work collaboratively with others by following agreed-upon rules, norms, and protocols; and

    (E) develop social communication such as conversing politely in all situations.

ELA Texas Essential Knowledge & Skills Grades 4 & 5

(b) (1)Developing and sustaining foundational language skills: listening, speaking, discussion, and thinking--oral language. The student develops oral language through listening, speaking, and discussion. The student is expected to:

    (A) listen actively, ask relevant questions to clarify information, and make pertinent comments;

    (B) follow, restate, and give oral instructions that involve a series of related sequences of action;

    (C) express an opinion supported by accurate information, employing eye contact, speaking rate, volume, enunciation, and the conventions of language to communicate ideas effectively; and

    (D) work collaboratively with others to develop a plan of shared responsibilities.

(b)(13) Inquiry and research: listening, speaking, reading, writing, and thinking using multiple texts. The student engages in both short-term and sustained recursive inquiry processes for a variety of purposes. The student is expected to:

    (A) generate and clarify questions on a topic for formal and informal inquiry;

    (B) develop and follow a research plan with adult assistance;

    (C) identify and gather relevant information from a variety of sources;

    (D) understand credibility of primary and secondary sources;

    (E) demonstrate understanding of information gathered;

    (F) differentiate between paraphrasing and plagiarism when using source materials;

    (G) develop a bibliography; and

    (H) use an appropriate mode of delivery, whether written, oral, or multimodal, to present results.

§74.4. English Language Proficiency Standards

(c) Cross-curricular second language acquisition essential knowledge and skills.

(3) Cross-curricular second language acquisition/speaking.

(D) speak using grade-level content area vocabulary in context to internalize new English words and build academic language proficiency;

(E) share information in cooperative learning interactions;

(F) ask and give information ranging from using a very limited bank of high-frequency, high-need, concrete vocabulary, including key words and expressions needed for basic communication in academic and social contexts, to using abstract and content-based vocabulary during extended speaking assignments;

(G) express opinions, ideas, and feelings ranging from communicating single words and short phrases to participating in extended discussions on a variety of social and grade-appropriate academic topics;

(H) narrate, describe, and explain with increasing specificity and detail as more English is acquired;

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!

Color Coded

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.

Color Coded

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.

Color Coded

Step 4: Color variable

Color Coded

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

Color Coded
Color Coded

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.

Color Coded

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".

Color Coded

Step 8: A few more ifs

Color Coded

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.

Color Coded
Color Coded

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.

Color Coded
Color Coded

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.

Color Coded
Color Coded

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.

Color Coded

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!