Wireless Security Camera with the Arduino Yun

Ever saw these wireless security cameras that you can buy off the shelf? These are devices that you can setup somewhere in your home or outside, connect to your WiFi network, and then automatically take pictures if some motion is detected, for example. However, they are usually using the interface given by the manufacturer, which means you are quite limited with what you can do with your camera.

In this project, we are going to build our own DIY version of such devices. The project is based on the Arduino Yun, to which we are going to connect a standard USB webcam and a PIR motion sensor to create a cool application.

The application will be a modern version of a standard task that you expect from a security camera: taking pictures when some motion is detected. The project will store pictures taken by the USB camera on an SD card inserted into the Yun, but that’s not all. Because we are in the age of the Internet of Things, we also want these pictures to be automatically uploaded on a secure location. And that’s exactly what we are going to do by uploading the pictures to Dropbox at the same time. Excited? Let’s dive in!

Hardware & Software Requirements

The first step is to make sure you have the right hardware components. You need the following components to build this project:

For the USB camera, you can choose any webcam that is compatible with the UVC protocol. Most of the recent webcams are compatible. I choose a Logitech C270 that can take pictures up to 720p resolution. You can find a list of compatible cameras here:


Before we can build exciting applications with our hardware, we need to setup some accounts on the web services we are going to use. The first one is Temboo, where you will need to have an account. Temboo will basically make the interface between the Arduino Yun and Dropbox. Just go over to:


You will be prompted to create an account, and then your first app. Write down the name of your account, the name of the app and your app API key, you will need them later. There is also one more thing you need from the Temboo website: the Temboo Python SDK, that we will use later to upload pictures to Dropbox. You can get it at:


Once downloaded, simply extract the folder on the microSD card.

Then, you need a Dropbox account. Go over to the Dropbox website to do so:


Once the account is created, you need to create an App so the Yun can upload pictures to your Dropbox folder. To create an app, you need to go to the developers section of Dropbox:


Then, click on “Create app”, and choose which type of app you want to create (Dropbox API app for our project):

8007_03_03Then, select “Files and datastores”:


What you need to get now is all the keys relative to your Dropbox app, so you can enter them later in the software part of the project. You will need the App Key and App Secret at this point, which are displayed on the same page as your app.The next data we need to get is the Token Key & Token Secret key. To get them, the first step is to go to the InitialiseOAuth Choreo on the Temboo website:


Here, you will need to enter the App Key and App Secret. That will generate some additional information, like a callback ID, and a temporary token secret. You’ll also be asked to visit a link to Dropbox to confirm the authentication. Finally, go to the FinalizeOAuth page to finish the process. You’ll be asked to enter your App Key, App Secret, callback ID and temporary token secret:


After that step, you’ll be given your final Token Key and Token Secret. Write them down, you’ll need them later.

Hardware Configuration

The first step is to insert the SD card in the Arduino Yun board:


Then, connect the camera to the USB port of the Yun:


Finally, connect the motion sensor to the Yun. Simply connect the VCC pin to the Yun 5V pin, GND to GND, and the SIG pin to the Yun pin number 8:


Finally, just connect the project to your computer via the microUSB port, and you’re good to go!

Testing the Camera

Before we can write the software for our project, we need to install some more software on your Arduino Yun. We are also going to test the USB camera to see if the drivers are working correctly. In the rest of the project, I will assume that your Yun is already setup and connected to your local WiFi network. If it is your first time using your Yun, I recommend following this guide first:


First, the UVC drivers for the camera. To install them, you need to connect to your Yun via SSH. Simply open a terminal, and type:

ssh [email protected]

Where you need to insert the correct name of your Arduino Yun, that you set when you first used the Yun. You will also be prompted to enter your password. If the connection is successful, you should see some ASCII art:


We can now install the required packages. Start with an update of the package manager:

opkg update

Then, install the UVC drivers:

opkg install kmod-video-uvc

And the python-openssl package:

opkg install python-openssl

We also need the fswebcam utility that we will use to take pictures from the terminal:

opkg install fswebcam

We are now ready to test the webcam. Make sure that the SD card is mounted into the Yun, and go over to the SD card folder with:

cd /mnt/sda1

To test the camera and take a picture, it is really easy. Simply type:

fswebcam test.png

You should see some information being displayed, along with some errors, but don’t worry about them. The important thing is to see these lines:

— Opening /dev/video0…
Trying source module v4l2…
/dev/video0 opened.

To check that the picture was correctly taken, remove the SD card from the Yun and read it using your computer. You should see the picture appearing at the root of the SD card:


Simply open it to make sure it was correctly taken and that it is not corrupted. If the picture looks good, you can go over to the next section and start building cool applications with the project!

Building the Security Camera

What we want to achieve in this first application is to take a picture whenever some motion is detected by the PIR motion sensor. And when that happens, store this picture locally on the SD card, and upload it to Dropbox. To do so, the code will be composed of two parts. T

he first one is a Python script that will connect to Dropbox, take a picture on the SD card, and then upload this picture to Dropbox. The reason to use Python for this part is that it is much easier to upload files to Dropbox using Python than directly from the Arduino sketch.

The second part of the code will be the Arduino sketch itself, which will basically call the Python script to take pictures via the Bridge library of the Yun.

Let’s first code the Python script. It starts by including the required libraries from the Temboo Python SDK:

from temboo.core.session import TembooSession
from temboo.Library.Dropbox.FilesAndMetadata import UploadFile

The Python script will also take the name of the picture we want to upload as an argument:

with open(str(sys.argv[1]), "rb") as image_file:
  encoded_string = base64.b64encode(image_file.read())

Remember these Temboo credentials that you created earlier ? That’s where you need to enter them:

session = TembooSession('yourTembooName', 'yourTembooApp', 'yourTembooKey')

We can then create the correct Dropbox library to upload files, called a “Choreo” on Temboo:

uploadFileChoreo = UploadFile(session)
uploadFileInputs = uploadFileChoreo.new_input_set()

It’s now the time to enter all the informations about your Dropbox account, like your app Key, app Secret, Access Token an Access Token Secret:


And finally, upload the file on Dropbox:

uploadFileResults = uploadFileChoreo.execute_with_results(uploadFileInputs)

You can now save this code in a file named upload_picture.py. Note that all the files are available on the GitHub repository of the project:


We’ll now work on the Arduino sketch. The sketch starts by including the required libraries:

#include <Bridge.h>
#include <Process.h>

We also have to declare a process, that we are going to use to call functions on the Linux machine of the Yun (for example the fswebcam utility we used before):

Process picture;

We are also going to build a filename for each picture the project will take, that will be stored in a string:

String filename;

We also declare the pin on which the PIR motion sensor is connected:

int pir_pin = 8;

And the path of the SD card on the Yun:

String path = "/mnt/sda1/";

Because we need to call functions on the Linux machine of the Yun, we have to start the Bridge:


Then, in the loop() part of the sketch, we check if some motion was detected by the PIR sensor:

if (digitalRead(pir_pin) == true) {

If this is the case, we build a unique filename for the picture, with the date at which the picture was taken:

filename = "";
picture.runShellCommand("date +%s");
while (picture.available()>0) {
  char c = picture.read();
  filename += c;
filename += ".png";

We then make the first call to the Linux machine of the Yun, first to take a picture with the fswebcam utility. Note that here, we provide an extra argument with the -r command, which set the resolution. I used the maximum resolution of my camera, which is 720p:

picture.runShellCommand("fswebcam " + path + filename + " -r 1280x720");

We then make a second call to the Linux machine, this time calling the Python script with the name of the picture as an argument, which will upload the picture to Dropbox:

picture.runShellCommand("python " + path + "upload_picture.py " + path + filename);

You are now ready to test the project. Again, all the files are available on the GitHub repository of the project:


First, put the Python file at the root of the SD card, and put the SD card back into the Arduino Yun board. Then, upload the Arduino sketch to the Yun. Now, try to trigger the motion sensor, for example by waiving your hand in front of it. You should see that the webcam is being activated shortly after (for example, my webcam has a LED that turns green when it is active).

To check that the project is working correctly, after a while you can check the SD card, you should see that some pictures have been recorded:


You can also check on your Dropbox folder, where the same pictures should have been uploaded. They should be located in your Dropbox apps folder:


How to go Further

In this project, you learned how to connect a USB camera to your Arduino Yun and build an exciting project on top of it. We built a security camera that automatically uploads pictures on Dropbox when motion is detected by a motion sensor.

Of course, there are several ways to build other cool applications using this project. You can for example drop the motion detection part, and build a camera that take snapshots at regular intervals and upload these on Dropbox. You can for example easily create time-lapse videos with this kind of project: just collect the pictures from your Dropbox account, paste them into a time-lapse software, and done! You can also extend this project by adding more Yun + camera modules, to have a complete monitoring system in your home!

  • Pingback: Construire une caméra de sécurité avec une webcam et un arduino | Geekofyou()

  • Kyle Cox

    Thank you for the great info!! I was wondering if this can be adjusted to stream video instead of pics. If not, where do you suggest i look. Thank you for any advice you may have.

  • Jonathan Oberreuter

    What should I put on “sandbox”?


    • Hi Jonathan, just leave this like this, sandbox means this app can’t access your other Dropbox files.

  • Frank Tiernan

    Hello Marco,

    Thanks for the very interesting post. Can you provide a few more details on the step:

    “Once downloaded, simply extract the folder on the microSD card.”
    I’ve downloaded the temboo python files to my MacBook and have the arduino yun connected to the MacBook (and also the wifi). I can access the microSD from a terminal window using ssh but am unsure of exactly how to proceed from there.

    • Thanks! I recommend putting the SD card directly into your Macbook (via an adapter) and then extract the folder to the card from there. SSH for this transfer should work as well but I didn’t try it.

      • Frank Tiernan

        Thanks Marco, that did the trick! All working now. I had a bit of difficulty troubleshooting the Python script over the Yun bridge but found that creating a file in the python script using:
        f = open(‘/mnt/sda1/workfile.txt’, ‘w’) and then writing runtime diagnostics to it as necessary using f.write() (and f.close at the end) and then reading work file.txt from the microSD (on the Mac) helped resolve things.

  • redpuca

    Should the Temboo and DropBox apps have the same name?

  • Vinood Lechimanan

    as i am using windows i have problem on accesing the terminal for SSH… is there any other way to install package manager, uvc driver, and phyton package…???

  • Sicabol

    Hi !
    It’s my first Arduino project… and I have a problem with the HTTPS connection. I’ve installed python_openssl on the Yun but it doesn’t give me access to HTTPSConnection from httplib. Of course Python 2.7.3 is installed.
    So when I launch upload_picture.py (even from the shell through SSH) I’ve got this error from Temboo lib :

    python upload_picture.py 1446930347.jpg
    Traceback (most recent call last):
    File “upload_picture.py”, line 7, in
    from temboo.core.session import TembooSession
    File “/mnt/sda1/temboo/core/session.py”, line 34, in
    from http.client import HTTPConnection
    ImportError: No module named http.client

    It is due to the try/catch at the beginning of the session.py file, as “from httplib import HTTPSConnection” raises an error.
    Does anyone have a clue about how to solve the problem ? Thanks !

  • shane jelliffe

    please help…
    every time I enter the following command I get a “not found” error.

    [email protected]:~# cd/mnt/sda1

    -ash: cd/mnt/sda1: not found