Lift-Off with CodeX - Mission 10: Exploring the Surface!

Mission 10 Lesson Plan

Exploring the Surface

The crew has landed on Mars and the rover has to explore. Students build a sonar warning system on a breadboard so the rover can spot an object, measure how far away it is, and react before it gets too close.

⏱ 75-120 min 🎯 Grades 4-12+ 💻 CodeSpace 📱 CodeX 🔌 Peripherals Kit 🐍 Python
View Lesson Outline
📋

Overview

A new journey begins. After landing on Mars, the crew has a new job ahead of them, exploring the surface. But if the CodeX, which is standing in for the rover, is damaged, the peripherals students have been using so far may not work.

This project moves off the peripheral ports and onto a breadboard. Students wire an ultrasonic sensor and two LEDs with resistors, use sonar to detect an object, convert the echo time into a distance in centimeters, and build a warning system that keeps the rover away from anything harmful.

🎯 Mission Goal: Students write code to simulate a warning system for a rover.

🎯

Learning Targets

  • I can connect a breadboard to the CodeX.
  • I can connect external peripherals to the breadboard.
  • I can use sonar to detect an object.
  • I can convert sensor time data to a distance in centimeters.
  • I can create a warning system for the rover.
💡

Key Concepts

  • The types of components that can connect to the CodeX are greatly expanded with a breadboard.
  • A sonar can detect an object and how far away it is.
  • A well-known formula for distance is used to calculate how far away an object is.
  • The CodeX timer can be used in several types of applications.

Assessment Opportunities

  • Check for Understanding in CodeSpace (2)
  • Mission 10 Assignment
  • Write instructions, or draw a diagram, for connecting a sensor on a breadboard
  • Explain how sonar works
  • Exit ticket - write pseudocode for setting up an alarm system using an if/elif/else statement
  • Submit and/or check the ExploreSurface program
  • Journal entry on their learning experience
☑️

Success Criteria

  • Connect the breadboard to the CodeX.
  • Use jumper wires for the sensor's power, ground, and input/output.
  • Interpret data from the sonar sensor by calculating the distance to an object.
  • Create two simple circuits using an LED and resistor.
  • Create a warning system for the rover based on the distance to a harmful object.
  • Add a function to "power down" the rover.
🧰

Classroom Materials

  • Laptop/computer with the Chrome browser
  • CodeX and connecting cable
  • Metric ruler to measure centimeters
  • Small objects to place in front of the CodeX
  • Breadboard and jumper wires
  • 2 LEDs (amber and red) and 2 resistors
  • Ultrasonic sensor
Lift-Off Mission 10 hardware: the CodeX breadboard adapter board with a mini breadboard, an HC-SR04 ultrasonic sensor, two LEDs, two resistors, and a bundle of jumper wires
🌍

Real-World Applications

🚗Cars use ultrasonic sensors to help drivers park and to detect obstacles nearby.
🚢Ships and other watercraft use sonar to measure depth and find objects on the sea bed.
🏭Anti-collision detection, people detection, box sorting, and bottle counting on drink filling machines all run on ultrasonic sensors.
🔔Warning systems are everywhere. Have students discuss the ones in their own lives, low-battery warnings, home alarms, car alerts, and talk about what data each one uses.
🔎Have students research smart objects that use ultrasonic sensors as embedded technology.
🚀

Extensions & Cross-Curricular

ChallengeAdd more features to the "power down" function, like a beep or a song.
ChallengeUse additional CodeX features to enhance the warning system, such as the NeoPixels.
ChallengeUse LEDs and NeoPixels to simulate the Martian surface. Different colors can represent different terrain, green for safe paths and red for boulders.
ChallengeAdd other CodeX sensors, like temperature or sound, and feed their data into the warning system for too hot, too cold, or an explosion.
ChallengeUse the CodeX ambient light sensor to show how light levels change on Mars during a dust storm or at different times of day, then discuss the effect on the rover's solar panels.
ChallengeAdd the 360 servo to simulate the wheels. Run full speed when nothing is detected and slower for a warning, then program a back-up-and-turn sequence for an alert.
MathUse the formula D = R x T to make predictions. Pick a distance, predict the signal time, then check the prediction with the sonar sensor.
MathUse the project to introduce D = R x T, then apply the formula to other rates like the speed of a car or a train. Compare the results and graph them.
PhysicsStudy the science behind the ultrasonic sensor and sonar.
ScienceInvestigate the speed of sound in different mediums, like water, an electric circuit, or through a pillow.
ScienceThink about braking distance and friction. How far out must the rover start braking to avoid a collision? Use the calculation to pick a safe alert distance.
BiologyExplore how bats and other animals use sonar to navigate.
Lang ArtsStudents write a short story about a rover or an autonomous robot.
Social StudiesResearch when sonar was invented and the ways people have used it. What did people use for navigation before sonar?
🔤

Vocabulary

Breadboard - A plastic board with tiny holes for inserting electronic components to build a circuit.
Sonar - Short for "sound navigation and ranging", a method of detecting and locating objects using reflected sound waves.
Ultrasonic Sensor - A peripheral that uses sonar to detect an object and the distance to it.
Terminal Strip - A column of tiny holes on a breadboard that are electrically connected together.
Jumper Wires - Wires with connector pins at each end, used for connecting items on a breadboard.
Resistors - Electronic components that limit the amount of current passing through them. They are used with other peripherals to keep them from being damaged.
🐍

New Python Code

import pulseioImport the pulse in/out library so the ultrasonic sensor's echo pin can receive a sound wave (pulse).
pulseio.PulseIn(exp.GPIO0)Set up an input peripheral that receives a pulse.
trigger.valueSet it True to turn on, and False to turn off, the sonar's digital trigger.
echo.clear()Clear the echo so it is ready to receive a newly transmitted signal.
echo[0]The return value of the echo, which is the transmission and receiving time in microseconds.
return -1Breaks a loop and returns a value the peripheral would not normally give, useful when the loop condition may not be met, like a timeout.
display.show(pics.HAPPY)Displays a pre-defined bitmap image on the CodeX LCD.
📐

Standards

CSTA Standards - Grades 6-8

2-CS-02 2-CS-03 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-19

CSTA Standards - Grades 9-10

3A-CS-03 3A-DA-11 3A-DA-12 3A-AP-13 3A-AP-15 3A-AP-16 3A-AP-17 3A-AP-18 3A-AP-21 3A-IC-26

CSTA Standards - Grades 11-12

3B-CS-02 3B-DA-05 3B-DA-06 3B-AP-10 3B-AP-14 3B-AP-15 3B-AP-16 3B-AP-17 3B-AP-21 3B-AP-22 3B-AP-23
📝
Preparing for the Lesson
  • Students need a computer or laptop with the Chrome web browser.
  • Make sure students can successfully log in to make.firialabs.com.
  • Build the breadboard circuit yourself once ahead of time. Wiring the sensor and both LEDs before class makes it much easier to troubleshoot student rigs.
  • Gather the small objects students will use as obstacles and have metric rulers ready for measuring.

🧑‍🏫
Teacher Notes
  • The project requires a breadboard connected to the CodeX for power. Additional components are added from there. First the ultrasonic sensor, to detect an object and return the timing data. Then students use that data to calculate distance and drive the LEDs as a warning system so the rover can avoid harmful objects.
  • This is the first mission where students wire components themselves instead of plugging into a peripheral port. Expect wiring mistakes, and treat them as part of the lesson. Have students check power, ground, and signal in that order.
  • Good discussion and research questions come easily here, warning systems, sonar detection, and autonomous vehicles. This technology shows up in a huge number of real-world applications.
  • Extensions and cross-curricular projects are included to enhance the concepts in the mission. Use them to extend students' programming experience.
  • A Final Project follows Mission 10.
🗺️

Lesson Outline

🗣️Warm-up / Hook

Students access prior knowledge by answering the pre-mission questions in the assignment doc.

  • Ask: "The rover is driving across Mars with no one steering it. How does it know something is in the way?"
  • Ask: "Name a warning system you run into in daily life. What information does it use to decide when to warn you?"
Teaching tip: Clap once in a large room and ask students what they hear a moment later. The echo is exactly what the sonar sensor is listening for, and it makes the whole mission click.
📖Introduce the Mission

Front-load the hardware before any code. This mission moves off the peripheral ports and onto a breadboard for the first time.

  • Show the breadboard and explain terminal strips, the columns of holes that are wired together underneath.
  • Connect the breadboard to the CodeX for power, and point out where power and ground land.
  • Introduce jumper wires and walk through the sensor's three connections, power, ground, and input/output.
  • Explain how sonar works. The trigger sends out a sound wave, the echo pin listens for it to come back, and the sensor reports the round-trip time in microseconds.
  • Introduce import pulseio and pulseio.PulseIn(exp.GPIO0) for setting up the echo pin.
Teaching tip: Have students write instructions or sketch a diagram for wiring the sensor before they touch the breadboard. It doubles as an assessment and it slows down the students who want to plug things in first and read later.
💻Coding Time

Students work through the mission objectives in CodeSpace, taking notes and answering questions in their assignment doc as they go. There are two Checks for Understanding along the way.

  1. Connect the breadboard to the CodeX, then wire the ultrasonic sensor with jumper wires for power, ground, and input/output.
  2. Set up the trigger and echo, then read the raw timing value with echo[0]. Use echo.clear() before each new reading.
  3. Convert the echo time into a distance in centimeters using D = R x T, remembering the signal travels out and back.
  4. Add a timeout so the program does not hang when nothing is detected, using return -1 to break the loop.
  5. Build two simple LED circuits on the breadboard, amber and red, each with a resistor.
  6. Write the warning logic with if/elif/else, then add a "power down" function to finish the ExploreSurface program.
Teaching tip: Have students test their distance calculation against a metric ruler. Place an object at 20 cm, read the sensor, and compare. It turns an abstract formula into something they can check.
Teaching tip: When an LED does not light, check the resistor and the direction of the LED legs before looking at the code. Wiring is the usual culprit.
Teaching tip: Let students choose their own warning and alert distances, then defend the choice. The braking distance extension pairs nicely here.
🧑‍🤝‍🧑Class Debrief

Bring the class back together to connect the wiring, the math, and the warning logic.

  • Ask: "How does sonar measure distance when all it gets back is a time?"
  • Ask: "Why did we divide the round-trip time in half?"
  • Ask: "What should the rover do at each warning level, and who decides where those cutoffs go?"
Teaching tip: Use the exit ticket here. Students write pseudocode for an alarm system using an if/elif/else statement, which shows you fast who understands the logic apart from the hardware.
✏️Wrap-up & Review

Students answer the reflection question in the assignment doc, add a journal entry about their learning experience, and submit the ExploreSurface program.

Use the Mission 10 Review Questions or the Mission 10 Review Kahoot! through whichever method you prefer, class discussion, Kahoot!, or an LMS quiz.

Teaching tip: Mission 10 is the last mission before the Final Project. Point students toward the challenges here, several of them make strong starting points for that project.