# Case 02: Security Vanguard Alarm System Level:  
## Goal
## Background
Security vanguard alarm system is a smart defense system that triggers an alert automatically when detecting an unexpected visit. It is good to have security system to prevent from the theft coming in.
Vanguard Alarm System Principle
Motion sensor and distance sensor is implemented over the house and monitor the surrounding environment to check if there are visitors. If there are moving objects nearby, the sensors will reflect data to the system and trigger the buzzer with master icon shown on the micro:bit, until the objects move away.

## Part List
## Assembly step
To start with, build the Big House Model.

Step 2
For extra room installation, Insert the model D1, D3 on model B1, align with the holes on model A.

Step 3
Attach the distance sensor to the Model D3 using M4 * 10mm screws and nuts.

Step 4
Put the model D2 on the holes of model A, and then insert it to model D1 and D3.

Step 5
Add the 4 rubber bends to the model D2 so that the house will not loose.

Step 6
Insert the model D4 to the model B1, and then attach it to the model D1, D2 and D3.

Step 7
Completed.

Step 8
Attach motion sensor to the model B1 (near the door) using M4 * 10mm screws and nuts. And the connecting wire should be bended to the hole above it.

Step 9
Assembly Completed!

## Hardware connect
## Programming (MakeCode)
* Create two variable `distance` and `motion` * In `Forever`, use (set distance to `Get distance unit cm trig P14 echo P15`) to save the reading of distance to variable `distance` * Use (set motion to `Get motion (triggered or not) at Pin P2`) to save the result of motion detection to variable 
Step 2. Examine the reading
* Snap `if-else` into `Forever` after saving reading to variables. * To check both distance and motion result, the condition should include two comparison and one extra logic operators * set the condition as [(`motion = true`) or (`distance < 10`)] 
Step 3. Defend!
* In the `if` segment, means someone passing infront the door, show a angry icon by `show icon` * Also play a warning sound to expel the suspicious by `play melody at tempo 120 (bpm)` * In the `else` segment, no one is stay around home, no need to show the angry face, use `show leds` to clear up. * Add a 1 second interval `pause (ms) 1000` for the security system running in 1 second sampling rate 
Full Solution
MakeCode: [https://makecode.microbit.org/S67345-63455-14407-18164](https://makecode.microbit.org/S67345-63455-14407-18164)
You could also download the program from the following website:
## Think
Q2. Are other positions able to place the motion sensor to get the defend effect? (e.g in the living room)
## Result
When someone is get close to the door, either distance sensor or motion sensor will detect it and warn alert to house owner.

Q1.Except simply triggering the alarm system, what else do you think a smart vanguard system should have? (e.g. send notification/ call the police)