Watch a Short (5 min) Video Introduction on YouTube
This is a firmware application written in C++ using Arduino and Adafruit libraries. It sleeps in low power mode until, activated by the motion sensor, it takes a picture. Images are posted to io.adafruit.com using the REST API.
I've long wanted to play with an automatic wildlife camera just for the fun of it. We have lots of deer in our neighborhood and this camera is intended to take pictures of them eating my wife's garden.
There's also the fact that this project uses a TTL serial camera that speaks the VC0706 protocol. Programming the device driver gave me the opportunity to learn how to command the camera to:
- Reset,
- Display the boot message and firmware version,
- Change baud rates,
- Change the JPEG compression,
- Take a picture, and
- Upload pictures.
Here's a list of all the parts that went into this project. (Some items were absent the day I took the group photo.)
- Weatherproof TTL Serial JPEG Camera with NTSC Video and IR LEDs
- FeatherWing Proto
- PowerBoost 500 Basic
- PIR (Motion) Sensor
- Lithium Ion Battery Pack
- Cable Gland PG-9
- Panel Mount 2.1mm DC barrel jack
- USB to 2.1mm Male Barrel Jack Cable
- 3.2" x 5.1" x 2.8" (80mmx130mmx70mm) ABS Universal Project Enclosure with Polycarbonate Transparent Cover
- PN2907A Bipolar Junction Transistors (BJT) - PNP General Purpose Switch
- Adafruit Feather M0 WiFi - ATSAMD21 + ATWINC1500
- Short Headers Kit for Feather - 12-pin + 16-pin Female Headers
- M2.5 Black Nylon Screw Set
- JST PH (2mm) 2-Pin Cable - Female Connector 100mm
- 10K Ohm resistor 5%
- Cinch straps
- Foam scraps, cardboard, hot glue, epoxy, #10 wood screws,
The electrical connections are shown below. The feather runs on 3.3V. Both the camera and the PIR run on 5V supplied by the PowerBoost. The PIR is always on. The camera is software switched on/off from PIN_A0.
I've found that the easiest method for mounting circuit boards inside plastic enclosures is to use plastic stand-offs and epoxy. Use small screws on the top and stand-offs below.
Clean all the parts thoroughly with rubbing alcohol and a clean cloth. To install, simply dab a little epoxy on the stand-offs and then set the part into the enclosure. Be sure you know where you want everything to go before you start gluing. Once you stick them in they're very hard to remove.
Place the battery into the enclosure as shown. The cord and the Feather's battery terminal must be on the same side or the cord won't reach. Cut a bit of cardboard to just sit on top of the battery. Cut off a corner to allow the cord to get by. Hot glue the cardboard to the sides of the enclosure.
Cut some scrap foam to sit on top of the battery. It should compress slightly when you attach the lid to the enclosure. The pressure should be just enough to keep the battery still without pinching it. Be gentle with it.
You will need to drill a hole in the enclosure for the DC jack. Ideally the hole should be just big enough to allow the jack to pass through. Seal around the jack with silicone sealant or bathtub caulk to prevent leaks.
Here's a close-up showing a bit of caulk around the DC jack.
Drill a hole in the enclosure for the cable gland. Ideally the hole should be just big enough to allow the gland to pass through. When you insert the gland into its hole it should sit on top of the o-ring provided. This provides a water tight seal.
Drill a hole in the enclosure for the camera mounting screw. Ideally the hole should be just big enough to allow the screw to pass through. The best fit will require you to use a screwdriver to thread the screw into the new hole. Be sure to place the hole far enough from the front that the camera can sit flat on top of the enclosure and swivel smoothly from side to side.
For the larger holes a step-drill really helps. This is what tradespersons use for this task. Unlike a twist drill a step-drill only removes a small amount of material at a time. If you must use a twist drill, make a series of holes stepping up through your drill library until you reach the final size. If you try to remove too much material at once the bit will bite hard into the plastic, get stuck, and jerk the drill out of your hand.
Once the DC jack is mounted, wire it up to the FeatherWing. The positive terminal of the DC jack is the one in the center. Connect this terminal to the USB terminal on the FeatherWing. The DC jack will feed the Feather to charge the battery. Connect one of the outer DC jack terminals to the ground bus on the FeatherWing.
Connect the FeatherWing's BAT and GND terminals to the JST PH 2-Pin Cable and plug that into the PowerBoost 500 Basic. If you order this part from Adafruit the pins will be in the correct polarity. If you got it elsewhere, be sure to check the polarity and correct it before use.
Cut off the excess cable on the camera. Leave enough extra on the inside of the enclosure that that you can remove the circuit boards with wires attached and not have to adjust the gland. Connect the green and white wires to TX and RX as shown.
Stow the brown and yellow wires (NTSC) away in the bottom of the enclosure. You might someday be able to stream this signal over WiFi for a LiveCam project so preserve them for the future.
Connect the red wire to 5V on the PowerBoost.
Connect the black wire to pin 1 (emitter) of the PN2907A. Connect it's pin 2 (base) to PIN_A0. Connect it's pin 3 (collector) to the GND bus. According to the datasheet, this transistor can sink up to 600 mA. That's more than enough to power the camera even with it's IR lights on. (Sink is another word for the place where current exits a system.)
Connect the PIR to 5V, and GND. Install a wire, or a pair of male headers with a shunt, on the EN and LBO pins. This will shutdown the PowerBoost when the battery goes low.
Connecting the PIR output to PIN_A1. Also connect a 10K Ohm resistor (not shown) from this pin to the second ground pin on the DC jack. Set the retriggering jumper on the PIR in the L position to prevent retriggering. Adjust the sensitivity to the low side of the potentiometer. If you're wondering why, I have two reasons. One, the camera only has a ten foot range in night mode. And two, when using the unit outdoors there's more variability in the background temperature and this allows for more (false positive) triggering. To learn more checkout this article. Adjust the time potentiometer to it's minimum setting.
The first time around I had the PIR motion sensor inside the enclosure. It was less work to put it there and being inside meant it would stay dry.
I soon discovered that the polycarbonate cover either absorbs or reflects IR light. (The sensor was blind.) So I drilled a hole in the cover and epoxied the IR dome into it.
Screw the straps to the back of the enclosure using the holes provided.
Strap the camera to a convenient tree and enjoy the pictures.
- Checkout the arduino branch of the project.
$ git checkout arduino
- Edit
src/motion_camera_secrets.hpp
and replace the placeholder text with your own secrets. - Try to build the project. If you get compiler errors like this:
undefined reference to 'std::ios_base::Init::~Init()'
and, a lot more saying undefined reference to something in the namespace std::
,
it means that the linking step couldn't find the C++ Standard Library. To solve
this, edit
${INSTALL_FOLDER}/Arduino15/packages/adafruit/hardware/samd/1.2.1/platform.txt
- Locate this line:
compiler.c.elf.cmd=arm-none-eabi-gcc
- Change the line to:
compiler.c.elf.cmd=arm-none-eabi-g++
You should now be able to compile and link without further problems.
- Checkout the platformio branch of the project.
$ git checkout platformio
- Create or modify your platformio.ini to include
[platformio]
; MacOS X / Linux
lib_extra_dirs =
${env.HOME}/path/to/your/Arduino/libraries
[common]
lib_deps_external =
[env:adafruit_feather_m0]
platform = atmelsam
board = adafruit_feather_m0
framework = arduino
upload_port = /dev/cu.your_modem_device
upload_speed = 115200
lib_deps =
${common.lib_deps_external}
build_flags =
'-DWIFI_SSID="Your WiFi SSID"'
'-DWIFI_PASS="Your WiFi password'
'-DAIO_USERNAME="Your Adafruit user name"'
'-DAIO_KEY="our secret AIO key"'
If you're like me and you'd like to keep your AIO secret key a secret then you'll want to connect to the AIO REST API using SSL. (All the code in this project assumes that you do.) To do that simply load the io.adafruit.com SSL certificate into the ATWINC1500. See these directions to learn how.
You may be wondering why the leaves and grass look gray. It's because the camera is particularly sensitive to infrared light. It has to be to work in night mode.
It's not polite to spy on people without notice. Be sure to let people know you're operating the camera and sending the pictures to the Internet so that they can use common sense when entering the area where the camera is active.