< Creating Apps with Devices (micro:bit) ('23-'24)

Lesson 12: Accelerometer

45 minutes

Overview

In this lesson, students will explore the accelerometer and its capabilities. They’ll become familiar with its events and properties, as well as create multiple programs utilizing the accelerometer similar to those they’ve likely come across in real world applications.

Question of the Day: How can I use the accelerometer to create apps?

CSTA K-12 Computer Science Standards (2017)
    • 2-AP-11 - Create clearly named variables that represent different data types and perform operations on their values.
    • 2-AP-13 - Decompose problems and subproblems into parts to facilitate the design, implementation, and review of programs.
    • 2-AP-17 - Systematically test and refine programs using a range of test cases.
    • 2-AP-19 - Document programs in order to make them easier to follow, test, and debug.
    • 2-CS-01 - Recommend improvements to the design of computing devices, based on an analysis of how users interact with the devices.
    • 2-CS-02 - Design projects that combine hardware and software components to collect and exchange data.
    • 2-CS-03 - Systematically identify and fix problems with computing devices and their components.

Agenda

Objectives

Students will be able to:
  • Use accelerometer orientation (pitch and roll) when creating apps
  • Use the data event to continually update an element's properties.

Preparation

  • Prepare a board and USB cable for each pair of students
  • Check the "Teacher's Lounge" forum for verified teachers to find additional strategies or resources shared by fellow teachers

Links

Heads Up! Please make a copy of any documents you plan to share with students.

For the teachers
For the students

Teaching Guide

Warm Up (5 minutes)

Prompt: Have you ever tried to walk across a raised narrow platform, one foot in front of the other? How do you keep your balance and avoid falling over?

Share Out: Have students share with a partner, then share as a full group

Discussion Goal: Guide the discussion towards understanding our sense of balance - how we can detect when we’re about to fall, and the strategies we use to avoid falling (like keeping our arms out). Emphasize that, in some ways, our “sense of balance” is like another one of our senses, similar to the discussion yesterday

Remarks

Humans can detect when we’re off-balance, and we can make adjustments to stay balanced. Our micro:bit can also detect when it’s off balance and tilted, so that it can try and correct itself. It uses a sensor called an accelerometer to detect its position and keep track of how tilted or off-balance it is. Other devices, like automated drones or robotic vacuums, use an accelerometer to level themselves so they can move automatically without falling over.

Activity (35 minutes)

Transition: Send students to Code Studio.

Teaching Tip

Guide to Programming Levels: Additional guidance for programming levels is provided in the Guide to Programming Levels. This document includes strategies and best-practices for facilitating programming levels with students.

Troubleshooting Devices: If student devices aren't able to connect, they can click the Help and Tips tab and then access the Maker Setup page (click the image to see more). This will let them re-reconnect their board to App Lab.

If students continue to have issues, refer to the Troubleshooting section of our Maker Support Article

Discussion Goal: The accelerometer has two properties: the roll and pitch. The roll corresponds to tilting left and right, and pitch corresponds to tilting forwards and backwards. Students should notice this if they're holding their micro:bit level to the ground with the USB cable pointing away from them so all the lettering appears correctly. Students may also experiment with moving their miocro:bit in the physical space - moving it up and down or left and right - but this doesn't affect the accelerometer. Only rotating and tilting the micro:bit will change the roll and pitch.

Assessment Opportunity

Formative Assessment: This level can be used as a formative assessment. A rubric is provided in the level, and written feedback can be given to students. Click here to learn more about giving feedback to students.

Wrap Up (5 minutes)

Journal

Prompt: What are some uses for pitch and roll in an everyday app?

Discussion Goal: Students should think of several applications for the accelerometer, explaining how knowing the pitch and roll could be useful. Their responses may be similar to the examples in the warm-up, like autonomous vehicles, but encourage students to think beyond those uses.

Creative Commons License (CC BY-NC-SA 4.0).

This work is available under a Creative Commons License (CC BY-NC-SA 4.0).

If you are interested in licensing Code.org materials for commercial purposes contact us.