Add extra code to your Python program to trigger an alarm sound when motion is detected.
Make sure you have the alarm.wav file on your Raspberry Pi desktop.
Add this code above the first line of your program:import os
Add one more line at the end of your code so it looks like this:
import os
from gpizero import MotionSensor
pir = MotionSensor(4)
while True:
if pir.motion_detected:
print("Motion detected!")
os.system('sudo aplay /home/pi/Desktop/alarm.wav')
Now your Raspberry Pi will sound an alarm if motion is detected.
Remember you can press 'Ctrl+F6' to exit and stop the alarm.
Test your Raspberry Pi alarm in different parts of the room.
Try and work out how sensitive your PIR sensor is and where it works best.