Easy Raspberry Pi Security Cam With Automatic Web Upload




Introduction: Easy Raspberry Pi Security Cam With Automatic Web Upload

About: I'm a Mechanical Engineer turned IT Professional and Author. I came into the Information Technology world because someone challenged me to. But at heart, I'm still a grease monkey with no desire to lose touch …

This is a project that I put together super quick in under a week or so. The reason I needed to set this up the way I did was to get a basic security system in place as soon as possible to monitor my garage via my mobile device ,especially when I was away from home.

In its first version here, the security camera is controlled by a simple Python program that performs the following functions:

  1. Activate camera and capture a still image
  2. Check connection to the internet
  3. Upload the picture automatically to a WebAPI service
  4. If the connection fails, the image is cached to the local file system
  5. The saved image is uploaded the next time the program activates

Remote Web API Service:

I have my own ASP.NET based website where I host and test my code. As urgency was the key to this project, I started with a tutorial from Microsoft and modified the basic kit to upload the files using a secret key . I then added my own page that will need a personal secret key to view the most recently uploaded images first.

The Microsoft tutorial is located here. Readers who are comfortable working with ASP.NET technology stack can use this as a starting point. If not, you can build one using your favorite technology stack and modify the Python program accordingly.

The tutorial also comes with a basic styling that was not very appealing. Therefore, I decided to replace it with some quick bootstrap styling, which in its most basic form is quite easy on the eyes!

Step 1: Things You Would Need to Be Familiar With...

This instructable presumes that you're familiar with the following common knowledge from the countless resources accessible online:

  1. A Raspberry Pi (or simply referred to as the "Pi")
  2. Set up the Pi from a cold brick and turn it into an operational computer as it's supposed to be
  3. Configure the Pi to work with a USB Wireless Adapter to access the internet
  4. Modify the configuration settings of the Pi to enable the camera functionality
  5. Familiarity with Python, the IDLE environment , running Python programs
  6. Download and install Python modules/libraries

If you aren't or would like to revisit the Pi, this pocket book should come in handy to get you started.

Step 2: What You Need...

  1. The Raspberry Pi (Model B at least) from amazon or your favorite electronics retailer
  2. A qualifying SD Memory Card such as this one with at least 8 GB capacity
  3. An Edimax EW-7811Un Wi-Fi USB Adapter or equivalent that works well with a Pi
  4. A Waveshare Raspberry Pi Camera with Night vision also from amazon
  5. All the usual peripherals - monitor, keyboard and mouse
  6. A Raspberry Pi case (optional) - I decided to use one for obvious reasons


  • A 5V 3A power supply - Don't skimp on this piece of hardware!
  • Anything less than 3 amps will either shutdown your Pi, or like in my case, disable all other wireless equipment namely the keyboard and wireless access when the camera starts capturing images
  • I got one from KFDtech because in addition to the micro USB adapter, it came with a host of other ones that I could use in different projects or with other chargers in the parts bin
  • You will also need to install the Python PiCamera module to work with the camera using Python 2.7

This project uses Python 2.7.x. A different version of the PiCamera module may have to to be installed to get the camera working with Python 3.x

The instructions to install the PiCamera module is detailed in the user manual for the Pi Camera

Step 3: Plug in and Orient the Camera Right Side Up

Spending some time here will save you some trouble down the road.

Most issues arise from the fact that the camera is not plugged in correctly

When plugging in the camera, make sure that the Blue stripe on the ribbon faces the USB ports of the Pi

Ensure that the ribbon is plugged in uniformly - the blue stripe must appear as a straight band without noticeable taper on the opposite end once you are plugged in

Just so that the images are not captured upside down, the camera must be positioned in a way that the blue strip on the camera ribbon appears below the lens

Here I've used a couple of slack rubber bands to position the camera during testing - don't use uber-tight and beefy rubber bands or straps as you may risk damaging the photo-sensors on the face of the camera!


Given the tiny size, this one's easy to miss - remember to uncover the camera lens by taking off its cover!

Step 4: Enable the Raspberry Pi Camera Function

The Python program will be pretty much useless if the Camera function isn't enabled in the Raspberry Pi configuration file.

To do so, login to your pi using the default password raspberry (although it's recommended you change it to something more secure once tests have been completed).

  • At the LX terminal prompt type in:

sudo raspi-config

  • In the colorful screen that follows, scroll down to option 5 - Enable Camera
  • Tab to move cursor to the "Select" position and hit Enter
  • In the next screen, select "Enable" and hit Enter
  • With your settings saved, you will be back to the previous screen
  • Tab to the "Finish" position and hit Enter to complete the configuration


  1. The Rapsberry Pi Foundation has stopped supporting camera modules in recent days
  2. Therefore, when you open the Raspberry Pi Configuration Manager from the Desktop mode you will not find the Camera feature listed in the Interface tab
  3. The only way to enable support for the camera module is to run raspi-config and enable legacy camera support
  4. You will see a warning stating that this interface is not supported any more, but you can click OK to save your changes and reboot the Pi

Step 5: Writing the Python Code

The Python code is pretty straight forward.

The Watcher.py program file attached to this step contains as much documentation as sensibly possible to make it easily understandable.

As for the web service part of the equation, the code is pretty simple and is located on Microsoft's site

I have not published the Web API code here for the following reasons:

The Microsoft sample has been hosted with a code browser that makes it easy to read through the code better than if I hosted it here (not to mention content reproduction licensing terms!)

You may not be working with the Microsoft stack and would want to build your web service using another stack such as LAMP or Ruby


If you notice that the camera is capturing absolutely dark images after nightfall, you will have to update the script as follows:

# warm up camera
# allow at least 5 seconds for the sensors to capture the surrounding light
# now capture image

Step 6: Night Vision Runs Hot - Keep Your Camera Cool!

The camera does a great job of capturing images in the dark, but that comes with considerable heat. Literally!

I got a sense of it after putting the camera to work overnight in the living room and next day I found that the camera, and the Pi case had warmed up pretty good!

For initial tests I had used a couple of 3D printed pieces from another project for spacers, but they got pretty warm too!

In my case, the set up would be located in my unheated garage, but despite that, I decided to provide a basic heat sink between the camera and the Pi case.

For this, I set up a couple of metal washers lying around in the garage (and pretty cold by the way) by sandwiching them between the Pi case and the back of the camera (which is pretty flat, and gets pretty warm!)

This way there would be ample air circulation around the gap created by the spacers, and metal being conductive would cool down much faster than the plastic spacers or the Pi case.


The camera will operate in a cold dark corner of my garage most of the time. Therefore, I haven't choked the rubber bands around the setup because the more I stretch the rubber, the faster it will deteriorate at lower temperatures!

Step 7: Scheduling the Python Program Using Cron

Cron is a super scheduling utility that comes with most Linux flavors and the Raspbian flavor is one of them.

In my application, I want my Python program to be executed once every 30 minutes.

The program Watcher.py is saved at the location /home/pi/Watcher

Therefore, this schedule has to be added to the Cron table (or crontab) like so:

  • At the LX terminal, open the cron table in edit mode by typing this command:
    • sudo crontab -e
  • Use the cursor-down key to make your way to past the last line in the table
  • Add a useful comment beginning with a # to identify and understand your schedule in the distant future
    • # 12.12.2015 - - Run Watcher.py every 30 minutes using python
  • Just below the line, type the actual schedule like so:
    • */30 * * * * python /home/pi/Watcher/Watcher.py

where, */30 in the first position indicates a recurring schedule every 30 minutes

  • Now add another comment and schedule to clean out the cron logs every 24 hours
    • # 12.13.2015 - Clear cron logs every 24 hours
    • * */24 * * * echo '' > /var/log/httpd/access_log

In this case, the */24 is defined in the second position which is the place holder for the hour specification

  • To save changes, hit Ctrl + X and when prompted hit Y on your keyboard
  • Cron will confirm that you want to overwrite changes - simply hit Enter to return back to the LX command prompt

The comments I added to Crontab file pretty much describe the intent of what needs to be accomplished.


Cron logs get pretty exhaustive and with the limited storage on the SD card, these logs can prove to be problematic real quick!

For more information on Cron an Crontab, refer to this documentation

Before mounting the Camera, leave the Pi running to make sure that Cron is running the program as intended

Step 8: Mounting the Camera in Position

  1. I happen to get lucky because in my case I have a stretch of wiring that runs through an external channel on the wall that is bang opposite to the garage door
  2. By looping a wire tie around the channel I was able to mount the Pi and the camera pretty easily
  3. The wire tie is snug enough to hold the Pi at the set height, but flexible enough for me to adjust the height of the camera to capture the garage scene to suit my requirements
  4. The charger came with its own Velcro strap that helped secure the power chord
  5. Finally, I plugged in the charger to the wall socket and secured it using masking tape - duct tape is a bit too much!

With the camera mounted, all I had to do was wait for the Cron schedule to execute the Watcher.py Python program every 30 minutes.

Watcher.py would:

  • Trigger the camera to capture the image in the garage
  • Check for the internet connection and beam the image up to my hosted Web API service
  • If the internet connection failed, Watcher.py would stop capturing images and wait until service becomes available and then uploads the last image captured


This is the first version - Some of the nice to have features that I would like to add (if and when I get the time) would be:

  1. Add a motion sensor and capture an image each time the motion sensor is tripped
  2. Continue to capture images even in the absence of the internet connection or API service and add them to a queue
  3. Upload images in the queue once the internet connection and/or service becomes available
  4. Mount the unit on a Servo and have it auto rotate and follow the target!

Step 9: So, What's My Watcher.py Watching?


I really would like to keep tabs on my custom street rod when I'm away from home!

With a constant stream of images beamed up to my web API service, all I have to do is enter my access key on the Web gallery home page and select the number of images (starting with the most recent, and going back in time)

The gallery displays thumbnails of images along with their capture date and time stamp

These images from my live web gallery show the the contrast between the images captured when the lights are on and when there's near darkness . I say "near darkness" because the only lights I see in the garage are the ones that are blinking off of the Pi Board.

Regardless, they speak for themselves about the night vision capability of the tiny camera!

Hope you enjoyed my very first instructable!

Be the First to Share


    • Cold Challenge

      Cold Challenge
    • Make it Glow Contest

      Make it Glow Contest
    • Baking Contest

      Baking Contest



    6 years ago

    I have trouble when capturing picture. It said capture Timeout, how did you deal with it?


    Reply 6 years ago

    For the camera I used, I never ran into this issue. 9 months now, and the system is working without any issues.

    But these camera products have a timeout setting that may need to be changed in your setup.

    One helpful link to visit would be:



    7 years ago

    idea is good, but motion detection would be better. Heres another option, use any android phone with Motion detection software, then use tasker triggers to auto upload to any cloud service like dropbox etc. plus tasker can auto playback sounds like alarms etc. at a set preference, you can use either WiFi or use a backup cheap data plan to put images or videos to web. Tasker can SMS also if a video is uploaded. Less comlicated and less expensive. e.g. Moto E previous gen 1GB ram, may be $50 approx. is good enough


    Reply 7 years ago

    Yep, motion detection is something that I want to implement (as mentioned in one of my steps).

    In addition to motion detection, I'm trying to come up with some kind of a set up that can trigger the camera to rotate and follow the detected target. A couple of sensors should be able to give me a 180-degree sweep.

    In the meantime, I'm also thinking of designing a rotating mount , but my thinking is that the Pi+camera rotating as a single unit is a pain in the neck, and is heavy to begin with.

    Therefore, I have to design something to make just the camera rotate - which means some sort of a bracket . One of the cons of this camera unit is that it does not have a surface area that can be used to mount it to something. I guess this is going to take some time to design and print.


    Reply 7 years ago

    if you balance your pi-cam setup well, a simple servo underneath should be ok, but I think with motion detection you can put one inexpensive $5 wide angle camera lens, considering its just a small space you're monitoring.

    Even I'm looking to build tilt and pan mount for a smartphone, but it'll be working with an arduino to command the servos. No plans or need for zoom yet, but Tasker and arduino programming plus mount hardware would be quite a lot of time, so keeping it for later, would definitely share it here.


    Reply 7 years ago

    Got it! Please share it once it's up and running and I'll do the same.


    Reply 7 years ago

    Awesome! I will go through this article in detail. As mentioned in my ible, my project was a quick set up. I will need something more elaborate.

    currently i am researching on a web based home automation project using the arduino, but now I am thinking of using the Rpi. Which means some read up on the GPIO library. This is going to be fun (except the part where I have to take unwanted permissions from the boss)!


    7 years ago

    you can hide it in the car and see where your friends take your car!


    Reply 7 years ago

    LOL good Idea!

    one of the projects Im currently putting together is something close to what you've suggested. All I need is to get away for some alone time and put it in action.

    DIY Hacks and How Tos

    Cool security system. I think that I would put it at my front door so that I would know when people stop by while I am out.


    Reply 7 years ago


    The front door would be a perfect place to start. Now that I've got this up and running in my garage, I'm thinking of getting 4 more sets of the Pi and the camera and place them at other locations around the house.

    Or the other path to take would be to look into other options that would allow me to buy camera units that can report back to a single Raspberry Pi unit (over Xbee or Wireless) which would save me in the cost of additional Pis, and power supplies.

    But again, this option runs the risk of a single-point of failure.