In the previous posts we discussed about why Internet of Things is the buzzword of the decade and how to get started working on a Raspberry Pi to fire up an LED light. But now we’re stepping up the game from lighting up LEDs to detecting motion.
Sitting in front of the laptop staring at my pi3 and the sensors I had just bought, I was wondering what to work on. Something that is pretty cool, not mundane, something that can be used as a building block for the upcoming projects, yet not very complicated for beginners.
Some brainstorming and my natural inclination towards image processing led me to interfacing the raspberry pi with the PIR motion detector sensor. One might wonder what a motion detector sensor has to do with images. Fret not, I have a camera module that is going to come in handy for the next building block.
The bigger picture I’m looking at, is to activate the camera module and detect a face in the frame when the motion detector sensor is triggered. Watch this space for more such building blocks, like installing opencv and learning more image processing, to lead up to the bigger picture.
Introduction to the sensor:
PIR sensor is a motion detection sensor that is used to detect whether a human has moved in or out of the sensor’s range. They are inexpensive, low power, small and easy to use. PIR is made of a pyroelectric sensor, (refer image) the rectangular crystal (which detects the level of IR radiation) covered with the round can. Ideal input voltage is 5V and the output signal when motion triggers the sensor is 3V.
The IR sensor in a motion detector is split in halves, because we’re only looking to detect motion, and not the IR levels. The sensor we are using use the BISS0001 chip. This chip takes the output of the sensor and does some minor processing on it to emit a digital output pulse from the analog sensor. Remember that the sensor can also be set off by your cat, just saying!
Moving on to the project, let’s wire up the sensor to the Raspberry pi. You could connect the sensor directly to the GPIO pins of the pi, however we’re going to be connecting via a breadboard because it is easier to expand this project in the future. Remember that the sensor would work just as good, no matter which way you pick to connect it to the pi.
- Plug three M to F jumpers into the three pins on the PIR sensor.
- Plug the input pin (PIR-VCC) into the positive row of your breadboard, ground pin (PIR-GND) into the negative row, and output pin (PIR-OUT) into the other blank row.
- Connect the pin 6 (GPIO-GND) on the pi, to the negative row of the breadboard and PIR-OUT into any other blank row.
- Use another jumper wire to connect the pin 2 (GPIO 5V) on the pi to the positive rail of your breadboard (The same rail as PIR-GND wire)
- Connect the pin 26 (GPIO 7) to the same rail as the PIR-OUT. This is because we will be using pin 26 as an input to sense when the PIR detects motion.
Now that the hardware setup is done, let’s push some code into the pi so that it prints out a statement when the sensor senses movement.
The PIRs have a potentiometer inbuilt, that can be tuned to adjust the sensitivity of the sensor. Clockwise tuning increases the sensitivity, so if the print statements are running on an infinite loop, then tune the potentiometer in the anticlockwise direction.
Unfortunately, this method uses up a lot of computation power and makes sure the sensor keeps sensing continuously. We definitely don’t want that when we’re working on a more “real world” application. Since this is a pet project and something that we’re going to be using as a building block to a bigger project in the future, I’m inserting time.sleep() statement to not let the sensor work continuously.
Watch this space for more posts in the coming days. We will discuss on the architecture of Raspberry Pi, why I chose the Pi3 over Pi2, and more such topics on the foundation of IoT and Raspberry Pi. Also, do let me know if you have any questions or ideas!