Sie sind auf Seite 1von 3

Raspberry pi as Motion sensor Hey guys get ready, Here's the Raspi to work like a real sentry a motion

on sensor to catch any unwanted motion near your sacred study table in your absence ! Or a robot to detect a motion ahead of it's path ! The PIR sensors are nothing but a kind of motion sensor which is built on Passive Infrared sensors with a little circuit at the back. Don't worry ! You are not going to built another circuit for PIR. The whole module is available in most of the hobby store for less than Rs:400. Some PIRs has a pot at the back to change the delay times that's once a motion it detects, it's signal remains high depending upon the position of the pot. Here's a picture of a PIR (in my fingers .. EFY is going to make my fingers famous ! he he )

The small board has three output pins +5, out & gnd. Don't soldier on the PIR, instead make a break out cable to take these three pins into the Raspi like this...

The breakout cable has nothing but having some female plugs together ,which takes out the connection for making additional connections outside. The Raspi side breakout cable (a 26 pin breakout cable & a plastic case) I purchased along with the Raspi whereas for the PIR I hand made it. The out pin of PIR goes high when a motion is detected in front of it within a radius of 2 to 3 meters. This signal is going to be deciphered by Raspi. Well here's the connection diagram & code for you....

Please forgive me for this poor quality drawing but it works !

#!/usr/bin/php <?php require_once('GPIO.php'); $button1 = 21; $button2 = 17; $gp1 = new GPIO(); $gp1->setup($button2, "out"); $gp2 = new GPIO(); $gp2->setup($button1,"in"); while(true) { $val = $gp2->input($button1); if($val ==1){ echo "Value:".$val.'<br>'; echo "Turning on pin 17\n"; $gp1->output($button2, 1); usleep(0.5 * 1000000); echo "Turning off pin 17\n"; $gp1->output($button2, 0); usleep(0.5 * 1000000); } } ?>

GPIO pin 17 is made as output whereas GPIO pin 21 is made as input. Once the PIR detects a motion it's out pin becomes high and seeing it Raspi makes GPIO pin 17 high , thus making the LED glow. In place of LED you can put a transistor (BC548 etc) to switch on a relay to do some bigger works which you have to decide. Bye bye Bera Vindhyanagar.