Standalone photo recorder based on Arduino clone Adafruit Menta

Sometimes we need a small device detecting movement and making a snapshot in that time.
Here is a description how to build such device on Arduino.

Parts

Main component for our system is camera.
I found interesting exemplar – Weatherproof TTL Serial JPEG Camera with IR LEDs.
This camera has motion detection built in it. So we don’t need an additional PIR sensor.

As it is standalone system we need to store getting snapshots.
To store getting snapshots I use MicroSD card breakout from Adafruit.

We need to know when our system has detected movement and made a snapshots.
I use DS1307 Real Time Clock breakout board for that.

I decide to use Arduino clone Adafruit Menta as main module for this device.
It is compact and has a space for additional modules.

Connections

MicroSD is connected by SPI:

  • CLK to digital 13
  • DO to digital 12
  • DI to digital 11
  • CS to digital 10

DS1307 is connected by I2C:

  • SCL to analog 4
  • SDA to analog 5

Camera is connected to hardware serial (digital 0 & 1):

  • RX from camera through 10K resistor to TX on Arduino (digital 1)
  • RX from camera through 10K resistor to Ground.
  • TX from camera to RX on Arduino (digital 0)

Adafruit advises to use the 10K resistor divider: “the camera’s serial data pins are 3.3v logic and its a good idea to divide the 5V down so that its 2.5V”.

Wiring diagram shown in the following figure:

photofix

Source code

I use providing libraries to work with DS1307, SD and TTL Serial JPEG Camera.

To prevent storing all snapshots in root directory and easy navigation in this files, I create a directory in format “YYYYMM” where YYYY is a current year and MM is a current month.

For a filename for snapshots I use format “DDHHmm”, where DD is a day, HH is an hour and mm is a minute when snapshot was taken.

Here is a source code:

#include <Wire.h>
#include "RTClib.h"
#include <SD.h>
#include <SoftwareSerial.h>
#include <Adafruit_VC0706.h>

#define chipSelect 10

RTC_DS1307 RTC;
DateTime now;
char dirname[7];
char filename[18];
File imgFile;

Adafruit_VC0706 cam = Adafruit_VC0706(&Serial);

void setup() {
  Wire.begin();
  RTC.begin();
  pinMode(10, OUTPUT);
  SD.begin(chipSelect);
  cam.begin();
  cam.getVersion();
  cam.setImageSize(VC0706_640x480);
  cam.setMotionDetect(true);
}

void loop() {

  if (cam.motionDetected()) {

    cam.setMotionDetect(false); 
    if (cam.takePicture()) {
      
      now = RTC.now();
      snprintf(dirname,7,"%.4d%.2d",now.year(),now.month());
      snprintf(filename,18,"%.4d%.2d/%.2d%.2d%.2d.jpg",now.year(),now.month(),now.day(),now.hour(),now.minute());

      if ( !SD.exists(dirname) )  {
        SD.mkdir(dirname);      
      }

      imgFile = SD.open(filename,FILE_WRITE);
      if ( SD.exists(filename) )  {

        uint16_t jpglen = cam.frameLength();
        while (jpglen > 0) {
          uint8_t *buffer;
          uint8_t bytesToRead = min(32, jpglen);
          buffer = cam.readPicture(bytesToRead);
          imgFile.write(buffer, bytesToRead);
          jpglen -= bytesToRead;
        }

        imgFile.close();
      }
    }
    cam.resumeVideo();
    cam.setMotionDetect(true);
  }

}

It is also available here: https://github.com/vzaigrin/ArduinoPhotoRecorder

Realization

Here is an image of the soldered box:

SDIM4966

And here is an image of the camera on my country house:

SDIM4967

Some snapshots

A man:

05031431

A bird:

07061320

And even a butterfly:

08120633

Advertisements