Educator Resource Car Race – Piper

CAR RACE

PIPER MAKE EDUCATOR RESOURCES SERIES

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

Revisit the Beam Break project to challenge friends to a race.

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

Time: 60 minutes

Age Range: 10+

Difficulty: Advanced

This project allows students to apply what they learned in Beam Break. The sensors are to be coded and used for a car race.

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 breadboarding and wiring
  • Review and understand computational concepts of:
    • loops: running the same sequence multiple times.
    • sequence: identifying a series of steps for a task
  • Demonstrate computational thinking core concepts, including:
    • Algorithm Design by creating an ordered series of instructions for solving similar problems or for doing a task, such as turning a light off and on in the right order.
    • Simulation by developing a program to imitate the real-world process of a stoplight.
  • Create programs that include events, loops, and conditionals.
  • Decompose problems into smaller, manageable tasks which may themselves be decomposed.
  • Test and debug a program or algorithm to ensure it accomplishes the intended task.
  • Perform different roles when collaborating with peers during the design, implementation, and review stages of program development.

STANDARDS ALIGNMENT

CSTA's K-12 Standards 

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

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

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

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.

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.

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

In this project, students will apply what they've learned about loops and wiring in order to create a program that determines the winner of a race.

PARTS

Raspberry Pi Pico, breadboard, charging cable, M2M Green Jumper Wire, M2M Yellow Jumper Wire, 2 M2M Red Jumper Wires, 2 M2M Black Jumper Wires, Yellow LED, Red LED, Green LED, 330 Ω Resistor, 2 Beam Break Sensor Pairs

GPIO SETUP

Green LED GP13, Yellow LED GP14, Red LED GP15

OVERVIEW OF STEPS

Step 1: Who will win the race?

Has your Hot Wheels™ race ever been so close that you couldn't tell who won?

In this tutorial, you are going to use the Beam Break Sensors to see which car wins in a race.

If you don't have a second Hot Wheels™ car, don't worry! You can use anything that will roll, like a marble or even a coin. You can also do the race with just one car. The CONSOLE will show the winner's time, so you can take turns and see who had the fastest time!

One quick note: If you have already completed the Beam Break tutorial - most of the build and circuit steps are the same.

Are you ready to get started? Click NEXT.

Step 2: Get Your Stuff

Let’s start by gathering our supplies. For this project, you’ll need your Pico and breadboard, 6 jumper wires, 3 LEDs, 3 resistors, and both pairs of Beam Break Sensors.

The jumper wires don't have to be the same color as the ones in the diagram - you can use any color wires that you have.

You'll also need the parts that came with the Beam Break Sensors. 4 small wood pieces, 2 larger wood pieces, two black, C-shaped plastic pieces, and 2 Hot Wheels™ track, as shown.

 

Step 3: Build Your Beam Break Sensors

Your Beam Break Sensors have two parts - an emitter and a receiver. The emitter sends out a beam of infrared light and the receiver senses whether that beam is broken. So let's set up your Beam Break gates

To start, line up the Beam Break Sensor that has 3 wires (the receiver) with the hole on one of the smaller wood pieces.

Grab the C-shaped plastic piece, and hold the Beam Break receiver in the black plastic piece like the picture below. Then, hook the small wood piece in at the top and push in the bottom until the small wood piece is vertical.

Next, feed the wires through the hole on the bottom of the black plastic piece.

Now, grab one of the Beam Break Sensors with 2 wires. This is the emitter side of the Beam Break Sensor.

Install it and the small wood piece just like you did on the other side - use the picture below as a guide.

Then, feed the 2 wires through both holes of the black plastic piece.

Do this again for the other pair of Beam Break Sensors. When both sets are ready, click NEXT.

Step 4: Finish the Beam Break Sensors

Awesome, now we've got to make space for the track in between the emitter and the receiver!

Take the larger wood piece and push it straight down over the center of the black plastic piece.

The black plastic piece should stick through the cutout in the wood piece. Do this for both sets of Sensors.

Now that both Sensors are attached to the plastic and wood pieces, we will call the finished part a "Beam Break Module". When you finish building both Beam Break Modules, click NEXT.

Step 5: Attach the Modules

Look carefully at the image below. The orange Hot Wheels™ track will hook onto the Beam Break Module like this.

Attach a track piece to each one of the Beam Break Modules.

When both sensors are attached to the track pieces, click NEXT.

Step 6: Wire up some LEDs

Awesome! Now that the track is ready, let's build the Beam Break circuits! Let's start by building the 3-LED circuit we built back in Traffic Light.
First, create a GROUND rail by connecting a GROUND pin to the (-) blue column on the edge of the breadboard, as shown at the top of the picture below.

Insert a Red LED into the breadboard across the center gap. Make sure the shorter leg of the LED is on the same side as the GROUND wire you just connected.

Connect a resistor between the short leg of the LED and the (-) blue column on the edge of the breadboard.

Then, connect a jumper wire from GP15 on the Pico to the long leg of the Red LED.

Repeat the steps above to add a Yellow LED connected to GP14 and a Green LED connected to GP13.

Click NEXT when you are finished building the LED part of the circuit.

Step 7: Connect the Modules

The Beam Break Modules have a lot of wires! Don't worry, they are actually easy to connect! We'll do it one step at a time, using the image below as a guide.

Start by connecting the (+) red column on the bottom of the breadboard to the 5V pin of the Pico using a jumper wire.

Next, connect the (-) blue column on the bottom of the breadboard to one of the GROUND pins on the Pico.

Connect all four of the black wires from the Beam Break Modules to the (-) blue column at the bottom of the breadboard. Then, connect all of the red wires from the Beam Break Modules to the (+) red column at the bottom of the breadboard.

Finally, connect the first Beam Break Module's white wire to GP6 on the Pico. Connect the second Beam Break Module's white wire to GP11 on the Pico.

Note that the first Beam Break Module is connected to GP6, and the second Beam Break Module is connected to GP11. When you send the car racing down the track, it needs to break the first beam, and then the second one. If you send it through backwards, the program we build won't work!

When your Beam Break Modules are connected, click NEXT.

Step 8: What's an IR Beam?

But wait, now that we have our Beam Break Modules all wired up, how come we can't see the light emitted by the emitter?


The emitter (the Sensor with two wires) is an infrared LED. Infrared light is special because we can't see it with our eyes.

If you have a cell phone or digital camera, the camera's Sensor can probably see it though! Here's a video clip from a cell phone showing the infrared glow from the emitter when it is connected.

The receiver, the other half of the Beam Break Module, uses a device called a phototransistor.

If we break down the word, "photo" means light (think photosynthesis), and "transistors" are digital switches. So a phototransistor is a light-sensitive digital switch!
Shining infrared light on the phototransistor turns it on, and when the car blocks the infrared light, the phototransistor turns off.

All we have to do to determine the winner of the race is measure which Beam Break Module turns off first.

Click NEXT to start building the code to measure the speed of the car.

Step 9: Ready, Set, Go!

Let's build some code that will light up the LEDs in order to make a "Ready, Set, Go!" indicator so we know when to push our Hot Wheels™ car down the track.

To make a Ready, Set, Go light, the red LED needs to light up first for 2 seconds - that means "Ready". Then, the red LED will turn off and the yellow LED will turn on for 2 seconds. That means "Set". And finally, the green LED will turn on, and that means "Go!"

Click NEXT to learn how to build the code for the Ready, Set, Go! lights.

Step 10: Code the Lights

Let's build another Function to control the LEDs. Drag out a to do something block from the Functions menu. Then, change the name of the blocks to "ready set go lights".

Drag a turn pin block from the Chip menu and place it inside of the to ready set go lights block. Drag a wait block from the Chip menu and connect it below the turn pin block. Set the variables of the turn pin block to pin 15 and ON, and set the wait time on the wait block to 2 seconds.

Next, right click the turn pin block and select Duplicate. Connect the new block below the wait block. Change it from ON to OFF.

This will turn the red LED on, wait for two seconds, and then turn it off. We need the same code again, but using pin 14 to turn on the yellow LED for 2 seconds.

Use the right click button to duplicate your blocks and set them to pin 14.

Your code will now turn on the red light for 2 seconds, and then turn on the yellow light for 2 seconds.

All the function needs to do now is turn on the green light. Right click one of the turn pin blocks and duplicate it. Set the variables to pin 13 and ON, and connect it below the last block inside of the function.

Click NEXT.

Step 11: The Winning Function!

So now we have our Ready, Set, Go lights connected and programmed, but how can we get the code to detect which car passes through a Beam Break Module first?

To do this, we’re going to build another Function.

Drag out a to do something → return block from the Function menu and change the name of the function to "determine winner".

Be careful, there are two blocks in the Functions menu that look similar. Make sure you have the one with the return at the end.

Step 12: Send it back!

The first thing to think of when creating a function is what it will return. In this case, we want to know which car passes through its Beam Break Module first, so we’ll want our Function to return the number of the car that won!

To start, let’s create a variable (from the Variables menu) and call it "winner". Then, drag the winner block and place it in the return of your function so that it can be printed when the game ends.

Step 13: Setup the ifs

To figure out what that winner variable should be set to, we’ll need to check whether race car 1 or race car 2 passed through its Beam Break Module first.

To do this, let’s write an if-else if statement. This will test which, if any, car passes through its Beam Break Module.

Drag an if-do block from the top of the Logic menu into your "determine winner" Function block to get started.

We still need to turn the if-do block into an if-else if block. To do this, click the small blue gear icon on the if-do block. This will bring up a new menu that lets you change the shape of the if block.

In that menu, drag an else if block over to the if block and connect it. Click the blue gear icon again to close the menu.

Click NEXT when your if-else if block is ready.

Step 14: Checking in

Remember we want the code to do the following: if the Beam Break Module connected to GP6 is triggered first, then we want "race car 1" to be saved to our winner variable. Otherwise, if the Beam Break Module connected to GP11 is first, then we want "race car 2" to be saved to the winner variable.

How would you code that?

Click NEXT to find out!

Step 15: Looking for button presses

Drag out an is pin LOW when pulled UP block and add it to the first test of our if-else if block. Change the pin number variable to 6.

Duplicate the is pin block for the else-if test. Change that pin number variable to 11.

Step 16: Setting the variable

If the GP6 circuit completes first, we want to set our variable to "race car 1", so drag a set winner to block from the Variables menu and place it in the first do statement.

Next, you'll need a "_" block from the Values menu. Grab one and drag it into the set winner to block.
Type "race car 1" as the value into the "_" block.

Repeat all of the steps for race car 2 below the GP11 test step.

Step 17: Keep checking

But we want our code to be constantly looping, testing if either Beam Break Module detects a car, and we want that process to be happening FAST!

Let’s add a Loop Function to the check steps. Drag out repeat forever block and change the wait time to 0.

Why zero? Well if we set it to 1 second, both cars could pass through their Beam Break Modules, and THEN the loop will execute, automatically making the first is pin block in the loop, "race car 1" the winner. Every time. Boo!

Instead, with the wait time set to zero, the loop happens so quickly that even the winner in the closest race is picked up!!

Click NEXT.

Step 18: Exiting the loop

But we also want the loop to stop running when a car passes through a Beam Break Module, right? Otherwise, we’ll never know who won!

To have the function return the winner value, we have to stop the loop from running using an exit loop block. So if race car 1 hits its button, the winner variable will be set to "race car 1" and the loop will be exited.

If race car 2 hits its button first, then the same process should happen for player two in the if-else part of the block.

Drag out two exit loop blocks and add them to your function code like this.

 

Step 19: Start Putting it All Together

Now that we have our functions, let's put it all together.

Grab a start block from the Chip menu and drag it onto the workspace. We want the Ready, Set, Go! lights to start first, so grab a ready set go lights block from the Functions menu and place it below the start block.

Let's clean up the workspace a bit. Right-click the to ready set go lights block and select Collapse. Do the same thing to the to determine winner block:

Step 20: Who won?

So let’s go back to our main code and code up the big reveal! Right now we have the LED coming on, but after that, we want to execute the function we’ve written. And ideally, because the function’s output is the winner, we want to print that in our console.

To do that, drag a print block from the Chip menu and connect it below the ready set go lights block. Delete the "_" inside of the print block by dragging it to the trash can. Grab the determine winner block from the Function menu and place it inside of the print block.

After that, go ahead and turn off the green LED using a turn pin block from the Chip menu. Connect it below the print block. Change the block's variables to 13 and OFF.

All we have left is adding in the time of the race! How long did it take for the car to get to the finish line?

Click the Variables menu and then click the Create variable... button. Name your new variable "start time".

Then, grab the set start time to block and insert it right after the ready set go lights block. Next, grab a chip clock block from the Chip menu and insert it into the set start time to block.

Grab a print block from the Chip menu and place it at the end of your code. Delete the "_" block in the print block by dragging it to the trash.

Next, grab a _ + _ block from the Logic menu and place it into the print block. Change the + (plus) to a - (minus).

Grab another chip clock block from the Chip menu and insert it into the left side of the _ - _ block. Then, grab a start time block from the Variables menu and place it into the right side of the _ - _ block.

Almost there!

Grab another print block from the Chip menu and place it at the end of your program. In the "_" block, type "seconds".

That's it! Now you will know how long it took the winning car to make it to the end of the race track!

Step 21: Play your game!

Now your code is ready to go.

Here's a reminder on how you play! Start with your cars at the top of the track. After the green light turns on, let go of the cars. Whichever car passes through its Beam Break Module first wins the race!

Grab a friend and hit START to play!

Keep tweaking your game! Can you modify the messages that print? Can you add a button and a loop so that the game resets and starts again?

Click NEXT.

Step 22: You Finished!

Click EXIT to return to the menu and start your next coding challenge.