5. Case 02: Security Vanguard Alarm System

Level: level auto_fit

5.1. Goal


Make an automatic home vanguard by detecting the motion around the home.

5.2. Background


What is a Security Vanguard Alarm System?

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.

pic_90

5.3. Part List


pic_90

5.4. Assembly step


Step 1

To start with, build the Big House Model.

auto_fit

Step 2

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

auto_fit

Step 3

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

auto_fit

Step 4

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

auto_fit

Step 5

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

auto_fit

Step 6

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

auto_fit

Step 7

Completed.

auto_fit

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.

auto_fit

Step 9

Assembly Completed!

auto_fit

5.5. Hardware connect


  1. Connect the Motion sensor to P2

  2. Connect Distance Sensor to P14,P15

  3. Pull down the buzzer switch to connect buzzer

pic_90

5.6. Programming (MakeCode)


Step 1. Create and save the reading to variable

  • 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 auto_fit

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)] pic_90

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 pic_90

Full Solution

MakeCode: https://makecode.microbit.org/_cc21MTdEuhMv

You could also download the program from the following website:

5.7. Result


When someone is get close to the door, either distance sensor or motion sensor will detect it and warn alert to house owner. auto_fit

5.8. Think


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)

Q2. Are other positions able to place the motion sensor to get the defend effect? (e.g in the living room)