Lesson 12: Tilt Alarm with micro:bit
45 minutes
Overview
In today's skill-building lesson, the goal is to use the micro:bit's accelerometer and radio features to make an alarm that warns you when something has been moved - and learn how functions can make code more compact and easier to read and modify. Note: This project works best with two students working in pairs, each with their own micro:bit (two micro:bits per pair of students). The key concepts are: functions.
Standards
AP - Algorithms & Programming
- 1A-AP-11 - Decompose (break down) the steps needed to solve a problem into a precise sequence of instructions.
Agenda
Objectives
Students will be able to:
- Collaborate with a partner to complete the project.
- Program events on MakeCode.
- Use functions to make code more compact and easier to read and modify.
- Write code that uses micro:bit's accelerometer and radio functions.
Preparation
-
Make sure students have completed the Meet your micro:bit exploration lesson.
-
Make sure you know how to create a new classroom section where students will code their micro:bit project.
Links
Heads Up! Please make a copy of any documents you plan to share with students.
For the teachers
- CS talking points for code - Resource
- Grade 4 - Maker with micro:bit slides - Slides
- Live micro:bit classroom session - Resource
- Tilt Alarm: Finished project - Exemplar
For the students
- Tilt Alarm: Introduction Video - Video
- Tilt Alarm: Step by step coding video - Video
Vocabulary
- Function - A piece of code that you can call over and over again.
- Radio - A way to send signals over a long distance, to deliver information from one place to another.
Teaching Guide
[Optional] Pre-requisites
Sound Meter and Alarm Clock
Option 1: This activity helps students understand how physical devices use sensors to track data and solve problems. Students will create a sound meter to gauge the classroom's noise level. Each student will program their micro:bit to react to the volume in the classroom. Once the sound meters are created, you can challenge the whole class to see how long they can stay quiet enough to get all the smiley faces to show up.
Find the code for the Sound Meter project here.
Find the student handout for the Sound Meter project here.
Option 2: This could also be an opportunity to have students explore the light sensor on the micro:bit and create an alarm clock that shines and plays music when the sun rises but when it is dark it turns into a night light.
Find the code for the Alarm Clock project here.
Find the student handout for the Alarm Clock project here.
Warm Up (10 minutes)
Warm Up (10 minutes)
Say: Today's aim is to use the micro:bit's accelerometer and radio features to make an alarm that warns you when something has been moved - and learn how functions can make code more compact and easier to read and modify.
[Option 1] Do this: Watch the introduction video.
[Option 2] Do this: Explore the project uploaded onto micro:bits prior to the lesson.
Discuss where these concepts are being used and where students have used them before:
- Functions: a piece of code that you can call over and over again (e.g., the alarm showing an image on the LED display and playing an audible alert is in a function because it's used twice: when the micro:bit is moved and when is receives an alert message by radio)
Do this: Share the project working in the simulator with your students and look at the code together prior to students coding the main activity.
Main Activity (30 minutes)
Student Coding (20 minutes)
Students will make the project themselves using the MakeCode editor and micro:bit simulator. Once they have tested their code in the simulator, they will download their code onto the micro:bits.
Pick one:
- Step by step coding video
- Live micro:bit classroom session
Assessment (10 minutes)
After completing the lesson, assess students' knowledge of the concepts covered by going through the assessment slides in the slide deck. You can also assign students a content assessment hosted on the JuiceMind platform. To assign the assessment to your students, click here.
Setting up a JuiceMind assessment
Click "Assign" on the assessment page, then have students join your unique class session. Students have a link to the Join page on level 1, and will need to enter the class session code. After students complete the assessment, you can view their results on the JuiceMind teacher dashboard.
Note: You will need to sign up for an account on JuiceMind to assign the assessment.
Wrap Up (5 minutes)
Discussion (5 minutes)
Share student work, revisit key concepts used, and explore ideas for extended learning.
[Optional] Extended learning
Change the alert: Edit the function to change the alert - for example, you could use animations, scrolling text, or different sounds.
Radio distance: Test how far away you can get before the radio messages stop working.
Split the code: Split the code into two different programs - one just to send a radio signal when shaken which can be kept in the object you want to keep safe, and another that just receives messages and alerts you.
Find this project and more on microbit.org
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.