MicroPython 101

A project-based introduction to micro:bit programming using MicroPython with instructions to build 16 hands-on micro:bit projects. Request Quote

  • Grades 6 - 8
  • 14 lessons
    • Web
  • Python
  • Advanced Course
Course includes
  • 14 lessons
  • 86 activities
  • Enhanced Creativity Tools
  • Automatic Assessment
  • Tutorials and Reviews
  • Coding Puzzles
  • DIY Projects
  • Quizzes
  • Teacher Guides
  • Answer Keys
Prerequisites
No previous coding experience required.

MicroPython 101 Lesson Plan

Lesson: Temperature Search
Time: 45+ mins

Introduction

In this lesson, students will learn how to program their micro:bit to display temperature. Additionally, they'll learn how to create their own temperature game as they're introduced to new functions, such as random.randint() and temperature(). Note: If your students have a battery pack, it is recommended that they use it for this lesson.

New Code

  • random.randint() : Chooses a temperature at random.
  • temperature() : Returns the temperature value (defaults to degrees Celsius).

Vocabulary

  • Random: When all possible choices have an equal chance of being selected

Objectives

Students will...

  • Use the micro:bit to run coding examples
  • Apply coding concepts to solve challenge activities
  • Create a temperature game using the micro:bit

Materials

  • micro:bit device (recommended 1 per student)
  • USB cable
  • Computers, laptops, or Chromebooks (1 per student) with student account access to Tynker.com
  • Optional: Battery pack

Warm-Up (5 minutes)

  • Explain to students that in today's coding activity, they'll learn how to create their own temperature game using their micro:bit! Ask students, "What does it mean to detect the temperature of something?" (Answer: To see how hot or cold something is, usually given in degrees Fahrenheit or Celsius.) Does anyone remember the formula to convert degrees Celsius to Fahrenheit? (Answer: Temperature Fahrenheit = Temperature Celsius x 9/5 + 32.)

Activities (45 minutes)

Facilitate as students complete all Temperature Search modules on their own:
1. Temperature Search (Document)

  • Students will read a short document that introduces the chapter. They'll learn that today's coding activities include programming their micro:bit to work as a thermometer. Additionally, students will need to explore different areas in search of a target temperature once they finish the coding activities.

2. Thermometer (DIY)

  • In this module, students will learn how to program the micro:bit to detect temperature.
  • Students are introduced to the temperature() function, which returns the temperature in degrees Celsius.
  • Coding Challenge, Step 1: Measuring the Temperature
    • To solve this challenge, students need to program their micro:bit to detect temperature.
    • Give a hint: Tell students to use a display.scroll() function.
    • Optional: Ask your students to compare their results with each other. Are there any outliers?
    • If students finish early, ask them to try the optional activity, which encourages them to change the temperature from Celsius to Fahrenheit.

3. Choosing a Random Temperature (DIY)

  • In this module, students will learn how to create a temperature game using the random.randint() function.
  • Tell students that the random.randint() function will randomly choose a temperature.
  • Coding Challenge, Step 2: Choosing a Random Temperature
    • To solve this challenge, students will need to program their micro:bit to display a random temperature from 10 to 28 degrees Celsius (50 to 83 degrees Fahrenheit).
    • Give a hint: Tell students that the random.randint() parameter needs to be set to the temperature range. For example, if students want their micro:bit to display the temperature in degrees Fahrenheit, their random.randint() function should look similar to this:

    • Tell students that they'll expand on this project in the next module.

4. Am I Getting Warmer?(DIY)

  • Students will expand on their project by programming their micro:bit to check if the temperature near the user matches the micro:bit's goal temperature.
  • Point out to students that the brightness of the LEDs indicates how close students are to reaching the micro:bit's goal temperature. The brighter the LEDs, the closer the students are to reaching the micro:bit's goal temperature.
  • Make sure students analyze "Example 1," which includes code to compare different temperatures.
  • Coding Challenge, Step 3: Checking Real Temperature with Goal Temperature
    • To solve this challenge, students need to program their micro:bit to compare the real temperature to the goal temperature.
    • Make sure students are reading the criteria carefully.
    • Give a hint: Tell students to use display different-sized dots using strings. Remind them that the string's digits need to range from 0-9, where a 9 is the maximum brightness. Each row needs to be separated by a colon (:).
    • Tell students that they'll finish coding their game in the next module.

5. Finishing Touches (DIY)

  • In this module, students will finish programming their temperature game. They'll need to program their micro:bit to display the word "win" (or an animation) to let the user know they reached the goal temperature.
  • Coding Challenge, Step 4: Turning It All Into a Game
    • To solve this challenge, students need to add the following to their temperature game program:
      • Type the word "break" to exit out of the loop.
      • Use the display.scroll() function to display text that says, "Win!"

6. Playing the Game (DIY)

  • This page instructs students to experiment with their code as they test and debug their temperature game program.
  • If students finish early, ask them to try the bonus tasks or create their own rules for the temperature game. They can even adjust the temperature range!
  • Optional: Ask students to bring their micro:bits and, as a class, take a short trip to the school courtyard or football field (somewhere away from cars). Next, ask students to test their micro:bit. If it's a sunny day, the temperature should rise. If it's cloudy, chilly, or cold outside, observe how the temperature outside compares to the temperature inside the classroom.

7. Review

  • This module reviews the following:
    • The temperature() function allows the user to get information from the micro:bit's temperature sensor.
    • The abs() function can be used to compare the "distance" to the target value.
    • To escape from a forever loop, use the break keyword.
    • The random.randint(start, end) function allows the user to include unpredictability in games or projects.

8. Quiz (Multiple-choice)

  • Students will be asked 5 quiz questions to review concepts from this lesson.

Extended Activities (10 minutes)

Lead a discussion with your students:

  • Did anyone create their own temperature game rules?
  • Do you prefer to use degrees Celsius or Fahrenheit? Why?

U.S. Standards

  • CCSS-Math:MP.1
  • CCSS-ELA: 6-8.RST.3, 6-8.RST.4, 6-8.RST.7
  • CSTA: 2-AP-11, 2-AP-13, 2-AP-15, 2-AP-17
  • CS CA: 6-8.AP.11, 6-8.AP.13, 6-8.AP.15, 6-8.AP.16, 6-8.AP.17
  • ISTE: 1.c, 1.d, 4.d, 5.c, 5.d, 6.b

U.K. Standards

Key Stage 2 (Years 4-6)

  • Design, write and debug programs that accomplish specific goals, including controlling or simulating physical systems; solve problems by decomposing them into smaller parts.
  • Use logical reasoning to explain how some simple algorithms work and to detect and correct errors in algorithms and programs.
  • Understand computer networks, including the internet; how they can provide multiple services, such as the World Wide Web, and the opportunities they offer for communication and collaboration.
  • Use technology safely, respectfully and responsibly; recognise acceptable/unacceptable behaviour; identify a range of ways to report concerns about content and contact.

Key Stage 3 (Years 7-9)

  • Understand several key algorithms that reflect computational thinking [for example, ones for sorting and searching]; use logical reasoning to compare the utility of alternative algorithms for the same problem.
  • Create, re-use, revise and re-purpose digital artefacts for a given audience, with attention to trustworthiness, design and usability.
  • Understand a range of ways to use technology safely, respectfully, responsibly and securely, including protecting their online identity and privacy; recognise inappropriate content, contact and conduct and know how to report concerns.