3.20 Intrusion Alarm
3.20.1 Overview
Intrusion alarm is a device alerting illegal intrusion into a prevention area. It plays an important role in security. We can see it everywhere: families, stores, warehouses, supermarkets and so on.
All in all, it protects our personal and property safety.
3.20.2 Test Code
3.20.2.1 Code Flow

3.20.2.2 Build Code
There are two ways to upload the code: directly open the code file we provide; or manually build blocks.
Directly open the code file we provide:
Click
and choose Load from your computer

We have already downloaded the codes on computer desktop, so open the file and choose
3-20-IntrusionAlarm.sb3
Manually build blocks:
Build the two basic blocks:

We use this block to determine the PIR motion sensor value. When the sensor outputs 1, the speaker alarms, the red LED turns on and the green one is off. If the sensor value equals 0, the red LED will go off and the green will be on; at the same time, the speaker stays quiet.
Complete Test Code

3.20.2.3 Test Result
After uploading code, when the sensor detects a motion around, the speaker alarms, the red LED turns on and the green one is off. If no intrusion is detected, the red LED will go off and the green will be on; at the same time, the speaker stays quiet.