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

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

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.

CCSS Math

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.

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

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

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.

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

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.

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

TEKS Science Grade 3

(a) Introduction.

  (1) In Grade 3, students learn that the study of science uses appropriate tools and safe practices in planning and implementing investigations, asking and answering questions, collecting data by observing and measuring, and using models to support scientific inquiry about the natural world.

    (A) Within the physical environment, students recognize that patterns, relationships, and cycles exist in matter. Students will investigate the physical properties of matter and will learn that changes occur. They explore mixtures and investigate light, sound, and thermal energy in everyday life. Students manipulate objects by pushing and pulling to demonstrate changes in motion and position.

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

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

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

Math Texas Essential Knowledge & Skills

TEKS Math Grade 2

(b)(9) (D) determine the length of an object to the nearest marked unit using rulers, yardsticks, meter sticks, or measuring tapes;

TEKS Math Grade 4

(b)(8) Geometry and measurement. The student applies mathematical process standards to select appropriate customary and metric units, strategies, and tools to solve problems involving measurement. The student is expected to:

  (C) solve problems that deal with measurements of length, intervals of time, liquid volumes, mass, and money using addition, subtraction, multiplication, or division as appropriate.

TEKS Math Grade 5

(b)(7) Geometry and measurement. The student applies mathematical process standards to select appropriate units, strategies, and tools to solve problems involving measurement. The student is expected to solve problems by calculating conversions within a measurement system, customary or metric.

TEKS Math Grades 6 & 7

(4) Proportionality. The student applies mathematical process standards to develop an understanding of proportional relationships in problem situations. The student is expected to:

  (H) convert units within a measurement system, including the use of proportions and unit rates.

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

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

TEKS ELA 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 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!

Security Zone

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

Security Zone

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.

Security Zone

Step 4: Sensing

Security Zone

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!

Security Zone

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.

Security Zone

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.

Security Zone

Step 8: Finish your program

Security Zone

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.

Security Zone

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!

Security Zone

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.

Security Zone

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!