This is the second blog post for the Pi Spy Audio Recorder project, in this blog post I am adding a PIR sensor to the Raspberry Pi Zero W, to detect a motion in the room, so that the spy audio recorder can start recording for a few minutes, and then send the recording to the spy via an email.
As part of the build/circuit, as you see in the picture above
- the PIR sensor signal pin, the yellow wire is connected to GPIO 4 on the raspberry Pi zero
- and the USB mic is connected to the Pi using a micro USB OTG cable.
Once you done installing pyaudio and running the python program in the previous blog, to record audio for 60 seconds, check if every thing is fine with your PIR sensor by running this simple program below. Basically you will have to check if motion is detected, by the sensor.
from gpiozero import MotionSensor from time import sleep pir = MotionSensor(4) while True: if pir.motion_detected: print("Motion Detected") else: print("No Motion") sleep(1)
Now, if you are using your brand new PIR sensor for the first time, and you are continuously get "No Motion" , even tough you are waving your hand in front of the PIR sensor, you may have to adjust the two potentiometers on your PIR sensor as you see in the picture below. To adjust the two pots you will need a regular small screw driver. To start off, make sure that trigger pot is to the left, which means lower trigger time, and the sensitivity pot in the middle.
Now, once you have successfully got "Motion Detected", in you Pi home directory create a recordings folder, using
Once done, download the python program file attached and FTP it to your Pi Zero W. And, run it using
sudo python3 spyRecordPIR.py
Now, instead of the above output, if you run into an error for your email setup, something on the lines of -
File "/usr/lib/python3.7/smtplib.py", line 642, in auth raise SMTPAuthenticationError(code, resp) smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8
This means you will have to login to your from_email and go to https://myaccount.google.com/lesssecureapps , to enable the less secure option, for the SMTP sending email method to work, and to get rid of the above error.
Here is an email with the audio recording received, once motion is detected by the PIR sensor.
Here is a quick demo video of the Pi Spy Audio Recorder in action.