Teacher Resources: Python with Robots MS Mission 9-2

Mission 9-2 Lesson Plan

All Systems Go! Lesson 2

Students use system sensors to monitor temperature and build a UI that displays LED alerts when readings fall outside an acceptable range.

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

Overview

In this lesson, students read system temperature data from the CodeBot using built-in sensors and use it to build a thermostat-style user interface. They learn to collect temperature samples, calculate a moving average, and define constants for a baseline and deadband. The 'bot's LEDs serve as visual alerts when the temperature is too high or too low.

🎯 Mission Goal: Students will use system sensors to monitor system temperature and display unacceptable temperatures with a LED-based UI.

🎯

Learning Targets

  • I can use system sensors to read system temperature in either Celsius or Fahrenheit.
  • I can find the average of several temperatures.
  • I can create a UI that uses LEDs to show an alert if the average temperature is too high or too low.
πŸ’‘

Key Concepts

  • The 'bot can measure its own system temperature.
  • Just like system power data, temperature data from system sensors can be used to trigger alerts. The CodeBot's LEDs can show when temperatures are out of range.
  • The system sensors can measure temperature in either Celsius or Fahrenheit.
  • The CodeBot CB2 (older model) has a more exposed CPU than the CB3, which makes it easier to test temperature changes in real time. Specific CB2 instructions appear at the end of the slide deck.
βœ…

Assessment Opportunities

β˜‘οΈ

Success Criteria

  • Read system temperature using system sensors
  • Define an empty list for temperature readings
  • Get a sum of all temperatures in the list
  • Return the average of temperatures in a list
  • Define constants for baseline and deadband
  • Turn on/off LEDs as an alert when the temperature is too high or too low
🧰

Classroom Materials

  • β–ΈCodeBot and USB cable
  • β–ΈOptional: ice pack and/or heat pack for testing (CB2 model only)
🌍

Real-World Applications

Many electronic devices use a temperature-control system - or thermostat - to avoid overheating or overcooling. Students are already using this kind of code every day:

🏠Smart thermostats, central heating and air conditioning units
🍳Ovens, refrigerators, coffee makers, and water heaters
πŸ₯Medical equipment, vehicles, and portable heating/cooling units
πŸš€

Extensions & Cross-Curricular

ExtensionFix the check_baseline() function to turn off LEDs when the condition is no longer met.
ExtensionAdd beeps to the alert system to indicate whether the temperature is too high or too low.
ExtensionAdd a function that reads temperature in Fahrenheit, and use button presses to choose which reading is executed.
ScienceHave a lesson on temperature: what affects it, and how temperature affects electronic devices.
MathThis lesson uses averages. Review the formula for calculating an average and practice with your own data.
Lang ArtsSupports language arts through reading instructions, guided notes, and reflection writing.
πŸ”€

Vocabulary

β–Ύ
Milliseconds - A millisecond is a thousandth of a second.
Ambient - Surroundings.
Append - Adding a new item to the end of a list.
Traverse - Accessing each item in a list in order.
Baseline data - Starting point used for comparison; original data.
Deadband - In a control system, the range or band of input values where the output doesn't change.
🐍

New Python Code

β–Ύ
bot_temp = system.temp_C() Measure temperature in Celsius.
bot_temp = system.temp_F() Measure temperature in Fahrenheit.
sleep_ms(200) Delay program execution for 200 milliseconds.
samples = [] Initialize an empty list.
samples.append(bot_temp) Append (add) a new item to a list.
while i < count: sum = sum + nlist[i] i = i + 1 Traverse a list using a loop to sum all the items.
return sum / count Return the average without assigning it to a variable.
samples.clear() Clear a list of all items.
BASELINE = 25.5 DEADBAND = 3.0 Define constants for the thermostat control system.
for i in range(5): A quick way to loop a block of code five times.
if t > BASELINE + DEADBAND: leds.user(0b11111111) Compare temperature for a value that is too high - above the baseline + deadband.
if t < BASELINE - DEADBAND: leds.ls(0b11111) Compare temperature for a value that is too low - below the baseline - deadband.
πŸ“

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-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.
  • Students may want to use a calculator for the Obj. 5 mission log assignment.
  • If you have a word wall, or another form of vocabulary presentation, prepare the new terms.
  • If you have the older CB2 model, have hot and cold options available that can heat/cool the CodeBot CPU. Disposable water bottles work well and won't damage the CodeBot (see slides 40-41).

πŸ§‘β€πŸ«
Teacher Notes
  • This lesson follows the instructions in CodeSpace fairly closely. It is chunked into smaller bits of information and simplified for clarity.
  • The code in this lesson is similar to CodeTrek - simplified a little for ease of typing and organized in a way similar to former missions. All goals will be met.
  • Three extensions are given for the lesson. The lesson may not take an entire class period - the first extension is recommended and includes detailed instructions.
  • The older CodeBot model (CB2) has a more accessible CPU than the CB3. At the end of the lesson, additional instructions are given for testing with the CB2. If you have CB3 models, skip those slides.
πŸ—ΊοΈ

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, or 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. The warm-up question previews the lesson.

  • Question: What do you know about temperature?
πŸ’»Mission 9 Lesson 2 Activities

The Chrome browser works best, but other browsers also support CodeSpace. Each student will complete a Mission Log. Students can work in pairs or individually.

Teaching tip: Mission Introduction - slides 3-4. This mission is divided into three lessons. This lesson completes the second goal. Students answer one question in their mission log.
Teaching tip: Objective #5 - slides 5-7. System temperature is introduced. Students learn two functions for reading temperature. The sleep_ms() function is introduced and compared to sleep().
Teaching tip: Objective #5 Activity - slides 8-11. Students write a short program and observe temperature readings in the console panel. They stop the code after a few seconds and record the last five readings, then calculate the average manually. This sets up understanding of what the computer will do automatically in the next objective.
Teaching tip: Objective #6 - slide 12. This slide discusses the need for a moving average function.
Teaching tip: Objective #6 Algorithm - slides 13-17. The moving average algorithm is broken down step by step with code shown for each step. Students can refer back as needed. Lists were introduced in Mission 6 - review as needed.
Teaching tip: Objective #6 Activity - slides 18-22. Students implement the moving average algorithm, test it, record results in the mission log, then change the list length and test again - four different list lengths total.
Teaching tip: Objective #7 - slides 23-25. Students apply system controls for temperature by creating a thermostat - a real-world application.
Teaching tip: Objective #7 Algorithm - slide 26. Algorithm for the thermostat UI.
Teaching tip: Objective #7 Activity - slides 27-30. Students implement the UI by defining two constants and a new function.
Teaching tip: Extension (mild) - slides 31-39. The program is complete and all mission goals have been met. This extension guides students through adapting the code to test all temperature ranges - they'll discover that the check_baseline() function has a bug where LEDs don't turn off, then work through the fix. Sample code for this extension is available in the learning portal.
Teaching tip: Extension (mild) for CB2 only - slides 40-41. If you have the older CB2 model, students can test real-time temperature changes using warm and cold water bottles placed near the CPU.
Teaching tip: Extensions - slides 42-43. Two additional extension ideas are given (medium and spicy). Both are optional and solutions are not provided.
Teaching tip: Post-Mission - slide 44. Applies the lesson to the real world. Optional: run the Mission 9 Obj. 5-7 Kahoot! review.
πŸ§‘β€πŸ€β€πŸ§‘Post-Mission Reflection

The post-mission reflection asks students to think about how a temperature-controlled system could be used in other CodeBot programs. Answers can vary widely.

A cross-curricular activity makes a good post-mission option.

End by collecting the Mission 9 Lesson 2 Log.