This project was made for extra credit in my measurement and instrumentation class but I also wanted it to be something that I would get some use out of. This allows me to make sure nobody has been into my apartment when I am out of town.
This code is only set up to work with Gmail addresses. If you do not have a Gmail address make one here
So let's get Started.
The first thing were going to do is wire our PIR sensor to the Rasberry Pi. On the PIR Sensor there are three pins. A VCC, OUT, and GND. Using female to female jumper cables connect the VCC to 5V, the OUT to GPIO pin4, and the GND to GND. You should also note the 2 orange phillips screw heads. These are the potentiometers that control the sensitivity (Sx) and timing (Tx). You will want the sensitivity on max (max clockwise) and the time on minimum (minimum clockwise). This will be the baseline and can be tuned later to your preference.
Boot your Raspberry PI like normal.
Open up the terminal and create a new file called pirsensor.py by typing:
>> nano pirsensor.py
Enter/ Copy the code into the file.
Edit the to_email_address, from_email_address, and to_email_password to correspond with your desired emails.
Grant you Gmail permission to use less secure apps by following the instructions here.
Press ctrl+O to save and then ctrl+X to quit.
Run your code by typing the following into the terminal:
>> sudo python3 pirsensor.py
You should notice that when motion is detected that the GPIO pin 4 reads HIGH, but when it is not detected GPIO pin 4 reads LOW. When the code reads HIGH your destination email should get an email saying “INTRUDER!”.
Press ctrl+C when your done to halt the program. Now Your Done!
For more detail: Raspberry Pi Controlled PIR Sensor with Email Notifications