Teacher Resources: Python with Robots MS Mission 7-1

Mission 7-1 Lesson Plan

Hot Pursuit Lesson 1: Proximity Sensors

Students use CodeBot's infrared proximity sensors to detect objects and experiment with power and threshold settings.

⏰ 45-50 min 🎯 Grades 6-8 πŸ’» CodeSpace πŸ₯‡ CodeBot 🐍 Python
View Lesson Outline
πŸ“‹

Overview

In this first lesson of Mission 7, students explore CodeBot's infrared (IR) proximity sensor system. They start with basic object detection using the default function, then add power and threshold parameters to adapt detection for different surfaces. Finally, students use a scanning function to find the best threshold settings for white and black surfaces - collecting and recording real data along the way.

🎯 Mission Goal: Students use proximity sensors to detect an object.

🎯

Learning Targets

  • I can use proximity sensors to detect objects.
  • I can indicate a detected object using the proximity sensor LEDs.
  • I can experiment with light and dark surfaces to find the best power and detection threshold settings for each surface.
  • I can use a pre-defined function to scan multiple settings to find the best detection threshold for a given power setting.
πŸ’‘

Key Concepts

  • CodeBot uses the Infrared Proximity Sensor system to detect objects in its path.
  • A detection threshold of 0-100% controls how much light is needed for a True detection. Decreasing the thresh value helps the 'bot work well even on a white surface.
  • An emitter power level from 1 to 8 controls the brightness of CodeBot's IR "flashlight." The prox.detect(power, thresh) and prox.range(num_scans, power) functions let students adapt to different environments.
βœ…

Assessment Opportunities

β˜‘οΈ

Success Criteria

  • Use the basic function prox.detect() to detect objects in front of the sensors.
  • Use the reading from prox.detect() to turn on/off the proximity sensor LEDs.
  • Measure the detection distance for a white surface using different power and thresh values.
  • Measure the detection distance for a black surface using different power and thresh values.
  • Use the function prox.range() to find the best threshold for detecting IR light on a white surface.
  • Use the function prox.range() to find the best threshold for detecting IR light on a black surface.
🧰

Classroom Materials

  • β–ΈCodeBot and USB cable
  • β–Έ4 AA batteries
  • β–ΈWhite paper
  • β–ΈBlack paper
  • β–ΈRuler (or print the White paper with ruler doc)
🌍

Real-World Applications

πŸͺŸTouchless faucets, soap dispensers, and hand dryers use proximity sensors to activate without contact.
πŸšͺAutomatic doors detect approaching people using IR sensors to open and close safely.
πŸš—Vehicle navigation and safety systems use proximity detection for collision avoidance and parking assist.
🏭Factory automation systems use sensors to detect objects on assembly lines and guide robotic arms.
πŸš€

Extensions & Cross-Curricular

ExtensionModify the while True loop to cycle through the power range and print the results to the console. This is a fast way to test all the powers for many different surfaces, and can be an alternative to using the console panel exclusively in Objective 3.
ScienceLearn more about IR light or proximity sensors. Research where proximity sensors are used in the real world.
MathCreate a chart from the data collected during Objective 2 or Objective 3. Use a different color for each surface.
Lang ArtsSupports reading instructions, guided notes, and reflection writing throughout the mission log.
πŸ”€

Vocabulary

β–Ύ
Proximity sensors - Infrared (IR) sensors that can detect nearby objects based on the reflected IR light.
Detection threshold - How much light is needed for a True detection. For proximity sensors, the range is 0%-100%.
Emitter power level - The brightness of CodeBot's IR flashlight, with settings from 1 (low) to 8 (high power).
🐍

New Python Code

β–Ύ
p = prox.detect() Pulses the emitter and detects reflected IR light. Returns a tuple of two bools: (left, right).
p = prox.detect(power, thresh) leds.prox(p) Proximity detection with optional parameters. power sets IR brightness (1-8). thresh sets detection sensitivity (0%-100%). leds.prox(p) turns on the LED below each sensor if an object is detected - for example, if p = (True, False), the left LED turns on and the right stays off.
sensed = prox.range(10, power) Scans multiple sensitivity levels to find the lowest detection threshold (0%-100%). Parameters: num_samples (up to 10), power. Returns the best threshold for the given power setting.
πŸ“

Standards

β–Ύ

CSTA Standards - Grades 6-8

2-DA-08 2-DA-09 2-AP-10 2-AP-11 2-AP-12 2-AP-13 2-AP-14 2-AP-16 2-AP-17 2-AP-18 2-AP-19
πŸ“
Preparing for the Lesson
  • Look through the slides. Decide what materials you want to use for presenting the lesson. The slides can be projected on a large screen.
  • Be familiar with the mission log assignment and the questions students will answer. Prepare the assignment to give through your LMS.
  • Have white and black surfaces available for each student or programming pair.
  • Have a ruler available for each student or programming pair, or print the "White paper with ruler" PDF.
  • If you have a word wall, or another form of vocabulary presentation, prepare the new terms.

πŸ§‘β€πŸ«
Teacher Notes
  • The code for Objectives 1 and 2 is the same as CodeTrek. You can use the slides or CodeTrek.
  • The code for Objective 3 is different from CodeTrek. You can type the code directly in the console panel without adding to the program. However, the last goal in the objective will not be met until you add a line of code - this is detailed in the slides.
  • Students will need a white surface and a black or very dark surface. Regular printer paper and black construction paper work well. For Obj. 2, students need to measure distance - you can put a ruler next to the surfaces, or use the PDF in the teacher resources, which has a metric ruler. Just put the black construction paper over the white paper for the second table.
  • This lesson can run long if students do a lot of testing. You can condense it and have students do less testing, stretch it slightly into the next day, or use the extension for Objective 3 instead of typing all the code in the console panel.
πŸ—ΊοΈ

Lesson Outline

πŸ’‘Lesson Tips and Tricks
Teaching tip: You can use a variety of discussion strategies to get the most engagement from your students. For example, you can have students write their answers before asking anyone for an answer. You can use one of many think-pair-share methods.
πŸ—£οΈWarm-up / Hook

Slide 2 - Students can write in their log first and then share, or discuss first and then write. These questions review line sensors and have students make a prediction for this mission.

  • Question: How does a line sensor work?
  • Question: How do you think CodeBot can "see" objects?
πŸ’»Mission 7 Lesson 1 Activities

The Chrome browser works best, but other browsers also support CodeSpace. Each student will complete a Mission Log. Students could work in pairs through the lesson, or they can work individually. There is a lot of testing in this mission, so it is a good one for pair programming.

Teaching tip: Mission Introduction - slides 3-7. This mission is divided into three lessons. The first lesson focuses on the first three objectives. Students answer three questions in their mission log. If you think you will be short on time, they can skip the questions or just answer them as a class discussion.
Teaching tip: Objective #1 - slides 8-12. These slides introduce the proximity sensors, how they work, and the function that returns a Boolean value for the left and right sensors as a tuple.
Teaching tip: Objective #1 Activity - slides 13-16. Students start a new file and copy the code from the slide or CodeTrek (they are the same). Students use a dark surface first - both LEDs should be off. They place a finger or object in front of each sensor to turn on the LED. Then they move CodeBot to a white surface - both LEDs should turn on without an object present. Students record what happens in their mission log.
Teaching tip: Objective #2 - slides 17-21. Parameters are added to prox.detect() so the programmer has more control over detection. Both parameters are explained.
Teaching tip: Objective #2 Activity - slides 22-29. Students modify their code using the slide or CodeTrek. CodeBot is placed on a white surface and run several times with different power and thresh values. Students use a ruler to measure detection distance and fill out a chart. Then they repeat on a black surface. An optional extension is to point CodeBot in the air and run the code again for various settings.
Teaching tip: Objective #3 - slides 30-39. A new function is introduced that scans multiple settings to find the best threshold for a given power. The slides give an alternative approach using the console panel directly. Results can vary widely even with the same settings - that is expected. Students repeat for both white and black surfaces. In order to meet both goals, they must use the console panel at least once and add one line of code to the program (slide 39).
Teaching tip: Extension - slides 40-41. One extension is provided for this lesson. You can use it as an alternative for Objective 3, or for students who finish early. Code is provided.

πŸ“ Optional: Mission 7 Obj. 1-3 Kahoot! Review covers all three objectives.

πŸ§‘β€πŸ€β€πŸ§‘Post-Mission Reflection

The post-mission reflection asks students to review the objectives in this lesson.

You can use a cross-curricular activity as a post-mission activity.

End by collecting the Mission 7 Lesson 1 Log.