DFROBOT Motion Sensor Alarm

Specifications
- Hardware connections (Challenge 8-1): PIR sensor to pin P0, LED Strip to pin P1
- Variable types: Use numeric variables only in this lesson
- PIR behavior (for counting logic): PIR outputs HIGH for 2 to 3 seconds
- Mode options (Challenge 8-2): mode = 1 Disarmed, mode = 2 Home, mode = 3 Armed
- Expected mode actions: Home mode activates the camera view for 5 seconds when people pass by the door; Armed mode flashes warning lights (LED)
Quick Guide
- Open the Coding page in Mind+ and connect hardware: PIR → P0, LED Strip → P1.
- Challenge 8-1 (counting): Create a numeric variable named count, set it to 0, then add a block to change count by 1 when the PIR detects motion. Show the count on the screen.
- Run the program; if the count jumps rapidly, add a wait 1 sec inside the loop to slow counting.
- Set Button A to reset: when pressed, set count back to 0.
- Challenge 8-2 (mode switching): Load program 8-2 and create a numeric variable named mode. Start with mode = 1.
- In a forever loop, add conditional logic so each mode performs its action: mode=1 do nothing; mode=2 shows doorway monitoring; mode=3 flashes warning lights.
- Use Button A and Button B to change mode (decrease/increase) during operation.
INTRODUCTION
Students will program with a PIR sensor to create a security alarm system that uses variables to store and modify data.
- can create variables and store numbers inside them.
- can adjust variable values to create a counting function.
- can use variables as mode switches to control program behavior.
Engage
5 min.
If someone walks by your door several times, could thesystemtell 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.

Build and Connect
5 min.

No extra structures arerequired;students only needahousingblock 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 opentheCodingpage in Mind+, connect theirhardware (PIR sensor topinP0,LED Strip to P1).

- Guide them to create a variable called count and set it to0. Explain that this variable is for tracking 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 show 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 themto addawait 1secblock inside the looptoslow



Extra Practice
5 min.
Ask students to improve the counter in Challenge
Make sure the count never goes below 1 or above 3.
Ask students to combine the counter built in Challenge8-1withthe mode switch from Challenge 8-2, then add soundeffects.
NOTE: Two variables can work together—count tracks events, mode decides when to act.
Troubleshooting
- The count jumps rapidly instead of increasing once per pass: The PIR sensor outputs HIGH for 2 to 3 seconds, so the program can increment multiple times during that period. Add a wait 1 sec block inside the loop to slow counting.
- Mode values go out of the intended range: Ensure mode stays within valid bounds (the lesson practice suggests preventing mode from going below 1 or above 3).
- The system doesn’t appear to respond in a specific mode: Confirm your conditional checks match the lesson logic: mode = 1 (disarmed) → no action, mode = 2 (home) → doorway monitoring for 5 seconds, mode = 3 (armed) → LED warning/flash.
Documents / Resources
![]() | Motion Sensor Alarm |
References
- User Manualmanual.tools

