Wireless Camera with Arduino and the CC3000 WiFi chip

camera_wifiOne nice thing to have in any home automation or alarm system is a camera to see what’s going on remotely. Of course, such solutions already exists, and you even have WiFi cameras that you can buy for under $50. But they are not open-source, and therefore it is difficult to have the control on what’s going on, or to customize the interface. In 2012, a nice tutorial was published on how to build such a connected camera. You can find the tutorial here. We will do something different in this article: we will use the CC3000 WiFi chip and the Arduino platform, along with a serial camera, to build you own wireless camera. You will learn how to take still pictures from your home and display them on your computer remotely. Let’s dive in!

Hardware requirements

The whole project is based on the Arduino platform, so of course you will need an Arduino board. I really recommend using the Arduino Uno board for this project, as it is the only board that is currently compatible with the CC3000 library at the time this article was written.

Then, you need the CC3000 chip. I recommend using the Adafruit CC3000 breakout board, which is the only one I tested that worked without problem. It is nice and compact, has voltage regulators onboard, as well as an onboard antenna. You can also make your own breakout board, as there are many PCB layout available online.

Then, you need a camera. I used a TTL serial camera from Adafruit. It is quite easy to connect and to use, thanks to a library developed for Arduino. It can take pictures up to 640*480. Not great, but enough to see what’s going on in your house. You will also need two 10K ohms resistors to connect the camera to the Arduino.

Finally, you need a breadboard and some jumper wires to make the connections between the different parts.

Software requirements

For this project, you just need the usual Arduino IDE, and the Adafruit’s CC3000 library. To install a library, just download the required folder, and put it into your /Arduino/libraries/ folder. You will also need the library for the serial camera.

You will also need a web server running on your computer.

Hardware configuration

The hardware configuration for this project is actually not that complicated, thanks to the good informations that you will find on the CC3000 breakout board. Connect the IRQ pin of the CC3000 board to pin number 3 of the Arduino board, VBAT to pin 5, and CS to pin 10. Then, you need to connect the SPI pins to the Arduino board: MOSI, MISO, and CLK go to pins 11,12, and 13, respectively. Finally, take care of the power supply: Vin goes to the Arduino 5V, and GND to GND.

Now, the camera. There are four pins to connect: the power pins VCC and GND, and the two serial pins TX and RX . Connect VCC to the 3.3V pin of the CC3000 board, and GND to the Arduino ground. After that, connect the TX pin to the Arduino pin number 2 using a voltage divider with the two 10K ohms resistors, following the picture below. Then, connect RX directly to the Arduino pin number 4.

The following picture summarizes the hardware connections:

cc3000_camera

Testing the camera

In this part, we are simply going to test the camera. I also recommend testing if your CC3000 module is wired correctly. For that, please refer to this tutorial. The code for this part is available on our GitHub repository.

In this test sketch, we will just see if the camera is correctly recognized, and try to take a picture. It starts by importing the correct libraries:

Then, we have to create the correct objects to use the camera: a software serial connection on the right pins, and finally the camera object:

Then, in the setup() function, we can check if the camera can be initialized:

We also need to set the picture size:

Finally, after 3 seconds, we can try to take a picture:

As usual, you will find the complete sketch on the GitHub repository of the project. You can upload the complete sketch, open the serial monitor, and you should see the following lines:

Camera test
Camera found
Picture in 3 seconds …
Picture taken!

Uploading a picture on your computer

Now let’s dive in the core of the article: automatically uploading the pictures taken by the camera to your computer. We’ll keep it very basic: the Arduino will simply upload a picture at given time interval, and erase the picture that was uploaded before. But it is quite easy to modify the software to do some more advanced functions. The code for this project is available on our GitHub repository.

First, the Arduino sketch. I will really focus on the code to upload the picture to your computer, you can find the details of how to connect to a WiFi network in a previous tutorial. The whole difficulty in this project is to format the right HTTP message to send to the server. We will transmit the picture using a “multipart/form-data” content type. And for that, we need to know the exact length of the message we are going to send to the server. After taking a picture like in the test sketch, we need to know the size of the picture:

The size of the data being sent will be this jpglen, plus the extra length of the headers around the picture. This is done by these lines:

We can then compute the final length of the message with:

We can then connect via TCP to the server:

And send the start of the request:

Now, we get to the part where we actually have to transfer the picture. We are going to send it chunk by chunk to the server. This is the loop that transfer the picture to the server:

This code basically put the picture in a buffer of 16 bytes, and transfer it to the server with a write() operation. There are two parameters you can play with here: the size of the buffer, and the delay() at the end. I had to reduce the size to 16 bytes and add a 100 ms delay to actually make it work, otherwise the picture was corrupted when it arrived on my computer. So at the moment the file transfer is quite slow. It might work with other parameters for you, I would really be interested by your results!

We can finish with the end of the request:

You can go over to our GitHub repository to check out the complete sketch.

Now, the server part, which is much shorter. It is basically a PHP file, camera.php, that is called by the Arduino sketch. This is the content of the file:

This code is actually quite simple: the main part is the move_uploaded_file command that move the $_FILES['picture']['tmp_name'] to the target path. It checks if this operation was successful, and return an error otherwise.

You can now upload the sketch, and look at the serial monitor. You should see the Arduino take the picture, connect to the server, and start uploading it:

Screen Shot 2013-10-01 at 10.15.54 AM

You can check the little dots on the Serial monitor to be sure it’s actually doing something. After a while, this is what was uploaded on my computer:

CAM

Of course, you can now use this code to develop some more advanced applications using this simple serial camera. It already has a built-in motion detector feature that I didn’t try yet, it would be an interesting application as well ! Note that in this tutorial, we will only cover a tiny part of the possibilities offered by the Arduino platform. If you want to learn more about Arduino, I recommend following the excellent Arduino Step by Step course on Udemy. This is the list of the part that were used in this tutorial:

You have an idea on how to improve this tutorial ? You made it and developed some cool applications ? Please let us know by commenting below or discussing on our forum !

Receive the latest news about home automation
Over 100 home automation enthusiasts already joined our list !

Do you want to receive the latest news about open-source hardware and home automation ? Then join our mailing list today by entering your name and email below. It is 100% free and you can unsubscribe at any time if you're not satisfied.

22 replies
    • Marco Schwartz
      Marco Schwartz says:

      Unfortunately, the Arduino Uno board is not powerful enough for such tasks (live video streaming). But it might be possible using a Raspberry Pi or a BeagleBone (or some of the new Arduino boards that were recently announced like the Arduino Tre). Also, this camera is really meant for snapshots only and not for live video streaming.

      Reply
  1. Ibrahim Odeh
    Ibrahim Odeh says:

    Initially I would like to thank you for this great project.

    I am newbie here and I know the question that I will ask right now may be considered stupid question but to be stupid one time much better to be stupid for the whole life :)

    Can this project work independently I mean without connecting the Arduino to computer (PC) can this project works alone and send the captured image to some server? I believe that it must be connected initially to upload the code but my after uploading can I disconnect Arduino from the PC?

    Thanks in Advance.

    Regards

    Reply
    • Marco Schwartz
      Marco Schwartz says:

      Hello Ibrahim,

      Thanks for your question ! Sure, once it is uploaded to the board you can just connect the project to a power supply and it will just work by itself! You will just have to modify the sketch for your needs (for example, taking a picture every 10 minutes or so).

      Reply
  2. miguipda
    miguipda says:

    Hi,

    why not doing it with the last Arduino Yun which already have a wifi and could allow to use it as webserver inside.
    http://arduino.cc/en/Main/ArduinoBoardYun?from=Main.ArduinoYUN

    It will just need the motion detection facilities and it could become to have a perfect remote home survey.

    Have a nice day.

    Miguipda ;-)

    It will then just need to add an independant IR with light (with sensibility switch) for night vision could be perfect.

    Reply
  3. martin
    martin says:

    Hi Marco,

    nice tutorial, thx.
    Did you manage to transfer the data faster?
    Its a pitty that it is so slow but I have to use the same settings as you do to make it work.

    cheers, martin

    Reply
    • Marco Schwartz
      Marco Schwartz says:

      Hello Martin,

      Thanks for your comment ! Unfortunately not, I tried it again recently and it’s still slow. I don’t really know if it’s a problem in the library (cause the CC3000 chip can definitely handle faster transmissions) or the Arduino Uno microcontroller is just too slow to handle such a task.

      Reply
  4. Amit Kumar
    Amit Kumar says:

    hello
    i m working on a quadrotor project for autonomous flight. i want to use the image taken by the camera to process it and use it for finding the position of the target.
    can this camera be implemented and how we can use it in such application???

    Reply
    • Marco Schwartz
      Marco Schwartz says:

      Hello David,

      For sure, the same can be done with the Arduino WiFi shield with only small modifications to the code. Look at the official WiFi shield documentation to know which part you have to modify.

      Reply
  5. Kris
    Kris says:

    Hi!
    Im a newbie and I have a question. Say i have a website hosted by google drive, how do i connect to the site/server for sending/recieving data to the cc3000? All i have is the site URL..

    Thx anyway for great tutorial!
    Br

    Reply
  6. Phil
    Phil says:

    Great project and nice tutorial. Thanks for that ;)

    I jave one question. Do you think it’s possible to replace the cc3000 with a blietooth module and send the pictures to the computer over bluetooth?

    Thanks for reply

    Reply
    • Marco Schwartz
      Marco Schwartz says:

      Hello Phil,

      Interesting comment, that should be possible in theory! You would have to transmit the picture chunk by chunk using Serial.write() commands, and then reconstruct it on the server side. Let me know if you have any success with this!

      Reply
  7. umair
    umair says:

    helo sir.
    our project is ” wifii controlled robotic vehicle with live video transmisson.:
    is this camera is suitable for us?, or guide us which one we use here.
    thanks

    Reply

Trackbacks & Pingbacks

  1. […] Wireless Camera with Arduino and the Adafruit CC3000 breakout board. […]

  2. […] Wireless Camera with Arduino and the Adafruit CC3000 breakout board. […]

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">