In this mini blog series we will build an IoT based intruder detection and alert system.
Blogs:
Part1 : Connecting Pir Sensor
Part2 : Capturing intruder image <--- this blog
Part3 : Email Alerts
In previous blog we integrated a PIR sensor to Riotboard for human movement detection.
In this very short guide we will try to capture image once an IR detection is made.
I am using a Logitech C310Logitech C310 USB camera for this purpose.
Connect pir sensor HC-Sr501 and Camera to Riotboard.
to capture image we will use fswebcam tool.
in terminal type:
apt-get install fswebcam
Now we determine the usb device
type "ls /dev/video*" without pluggin camera.
Now pluggin camera to Riotboard, and type "ls /dev/video*"
check for video device in /dev.
the camera hardware is accessible at the device /dev/video2
now add below line to previous code below ln28.
system("fswebcam -d /dev/video2 capture.jpg");
Next we will compile the below code and test.
#include <stdio.h> #include <fcntl.h> #include <unistd.h> #include <string.h> int main() { int ret =0; int fd=0; char buf[1]; system("devmem 0x20E00A0 w 0x5 "); system("echo 113 > /sys/class/gpio/unexport"); system("echo 113 > /sys/class/gpio/export"); usleep(100000); system("echo in > /sys/class/gpio/gpio113/direction"); usleep(100000); fd = open("/sys/class/gpio/gpio113/value",O_RDONLY); while(1) { ret = read(fd,buf,sizeof(1)); if(lseek(fd,0,SEEK_SET) < 0) return 1; if(ret>0 && (atoi(buf)==1)) { printf("\n\033[031;43m HUMAN DETECTED \033[0m "); fflush(stdout); system("fswebcam -d /dev/video2 capture.jpg"); usleep(500000); } else printf("\nNo Detection"); fflush(stdin); fflush(stdout); usleep(500000); } close(fd); }
Now perform some hand movement infront of Pir sensor, it will show human detected and captures image as "capture.jpg".
before capture:
after capture:
Now with every pir interrupt we can capture the image of the intruder.
Next time we will add an image based email alert for the above.
Top Comments