The PIR motion sensor will detect moving persons, while the LED and buzzer will sound the alarm. There is also an option to remotely disable the alarm by pressing an on-screen button.

Step 1

Connect the PIR Motion Sensor to the CN12 connector and the buzzer to the CN11 connector on the extension module.
RP_tutorials_visual_programming_1_b
 

Step 2

The main block contains a loop repeating 10 times each second. Inside, the loop the motion sensor is checked and its status is stored into the variable status. If motion is detected the program will start executing another loop, which will sound the buzzer and blink an LED 60 times, unless in the meantime the variable status changes to false.

Alarm_VP

Step 3

The third block is a function from Program > Functions > to [] []. Functions are used to store code which is used in multiple places. In this case the function is named timestamp, since when executed, it will return a string containing the current time. If you look at the first two blocks, you will see that one prints the alarm start time, the other the alarm stop time, both use the same timestamp function to provide the time string.

Alarm_VP_2

The first two blocks are running at the same time, the first one is checking for motion, the second is checking for button presses. The variable status is used to share/pass information between them.

Step 4

Experimentation:
By using a different loop type, you could change the alarm to sound until a button on screen is pressed, without the 30 second timeout (60 repetitions each taking 0.5 seconds)