How To Take Photo with Raspberry Pi at Given Time ?


Want to take photo of your room with Raspberry Pi if you are not at home ? It is possible with just few lines of code. This is my way to do it. I am using WDCloud to store images on my Windows drive available from anywhere. It is thanks to WD Cloud connected to my network. But you can store images on your local Raspberry Pi Sd Card and see them later. It is up to you. Jump in to my short article of how to take photo with raspberry pi at given time . For example every 5 minutes or so. 

Take Photo with Raspberry Pi at Given Time

First of all , create directory to store your images with simple terminal command like

mkdir /home/pi/mycctv

This is directory where you will store all your photos. That’s simple right ?

Another thing is to create sh file that contain terminal command to take photo

touch /home/pi/script.sh

you can give it executable permission like that

chmod +x /home/pi/script.sh

now we can edit it like that

nano /home/pi/script.sh

In you .sh file add this line

sudo raspistill -o /home/pi/mycctv/$(date +'%m%d%y%k%M%S''.jpg') -t 200

That command above will take the photo . You can test it in your termial. Image will be saved in /home/pi/mycctv as we mentioned in our command. Funny % and letters will give name to the file according to current date time including sceonds and extension will be .jpg . Simple right ?

Save the file (Ctrl+O , Ctrl +X)

Now it is time to exit cron file to run above command automatically .

sudo crontab -e

Add this line at the bottom of the file and save it (Ctrl+O, Ctrl+X)

 */5 * * * * /home/pi/script.sh

What is does mean ? It as cron to run file script.sh every 5 minutes

 

I am passionate about coding , online marketing and teaching others things that I know. I love to create something out of nothing. I love computers and that is my addiction. On my website I would like to share my knowledge and check myself how much that I know and what I don't. I love to learn and my motto is :So many things to learn ... so little time". Hope you're going to like my materials. I sincerely invite you to follow me on social media. All links to my profiles are available. Do not hesitate to contact me in case of any question, or if you just wish to say 'Hi'.

Leave a Reply

Your email address will not be published. Required fields are marked *