Welcome again this time you will learn how to use the digital inputs on the GPIO connector with PIR motion detector.
PIR sensors, often referred to as, "Passive Infrared" or "IR motion" sensors, enable you to sense motion. Everything emits a small amount of infrared radiation, and the hotter something is, the more radiation is emitted. PIR sensors are able to detect a change in IR levels of their detection zone (e.g. when a human enters a room) and hence sense motion.
The PIR sensors we’ll be using in this tutorial have three pins: ground, digital out and 3-5VDC in. At idle, when no motion has been detected, the digital out will remain low, however when motion is detected, the digital out will pulse high (3.3V) and we’ll use our Raspberry Pi to sense this! The PIR sensors we’ll be using in this tutorial have a range of approximately 7 meters, and a 110° x 70° detection range, so it’s great for monitoring a door or the corner of a room.
The GPIO pins can be used as both digital outputs and digital inputs. The High and Low levels are 3.3 volts and 0 volts. higher voltages may damage your PI.
The figure belwo shows the pinout for Raspberry Pi Rev 2.
To start using thr GPIOs you need to install a library called Rpi.GPIO. This module gives you a simple to use Python library that will let us control the GPIO pins. This library may be included in your image but doing the following steps will get you the lates version of this library.
sudo apt-get update
sudo apt-get install python-dev
sudo apt-get install python-rpi.gpio
You will probably be prompted to confirm by entering 'Y'.Thats all there is to it. You are ready to proceed.
import RPi.GPIO as io
io.setup(pir_pin, io.IN)# activate input
Since the output of the PIR is about 3.3 volts it could be connected directly to the board,as you can see we are using GPIO 18.
Run on Raspberry
SSH to your raspberry
SSH under Windows
If you use windows, then you will need to download a free program called “putty” from here: http://www.putty.org/. run the program once downloded.
Enter the IP address that you found earlier and click “Open”. This will give you a warning (the first time) and then prompt you for the user (“pi”) and password (“raspberry”). The ssh window will then be ready for use.
creat new empty file using the following command
copy and paste the code into it, Ctrl+X to save confirm the