Before running the code, make sure the sender and receiver email addresses and the password of the email sender are all entered.

The code will read the output from the sensor and, upon detecting motion, will capture an image and save it on the database folder.

When you run the code for the first time, it will automatically create the folder. Once the camera captures an image, the image will be attached in the email and sent to the sender’s address.

Copy and paste the below code into a new file with a filename extension .py and run the code with the command: python “filename” (e.g. python motionTest.py).