Lesson 8 House Security: Motion Sensor Alarm
Challenges: 8-1, 8-2
Students will program with a PIR sensor to create a security alarm system that uses variables to store and modify data.
I can create variables and store numbers inside them.
I can adjust variable values to create a counting function.
I can use variables as mode switches to control program behavior.
Engage
5 min.
If someone walks by your door several times, could the system tell the difference between passing by and lingering?

Introduce the core idea: use variables to record doorway activity and switch security modes.
Background
5 min.
What is a variable?
A variable is like a named box that can store a number or text. In Mind+, we can create variables by clicking the Make a Numeric Variable button (only use the numeric variable in this lesson).

The set variable to 0 block assigns a new value to a variable.

The change variable by 1 block increases the value in the variable by the amount you want.

NOTE: Make sure students create a variable with a clear name that is helpful for the program’s readability.

Build and Connect
5 min.
![]() | No extra structures are required; students only need a housing block to install hardware. |
After groups finish installation, prompt discussion:
Where should you place the PIR sensor to best detect doorway activity?
Prompt students to install the PIR sensor depending on the discussion.
Program
25 min.
Challenge 8-1: Entrance Monitoring System
![]() | Groups should open the Coding page in Mind+ , connect their hardware (PIR sensor to pin P0 , LED Strip to P1 ). |
![]() | Guide them to create a variable called count and set it to 0. Explain that this variable is for track ing each PIR detection . |
![]() | Ask students to use a change variable by 1 block to count how many times the PIR detects motion. Challenge students to s how the count on the screen so they can watch it climb in real time. |
![]() | Ask students to run the program and let them observe. Guide them to add a wait 1 sec block inside the loop to slow down the counting. |
![]() | ![]() Encourage students to add a reset button : button A sets the count back to 0. Here is a sample code: Ask : When would this be useful in a real security system? |
Challenge 8-2: Mode Switch
![]() | Guide students to create a variable called mode . Explain that this single variable switches between three security modes . |
![]() | ![]() Ask students to build two if-statements checking mode = 2 , 3 . Each mode triggers a different PIR response: mode= 1 Disarmed → no action. mode= 2 Home → Show the doorway monitoring view . mode= 3 Armed → LED flash. Here is a sample code: |
Extra Practice
5 min.
Ask students to improve the counter in Challenge 8-1. Make sure the count never goes below 1 or above 3.

Ask students to combine the counter built in Challenge 8-1 with the mode switch from Challenge 8-2, then add sound effects.

NOTE: Two variables can work together—count tracks events, mode decides when to act.
Next Class: Lesson 9
Current Tutorial: Click Here



















