SECURITY ZONE

PIPER MAKE EDUCATOR RESOURCES SERIES

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

Ring the alarm with this Ultrasonic Range Finder Tutorial!

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

Time: 60 minutes

Age Range: 8+

Difficulty: Intermediate

In Security Zone, students use the ultrasonic range finder to measure distance in real time. The project itself teaches students fundamentals about coding if/then statements and sound in the Piper Make interface. As the rangefinder measures distance by echolocation, this project also offers students a chance to learn about sound propagation in a hands-on way. As Piper Make is Chrome PWA (progressive web app), it is also accessible offline, allowing students to explore measuring distance in settings outside the classroom without internet. The project culminates in students building a “security zone” around the sensor with an alarm sounding when the zone is breached.

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

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

 

Science Standards Alignment

3-PS2-2: Make observations and/or measurements of an object’s motion to provide evidence that a pattern can be used to predict future motion.

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

 

Math Standards Alignment

3.MD.B.4: Generate measurement data by measuring lengths using rulers marked with halves and fourths of an inch. Show the data by making a line plot, where the horizontal scale is marked off in appropriate units— whole numbers, halves, or quarters.

4.MD.A.2: Use the four operations to solve word problems involving distances, intervals of time, liquid volumes, masses of objects, and money, including problems involving simple fractions or decimals, and problems that require expressing measurements given in a larger unit in terms of a smaller unit. Represent measurement quantities using diagrams such as number line diagrams that feature a measurement scale.

6.RP.A.3.D: Use ratio reasoning to convert measurement units; manipulate and transform units appropriately when multiplying or dividing quantities.

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)

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

 

Michigan Science Standards

3-PS2-2: Make observations and/or measurements of an object’s motion to provide evidence that a pattern can be used to predict future motion.

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

 

Michigan Math Standards

3.MD.4: Generate measurement data by measuring lengths using rulers marked with halves and fourths of an inch. Show the data by making a line plot, where the horizontal scale is marked off in appropriate units— whole numbers, halves, or quarters.

4.MD.2: Use the four operations to solve word problems involving distances, intervals of time, liquid volumes, masses of objects, and money, including problems involving simple fractions or decimals, and problems that require expressing measurements given in a larger unit in terms of a smaller unit. Represent measurement quantities using diagrams such as number line diagrams that feature a measurement scale.

6.RP.3d: Use ratio reasoning to convert measurement units; manipulate and transform units appropriately when multiplying or dividing quantities.

 

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 will develop programs with sequences and simple loops, to express ideas or address a problem. They will graph, compare, and predict proportional relationships while interpreting the unit rate as the slope of graphs.

PARTS

Raspberry Pi Pico, breadboard, charging cable, the Range Finder

GPIO SETUP

Red - VCC - 3.3V - Power, Black - GND - Ground, Yellow - DATA - GP22, Green - NC (No Connection) - Does not need to be connected

OVERVIEW OF STEPS

Step 1: Ultrasonic Range Finder

You’re going to need an Ultrasonic Range Finder 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 Ultrasonic Range Finder sensor, let’s get started!

Let’s pretend you’re a dolphin for a second. Go ahead, make your best dolphin face, we’ll wait. So the way dolphins orient themselves is through a process called echolocation, where they let out a series of clicks which reflect off of objects around them. Dolphins then sense the sound waves coming back and can figure out where objects are in space — which is exactly what our range finder does as well!

Step 2: Connect the sensor

Let’s start by connecting up our Ultrasonic Range Finder. Remember, the DIGITAL VIEW is a handy dandy way to see the GPIO pin locations. Here’s what each of those wires on the sensor connect to:

Red - VCC - 3.3V - Power
Black - GND - Ground
Yellow - DATA - GP22
Green - NC (No Connection) - Does not need to be connected

Step 3: Get it started

So let’s go back to pretending we’re a bionic dolphin and use our echolocation to detect where objects are in space around us!

To do this, we’re basically going to want to print out the distance measured by the sensor, right?

So let’s grab a start block and drag it to your programming space. Then find the print block under Chip menu and drag it to the start block.

Step 4: Sensing

Cool, so we know to print something but what do we want to be printed? Let’s tell the program to print the input from the Ultrasonic Range Finder!

We want to read the sensor more than once, so start with a repeat forever block from the Loops menu and connect it to the start block.

Find the range finder block under Sensing menu and drag into the print block as shown. When you place the range finder block where the "_" block is, the "_" block will be displaced. That’s fine, go ahead and put the "_" block in the trash can.

Now change the pin input to the GPIO pin that we connected the yellow wire to: GP22.

Click NEXT.

Step 5: Try it out!

Go ahead and test the program by clicking CONNECT and then clicking START.

Check out the CONSOLE tab at the bottom of the workspace. Do you see the readings change as you move your hand in front of the sensor?

After you've experimented with the distance sensor, click STOP and then click NEXT.

Step 6: Add logic

Now that we have a sensor that measures how close objects are, let’s use it to create a Security Zone!

Basically, if an object comes within the range of our Ultrasonic Range Finder, let’s set off an alarm. So how do we do that? Well, we want to set up a conditional statement, with an alarm set off if an object is detected. We can do this using an if _ do block under the Logic menu. Go ahead and drag one of those into the repeat forever block. Use the one with the inequality already in it:

Click NEXT.

Step 7: Set the conditions

Let’s think about what we want the code to do! Basically, if there is an object within a certain range, we want the program to do something (set off an alarm) or we want it to stay silent, right? And we don’t want that test to just happen once right, we want to test repeatedly?

So let’s set up the if statement to test if there is an object within a certain range. Duplicate the range finder block and drag the new one to the left side of the _ = _ block. Then set the inequality to ≤ (less than or equal to).

Drag a number value block from the Values menu to the left side of the _ = _ block. Change the value from 0 to 50.

Finally, change the wait time of the repeat forever block to 1 second:

Click NEXT.

Step 8: Finish your program

Okay cool, so we’ve set up the test, but what do we want to happen if the answer to the question "is there something within 50 cm of the sensor?" is TRUE?

Let’s set off an alarm!

There are many different sounds you could play in your program if the condition is met. Do you want a loud alarm to wake you up? Or a funny sound to make you laugh?

Whichever it is, drag a play sounds block from the Sounds menu and place it in the do statement in the if block. Then, pick which sound you want the program to play! You can find lots of different sounds in the Sounds menu.

You may change the sounds at any time by changing the blocks in your program:

Ready to try it? Click NEXT.

Step 9: Make some noise!

Okay drumroll please... Let’s click that START button to test your alarm.

Position the sensor and move your hand towards and then away from the sensor. Check the CONSOLE. Do you see the measurements printing?

Check the PYTHON tab. Do you see any text that looks like what the blocks you dragged and dropped above?

If you don't hear any sounds - check your computer's volume. The sound blocks actually send a command back to your computer that tells it to play a sound!

Click NEXT.

Step 10: Graph it

Let's try using the DATA tab to visualize the output from the sensor.

Replace the print block in your program with a graph number block from the Actions menu:

Click on the DATA tab at the bottom of the workspace to open it, and click START to run your program again.

What is the graph showing you?

Click STOP and then click NEXT when you've figured it out!

Step 11: Test code and view data

Maybe you want your Security Zone to be a little narrower or a little wider. Let’s adjust the Ultrasonic Range Finder distance based on your preference!

How close can someone come to your sensor without tripping the alarm? How would the alarm change if you used units of inches?

Try it, and when you're finished, click NEXT.

Step 12: Self-driving cars

Whew, setting up security systems is hard work! But hey, that’s not the only place sensors like these are used—in fact, self-driving cars actually use sensors like these to make sure they’re not running into things while on the road!

Can you think of any other places where you might use a range finder like this?

Click NEXT.

Step 13: Congratulations!

Congratulations, you built your own Security Zone! Click EXIT to go back to the start screen and try out more projects and tutorials!