Message Boards Message Boards

Make a home alarm system with a Raspberry Pi and a PIR Motion Sensor

This example shows how to use a PIR movement detector with a Raspberry Pi and to have the GPIO communicate with the Wolfram Language to speak, capture an image, and send it via email whenever movement is detected by the sensor.

To recreate this example you will need the following hardware (in addition to the Raspberry Pi itself):Although the PIR, “Passive Infra Red” sensor, requires a 5V supply, its output is a Pi-friendly 3.3V, so it can be connected directly to a GPIO input, I've choosen pin number 18. Set up everything as it's shown in the image below, adjust PIR's delay before firing (approx 2-4 seconds) and its sensitivity exaclty as I've done (check that the orange trimming controls are in the same position):

Once you set up everything you are ready to use the GPIO with the Wolfram Language on your Raspberry Pi.

Configure pin 18 for reading, it will return 1 if a movement is detected, 0 otherwise:


You can check that the sensor works properly as follows:

Dynamic[If[DeviceRead["GPIO",18]=={18->1}, Speak["Smile!"]]; UpdateInterval -> 3]

Notice that the Raspberry Pi needs a speaker connected to its 3.5mm jack.

Now you can finally email an image of the intruder using the RaspiCam and the following piece of code:

Dynamic[If[DeviceRead["GPIO",18]=={18->1}, Speak["Smile!"]SendMail["To" -> "", "Subject" -> "Intruder", "Body" -> {"Intruder's Portrait\n", DeviceRead["RaspiCam"]},"From" -> "", "Server" -> "", "UserName" -> "", "Password" -> "yourPassword", "PortNumber" -> 587, "EncryptionProtocol" -> "StartTLS"]]; UpdateInterval -> 3]

3 years ago

Group Abstract Group Abstract