members
Raspberry basics: Project 22a Raspberry PI Zero W board - PIR sensor, email notification
of Acoptex.com in Raspberry Pi Zero W
Raspberry basics: Project 22a
Project name: Raspberry PI Zero W board - PIR sensor, email notification
Tags: Raspberry, Raspberry PI Zero W board, vers 1.1, v 1.1, PIR sensor, email notification, RPi.GPIO library, time library, Gmail, smtplib library
Attachments: piremail.py
In this project, you needed these parts (Dear visitors. You can support our project buy clicking on the links of parts and buying them or donate us to keep this website alive. Thank you):
1. Raspberry PI Zero W board 1 pc
2. Micro SD card with NOOBS and SD card adapter 1 pc
3. Micro USB power supply (2 A 5V or 5V 3A) 1 pc
4. USB keyboard 1 pc
5. USB mouse 1 pc
6. TV or PC monitor 1 pc
7. HDMI cable 1 pc
8. T-Cobbler Breakout and GPIO Cable 1 pc
9. Micro USB 2.0 OTG Cable 1 pc
10. Mini HDMI to HDMI Adapter (HDMI to Mini HDMI Adapter) 1 pc
11. 4-Port USB 2.0 Hub 1 pc
12. PIR sensor HC - SR 501 or HC - SR 505 or Mini PIR Motion Sensor Module SC0322 1 pc
13. Jumper cables F-M, M-M
14. Breadboard 1 pc
General
We will learn how to use PIR sensor with the Raspberry Pi Zero W board. When the PIR sensor detects the motion it triggers an event that sends an email with message.
This project code is only set up to work with Gmail accounts.
Understanding the PIR sensor
You can read more about it here.
Understanding the Raspberry PI Zero W board
You can read more about it here.
Signals and connections of the PIR sensor
We are going to use Mini PIR Motion Sensor Module SC0322 in this project.
Signals and connections of the Raspberry PI Zero W board
Wiring
Step by Step instruction
We recommend using a high-performance SD card for increased stability as well as plugging your device into an external display to see the default application booting up.
1. Setup and preparation
We assume that you have Windows 10 installed on your PC and Raspbian OS installed on your Raspberry Pi Zero W board.
- Do wiring.
- Insert your micro SD card with Raspbian OS into the TF card slot on the Raspberry Pi Zero W board. It will only fit one way.
- Connect Raspberry PI Zero W board mini HDMI port to your TV or Monitor HDMI (DVI) port (use HDMI cable and mini HDMI to HDMI adapter and/or HDMI to DVI adapter).
- Make sure that your monitor or TV is turned on, and that you have selected the right input (e.g. HDMI/DVI, etc).
- Plug in micro USB 2.0 OTG Cable to USB data port of Pi Zero and 4-Port USB 2.0 Hub to micro USB 2.0 OTG Cable.
- Plug in your USB mouse and USB keyboard to 4-Port USB 2.0 Hub.
- If you intend to connect your Raspberry Pi Zero vers 1.2 or vers 1.3 to the internet, connect a WiFi dongle to one of the 4-Port USB 2.0 Hub ports.
- Connect Micro USB power supply to Raspberry PI Zero board micro USB input.
- The Raspberry PI desktop will start up.
- Open Terminal window and type the command: sudo apt-get update
- Then type the command: sudo apt-get install
2. Setting the GMAIL accounts
- As we are using GMAIL accounts in this project you need to make some too.
- Go to gmail website and make two accounts: first account you will need to send email and second account you will neeed to receive it.
- Please note the first_account_email_address, first_account_access_password, second_account_email_address, second_account_access_password as you will need them later.
- Change your settings on the first account to allow less secure apps into your account:
- Go to your Google Account.
- On the left navigation panel, click on Security.
- Scroll down and on the bottom of the page, in the Less secure app access panel, click on Turn on access.
3. Making the program
- Open the Raspberry Pi Configuration tool from the main menu. Go to Raspberry icon-> Preferences -> Raspberry PI configuration
- Select Interfaces and make sure that all settings are enabled. If it’s not enabled, enable it and reboot your Raspberry PI board to begin. We suggest to enable all settings and you will not need to come back to these configuration tool again.
- Click on OK button. We need to reboot our Raspberry PI.
- After restart of Raspberry Pi go to Terminal. Type this command in the Terminal: sudo nano piremail.py
- Copy and paste the code from piremail.py to opened window. Since it is a Python code, you need to be careful with the Tab characters as it is important to group the instruction as blocks in Python.
- Edit the first_account_email_address, first_account_access_password, second_account_email_address to correspond with your desired emails.
- Press Ctrl+X, Y, Enter buttons to save the file.
- Type the command in the Terminal: sudo python piremail.py
- When the motion detected the GPIO4 reads HIGH and your destination email should get an email saying "ALARM MOTION DETECTED!!!".
- Press Ctrl+C when your done to stop the program.
Summary
We have learnt how to use PIR sensor with the Raspberry Pi Zero W board. When the PIR sensor detects the motion it triggers an event that sends an email with message.
Libraries in use
- RPi.GPIO
- time
- smtplib
Script
- Look for attached code on the begining of this project
Other projects of Acoptex.com










Viewed: 4426 times