Mini Spy Camera

For this week’s project, I built a portable mini camera and In this guide, I’ll show you I how I built it. I think this is great for anyone looking to build a DIY project with a low cost camera. I’m using this to create time lapse videos but you could use it for all sorts of photo based projects.

The mini spy camera module has an integrated driver and is really easy to use without an Arduino or Raspberry Pi. The camera sensor can take 1280x960 photos and captures video at 480p. it's not an HD camera but it’s pretty decent for small projects. The module uses a microSD card to store data and it has a maximum support of 32GB.

Timelapse Photography

By taking a series of images, you can compose them together to create time lapse videos. When each photo is taken several seconds or minutes apart, slow things appear to be moving fast – Like these clouds flying by! I captured this timelapse by having the camera take a photo every 5 seconds. Normally, this is achieved with an intervalometer remote control. In this project, we're using an Adafruit Trinket micro-controller to act as the remote control to trigger the camera module.

Prerequisite Guides

We recommend walking through the following tutorial to get familiar with the components used in this project.

Parts

You'll need the following parts to build this project.

Tools & Supplies

The following tools and supplies will help you complete this project.

Project Expectations

This project uses a $12 camera module – It's not the best or going to replace a GoPro or the camera on your mobile phone. The image quality isn't fantastic, but it is suffice for most things. There are no adjustable camera settings, so everything is automatic.

If you're looking for a much higher image quality and adjustable settings, check out the Wearable Raspberry Pi Zero Camera build.

Camera Comparison

So how does the mini spy camera module stack up agaisnt some other projects / products? In terms of size, the mini spy camera is actually quite small. On the left is the GoPro Session, and the middle is our Wearable Raspberry Pi.

Wired Connections

The circuit diagram above shows how the components will be wired together. This won't be 100% exact in the actual circuit but it's a very close approximation.

  • Slide switch to Lipoly Backpack
  • VCC from Camera to 5V on Trinket
  • GND from Camera to GND on Trinket
  • BAT from Lipo backpack to BAT on Trinket
  • G from Lipo backpack to GND on Trinket
  • 5V from Lipo backpack to USB

Battery Power

The circuit will be powered by a 3.7V 100mAh Lithium ion battery via JST connection. The battery plugs directly into the Trinket Backpack, which allows the recharging over the microUSB port on the Trinket.

MicroUSB Trinket vs MiniUSB Trinket

Just as a warning, the enclosure was designed specifically to house the MicroUSB Trinket version. The MiniUSB Trinket might be too large to fit in the enclosure.

Getting Code Onto Trinket

Before we start disassembling or building the circuit, it's a good idea to get code uploaded to the micro-controller first. If you don't write / understand code, don't to worry! You don't need to be a programmer to be able to upload prewritten code :-) 

We'll walk you through the whole process. 

First, visit the Trinket tutorial page by clicking the button below. Follow the instructions to download & setup the Arduino IDE and install drivers.

Make sure you are able to get sketches compiled and uploaded, especially the blink example in the tutorial. Once you are comfortable with using the Trinket, you can continue!

Uploading Code to Board

Now that we have the Adafruit boards & NeoPixel library installed, we can get our code ready to upload onto the board. Select all of the code listed below in the black box and copy it to your clip board. Then, in Arduino IDE, paste it in the sketch window (making sure to overwrite anything currently there). Next, goto the Tools menu > Board and select Adafruit Trinket (if you're using the 3V Adafruit Trinket version use Trinket 8Mhz. If you're using the 5V Trinket, select Trinket 12Mhz). Now you can click on the "check mark" icon to verify the code. If it's all good, we can continue to upload the code to the board.

Connect USB Data Cable to Trinket

Be sure to use a micro USB cable that can transfer data - A USB cable that ONLY charges devices will simply not work. Plug it into the microUSB port on the Adafruit Trinket board and the USB port on your computer (try to avoid connecting to a USB hub). As soon as you plug it in, you'll see a red LED blink on the Adaruit Trinket - This let's you know the board is ready to except code. While the LED is blinking, click on the Upload button (It's a right arrow icon, next to the check mark). The Arduino IDE will notify you if the upload is successful and completed.

We've had issues with uploading code to the Trinket on a Mac with El Capitan – If you're running this setup be sure to use a USB 2.0 Hub. The issue is due to USB 3.0 ports on Mac hardware.
int trig = 0;
int led = 1;

void setup() {                
  // initialize the digital pins as output.
  pinMode(led, OUTPUT);
  pinMode(trig, OUTPUT);         

  digitalWrite(led, HIGH);  
  digitalWrite(trig, HIGH); 
}

// Hold HIGH and trigger quick (<250ms) LOW to take a photo. Holding LOW and trigger HIGH starts/stops video recording

void loop() {
  digitalWrite(trig, LOW);   
  digitalWrite(led, HIGH);
  
  delay(50);               

  digitalWrite(trig, HIGH);    
  digitalWrite(led, LOW);   
  
  delay(5000);               
  
}

3D Printing Enclosures

I drew up an enclosure in Autodesk Fusion 360 and designed each component so that I could design friction fit mounting points. I 3D printed the enclosure on several 3D printers to test tolerances (Printrbot Play, Flashforge Creator Pro, and Micro M3D).

If you don’t have access to a 3D printer, you could use a service like 3D Hubs to make it for you. I used PLA material to 3D print the parts, and they didn’t require any support material.

Slice Settings

Depending on your 3D printer, you may need to adjust the slice settings. I sliced the parts using Simplify 3D. They do not require any support material and are oriented to print "as is".

  • Nozzle: 0.4mm
  • Extrusion Multiplier: 1.0
  • Extrusion Width: 0.48mm
  • Layer Height: 0.2mm
  • Nozzle Temperature: 220c

3D Printing with Coffee!?

Yes, this enclosure was 3D printed with CoffeePLA, which is a special artisan's blend of HTPLA. Proto-Pasta "Heat Treatable" HTPLA Aromatic Coffee filament is easy to print with, and it smells like coffee when it's being extruded :-)

Enclosure Design Tutorial

For an indepth tutorial on how I designed the enclosure and components, you can watch my layer by layer tutorial.

Slide Switch Wires

I started off by making wires for connecting the slide switch to the lipo backpack. Most of the wires in the project are going to be pretty short, but it's OK if they're a little longer than necessary – You can always shorten them later. I suggest using 30AWG silicone cover wires because they're flexible and less prone to stress / breakage. 

Tin Switch Wires

Once I cut the two wires, I then used wire strippers to remove a little bit of insulation from the tips of each wire. With the bare wire exposed, I mounted them to a pair of helping third hands and tinned the tips by adding a little bit of solder – This helps prevent the strands of wire from fraying.

Connect Wires to Slide Switch

Then I soldered the two wires to the leads on the slide switch. We only need two of the three leads on the slide switch, so remove one (either the far left or right, but not the middle.) I recommend tinning the two leads on the slide switch before soldering in the wires – This helps the two connections stick together and adhere.

Cut Trace for Power Switch

Next, I needed to cut a trace on the Lipo Backpack to enable the power switch – By default the lipo backpack will always stay powered on. Cutting the trace allows a switch to power the circuit on and off. I used an X-Acto knife to scrape off the little trace that connects the two switch pins together. Make sure the trace is fully cut and the two pins do not have an electronical connection.

Connect Switch to Lipo Backpack

Now I can solder in the two wires from the slide switch to the Lipo backpack. The polarity of the wires and switch doesn't matter, so don't worry about wiring it in backwards.

Lipo Backpack Wires

We'll need three more pieces of wire for connecting the lipo backpack to the Trinket. These can be in different colors to help tell the connections apart. 

Tin Lipo Backpack Wires 

Again, I stripped and tinned the tips of each wire. I found it much faster if you mount all wires of the to one of the arms on the helping third hand. That way you can apply solder to the wires faster.

Connect Wires to Lipo Backpack

Now we can solder in the three wires to the pins on the lipo backpack – 5V, G, and BAT.

Connect Lipo Backpack to Trinket

With the wires now connected to the lipo backpack, we can then connect those to the Trinket. Connect 5V from the lipo backpack to USB on the Trinket. G (ground) from the lipo backpack goes to GND(ground) on the Trinket. Lastly, BAT from lipo backpack goes to BAT on the Trinket.

Trim Camera Wires Short

The wires from the camera module are a little long so I cut them short. Don't cut them too short, just enough to fit into the enclosure without too much excess. The three wires from the camera module have a little connector, it's OK to remove it – We won't be using it in the project.

Tin Camera Wires

Then I stripped and tinned the tips on each wire. Notice these wires are a bit more stiff than the silicone coated ones? Most wires are. Also, the coating is prone to warp when too much heat is applied to them, so be careful not to melt it too much.

Connect Camera to Trinket

OK, now we can connect the wires from the camera to the Trinket. Red wire from camera goes to 5V on the Trinket. Black wire from camera connects to GND (ground) on Trinket. Then, white wire goes to pin # 0 on the Trinket. The black wire (ground) might be tricky to solder in because we already have a connection here (from the lipo backpack). I recommend using a pair of tweezers to hold the wire steady while soldering it through the ground pin. I also found it helpful to simply remove the lipo backpack ground wire from the Trinket. Then you can solder the two ground wires together and connect them to the ground pin all at once. 

Test Circuit

Now that we have all of our wired connections made, we can plug in the 100mAh lipo battery into the lipo backpack. Depending on where the slide switch is set, the circuit will power on. The LEDs from the Trinket and camera will light up. Yay! Now we can start fitting the components into the case.

Install Components to Case

OK, now it's time to fit the parts into the case. You'll notice there's little walls inside the enclosure. These are mounting points for each component. Since each component is a different size, it should be easy to spot what goes where. I started with the slide switch, followed by the lipo backpack. Next the Trinket and then the camera module. The battery rests on the top of the Trinket. 

Installed Components

I found the cable from the battery a little bit too long, so I used a piece of heat shrink tubing to bundle it up. This made it easier to close the case.

Install Cover

Once all of the components are installed and mounted, we can place the cover over the enclosure. You'll need to orient the cover so the hole lines up with the camera lens. Also, make sure all of the wires are contained inside the enclosure. 

Case Snaps

The cover and case have little nubs on the edges that when pressed together, they snap together and "click" in place. This keeps the two parts together and prevents the cover from coming loose. It's a great way to make covers for enclosures without having to use screws or glue :-)

Case Ports

The case exposes all of the necessary ports like for the microUSB connector on the Trinket, the MicroSD card slot from the camera and the actuator from the slide switch. Nice!

Adjusting Intervals 

The code is set to take a photo every 5 seconds, but you can easily increase that value to take longer intervals. On line 24, you can change the value from 5000 (milliseconds) to whatever you want (too short of a value and it may not work).

Mounting to Tripods

The case doesn't have a built in way to mount it to a tripod, so I created a little 3D printed adapter that can connect to GoPro mounting accessories. It's a little "knuckle" that can be glued on the back side of the enclosure. Since I a lot of GoPro mounting bits, I thought I'd reuse them. This 1/4-20 GoPro adapter lets me easily mount it to any tripod. In this project, I'm using the standard GoPro tripod mount.

Creating Video Timelapses from Photos

The camera module simply takes photos and saves them to the microSD card. It can not generate a video from the image sequences, so you'll have to do that in a video editing software  (or a website if such exists). I personally use Adobe Premiere, but you can use whatever you have access to. I won't cover it in this tutorial, but I'm sure there are other resources that can help you there.

Dog CAM

Todd Treece mounted the camera to his husky/malamute k9 friends using a hardness and GoPro adapter. Fun idea to capture your walks :-)

Low Battery

The 100mAh lipo battery will power the circuit for about an hour. I know it's not a lot of time, but was suffice for me. I was able to capture 15 second timelapses using a 5 second interval. You could obviously add a bigger battery for longer time lapses, but that would require a bigger case. My main goal was to keep it small and make the smallest enclosure I possibly could. That's why I added a lipo backpack to the circuit so I could at least recharge the battery easily.

This guide was first published on Jan 30, 2017. It was last updated on Jan 30, 2017.