Tim is currently doing research in Internet of Things (IoT). His desire to spread the concept, ideas, and experience of IoT.
This small project can be useful when you want to capture images from remote location and perform some research on those images. Using the technique described in this article you can create an Internet of Things (IoT) device that sense the environment as in form of image/picture.
I have build a sensor node to monitor a human or animal activity outdoor. Whenever any human or animal comes in the range of sensor node, it captures the image and submit it web server. TO create such sensor node following equipments are required:
- Raspberry Pi (3 or latest)
- PIR motion sensor
- USB Camera
First connect the USB camera to your Raspberry Pi on the any USB port available on board.
Now connect the PIR sensor to Raspberry Pi as shown in following image:
- VCC to pin 2 (5V)
- OUT to pin 16 (GPIO 23)
- GND an pin 6 (ground)
Now you need to have python on your Raspberry Pi. If it is not pre-install, then you can install it as described in this link.
Write or copy paste following python script in the file called capture.py. You can give any name to your python script file.
The above python script checks whether the PIR sensor has detected any activity. If any activity has been detected, then the script invoke camera to capture image and then post that image to a PHP file, upload.php, located on remote server. Therefore whenever the python script POSTs image, the PHP page gets invoked at remote server and stores the image to database.
Following are the images of sensor node that I have developed.
At remote server the PHP page receives the image file and store it to database as shown in following code
After saving the python script the 'crontab' in Raspberry Pi must be configured than only the script start automatically at system startup and always keeps running in background. This is required because the script to capture image must be running all the time.
To configure 'crontab' open the terminal and type following command:
Now add the following line at the very end of file:
The above line run python script each time system restarts and keep it running until system is shutdown. It also adds the log to a text file.
Restart the Raspberry Pi, and the python script will automatically starts running as background process.
You can create a page to view uploaded image on web server and access it from anywhere. I have created a page display.php which displays all images in HTML image tag. Please check my article to display images from database. You may apply certain filters to display images for example view images on particular date.
Following code segment shows how you can display images. It displays all images captured on current day.
This kind of project can also be used to capture images of agricultural fields, green house etc. to monitor crops such as I have done in my research 'Mobile detection of crop diseases for agricultural yield management' to perform disease analysis of crop
or you may use anywhere where IoT based monitoring via images is required. You can also use these captured images for analysis or computation by applying Computer Vision and Machine Learning or Artificial Intelligence.
© 2019 Timothy Malche