Using the Camera

Next up, we will wire the camera to our microcontroller (in this case an Arduino). This is pretty similar to the above except we will be using two digital pins and a software serial port to talk to the camera. To save images, you'll need some sort of external storage like our microSD breakout board.

Connect up the camera like this:
For the weatherproof camera, the white and green wires are swapped on some cameras! So please flip the white and green wires indicated if using the metal camera. Red should still be connected to +5 and Black to Ground
We suggest testing the microSD card first. Check out our microSD breakout board tutorial and verify that you can read from the card by listing the files. Once you have verified the microSD card wiring, you can come back here and install the VC0706 camera library.

Visit the Github repository here. To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_VC0706. Check that the Adafruit_VC0706 folder contains Adafruit_VC0706.cpp and Adafruit_VC0706.h Place the Adafruit_VC0706 library folder your arduinosketchfolder/libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE.

If you're using Arduino v23 or earlier, you'll also need to install the NewSoftSerial library. Download it by clicking this link and install it as you did the Adafruit_VC0706 library. Arduino 1.0 has this built in now (called SoftwareSerial)

Taking a Snapshot

OK now you're finally ready to run the snapshot demo. Open up the Arduino IDE and select File-> Examples-> Adafruit_VC0706-> Snapshot sketch and upload it to the Arduino. Open up the serial monitor and you can see the sketch will take a 640x480 photo and save it to the microSD card. You can then pop the card into your computer to see the JPG file
There are a few things you can change once you get it working. One is changing the pins the camera uses. You can use any two digital pins, change this line:
// This is the camera pin connection. Connect the camera TX
// to pin 2, camera RX to pin 3
NewSoftSerial cameraconnection = NewSoftSerial(2, 3);
You can also change the snapshot image dimension to 160x120, 320x240 or 640x480 by changing these lines:
// Set the picture size - you can choose one of 640x480, 320x240 or 160x120 
  // Remember that bigger pictures take longer to transmit!
 
  cam.setImageSize(VC0706_640x480);        // biggest
  //cam.setImageSize(VC0706_320x240);        // medium
  //cam.setImageSize(VC0706_160x120);          // small
Simply uncomment the size you want, and comment out the others. Bigger pictures will take longer to snap, so you will want to think about how fast you need to grab data and save it to the disk

Detecting Motion

A neat thing that the camera has built in is motion detection. It will look for motion in the video stream and alert the microcontroller (by sending a serial data packet) when motion is detected. IN this way you can save a bit of cash and skip on having a PIR sensor (although a PIR sensor will be better at detecting warm mammalian things).

Load up the File-> Examples-> Adafruit_VC0706-> MotionDetect sketch and upload it to the Arduino. It will take a photo immediately because it just turned on. Then wait a few minutes and wave you hand in front of the camera, it will take another photo.
You can turn motion detection on or off by calling setMotionDetect()
//  Motion detection system can alert you when the camera 'sees' motion!
  cam.setMotionDetect(true);           // turn it on
  //cam.setMotionDetect(false);        // turn it off   (default)
You'll need to 'poll' the camera to ask it when motion is detected, by calling motionDetected()- it will return true if motion was recently detected, and false otherwise.

Adjusting the Manual Focus

One last thing, the camera modules use a manual focus system - there's no auto focus. This can be good or bad. The camera comes with a far depth of focus which is good for most stuff. If you want to change the focus, we strongly recommend plugging it into a video monitor as shown above so you can see exactly how the camera focus looks. You can then lock the focus with the set screw
The version in the weatherproof housing is a little tougher to adjust but it can  be done by unscrewing the housing (it takes a few steps but its all easy to do) and then adjusting the focus before reassembly
Last updated on 2015-11-19 at 06.17.31 PM Published on 2012-07-29 at 11.58.38 AM