Animal motion detection : an Arduino project for photography

Hungry (angry?) pigeon
A real angry bird.

I'm going to talk to you about a simple, yet fun project I did last year : an animal detection device that could control my DSLR and take pictures.

I thought that it would be a fairly simple thing to do with Arduino and a motion sensor. I chose to use an IR sensor because they are very cheap and efficient, and bought the PIR sensor from parallax. It just has a single bit output, so it's super simple to use with an Arduino. It is very sensitive and fits well this application. The only bad thing about it is that it has an incorporated LED that turns red every time a motion is detected, which is probably useful for most use cases, but not in my situation πŸ˜€ I just cut the circuit track leading to the LED so it wouldn't turn red anymore.

Motion detection on Arduino
The motion sensor and its 3 pins : The one bit output, VCC, and GND.

Once we have the information about whether Β a living thing is in front of the sensor or not, we need to control the camera to trigger it. This part really depends on what kind of camera you own, if it can accept a remote control or not. If it doesn't, one way to trigger it is to use a servo motor to press the shutter button (with the Arduino Servo library), but the problem might be the noise it generates when moving, which could scare the animals. My DSLR ( a Β Canon 550D) has a jack input for remote control which makes it really easy to command. What you will need is a standard 2.5mm stereo male jack, some wires and that's it!

Canon Remote Controller Wiring (2.5mm mini-plug and N3 plug)

You just need to solder the 3 wires to the jack connector. One for the ground, one for the focus command, and one for the trigger command. To focus, just put the focus contact to the ground; and it works the same way to take a picture.

So how to control the camera with an Arduino?

We will use two digital ports of the Arduino to control trigger and focus of the camera. When these outputs will be set LOW, they will fire the action they are supposed to create (focus or trigger). When set HIGH, nothing will happen. To protect the camera, you should put a resistor between the outputs and the camera (I used 2.2K resistor) just to make sure no current goes into the DSLR.

The final schematics look like this:

The very simple schematics of the breadboard circuit. The LED is simply there to control if everything is working (on when something is detected). You can click for the full size image.
The very simple schematics of the breadboard circuit. The LED is simply there to control if everything is working (on when something is detected). You can click for the full size image.
Motion detection on Arduino
The real life schematics πŸ™‚

The program will be pretty simple too : if something is detected, take a picture and turn on the control LED πŸ™‚

Here it is:


#include <Camera.h> // The Camera library makes it easier to control a DSLR

/********PINS*********/

int PIR_Pin = 3; //the digital pin connected to the PIR sensor's output
int LED_Pin = 2;
int focusPin=6;
int shutterPin=7;

/********VARIABLES****/

int idletime =0; // The time since last picture
int lastshot=0; // The millis() when the last picture was taken
int burstInterval=5000; //The time between pictures when motion is on
int calibrationTime = 30; // The sensor calibration time (so we don't get false positives when we start the Arduino up)
long unsigned int lowIn;//the time when the sensor outputs a low impulse
long unsigned int pause = 2000;// The time necessary for the motion to be gone after the sensor has gone to a LOW state
boolean lockLow = true; // goes to false when a motion is detected
boolean takeLowTime;
boolean burst=false;// burst mode indicator
Camera* eos; // a pointer to our DSLR

void setup()
{
 eos =new Camera(focusPin,shutterPin);
 Serial.begin(9600);
 pinMode(PIR_Pin, INPUT);
 pinMode(LED_Pin, OUTPUT);
 digitalWrite(PIR_Pin, LOW);

 //Sensor calibration
 Serial.print("Calibrating sensor ");
 for(int i = 0; i < calibrationTime; i++){
 Serial.print(".");
 delay(1000);
 }
 Serial.println("SENSOR READY");
 delay(50);
}

void loop()
{

 if(digitalRead(PIR_Pin) == HIGH){ //If a motion is detected
 if(idletime>30000){ // If the camera is in sleep mode
 (*eos).TriggerFocus(); // wake up the camera
 idletime=0;
 }

 digitalWrite(LED_Pin, HIGH); //signal that a motion is detected
 if (burst){ //Once the motion has been detected and a picture taken, we go into this mode to keep taking pictures every 5s until the motion ends
 delay (burstInterval);
 (*eos).TriggerShutter();
 lastshot=millis();
 idletime=0;
 }
 if(lockLow){
 lockLow = false;// We enter in "motion" mode
 (*eos).TriggerShutter();// We take a picture right away
 delay(1000);
 (*eos).TriggerShutter();// We take a second picture 1s later
 delay(2000);
 lastshot=millis();
 idletime=0;
 burst=true; //Now we go in burst mode,ie picture will be taken every 5S
 }
 takeLowTime = true;
 }
 if(digitalRead(PIR_Pin) == LOW){ //If mothing is detected
 digitalWrite(LED_Pin, LOW); //Turn off the LED
 if(takeLowTime){
 lowIn = millis(); //save the time of the transition from high to LOW
 takeLowTime = false; //make sure this is only done at the start of a LOW phase
 }
 idletime=millis()-lastshot;
 burst=false;

 if(!lockLow && millis() - lowIn > pause){ // If there has been more than 2000ms inactivity, we exit the motion mode
 lockLow = true;
 }
 }

}

The Camera library is included in the project. It is a very simple library that avoids you to code the boring stuff (like setting LOW the trigger output, then HIGH again etc πŸ™‚ )

To host the electronics and the camera, I built a wooden box big enough to put everything in easily, with a lid so It could be weather resistant. Here are the pictures

Motion detection on Arduino
You can see the PIR sensor, and a layer of tape around it. The goal is to make its FOV a bit narrower, so it only fires when the animal is in the camera frame.
Motion detection on Arduino
I used an old remote control from a broken RC helicopter (RIP πŸ™ ) to power the Arduino. You can obviously put anything you want in here ( staying in the 7-12V range is recommended )
Motion detection on Arduino
Top view of this masterpiece of engineering.
Motion detection on Arduino
The camera is held here with its tripod mounting hole. You can also see the stereo jack.
Motion detection on Arduino
The lid. The foam layer is there to protect from the rain.
Motion detection on Arduino
The whole thing, with the 550D and the Sigma 10-20mm. The bungee cords can be used to set the device in a tree.

This is obviously far from being perfect, the DSLR shutter noise scaring most of the animals away after the first picture, and the size and weight of this thing making it hard to place anywhere you'd want πŸ˜€

On the other hand, it does work pretty well and can take some fun pictures.

Cat eating a pizza

Hungry birds.

Hope this can give little help to those of you looking for ways to photograph animals πŸ™‚

New videos/ photos. When a drone goes 250m high

Hi everyone!

I created a new album on my flick'r account : Drones and stuff. I will try to update it frequently with pictures of everything we do πŸ™‚

Our quadcopter
Our quadcopter

We also posted 3 new videos on Youtube:

A FPV flight where we reach 250m of altitude with our quadcopter

[youtube]http://www.youtube.com/watch?v=GxX-b6REVtg[/youtube]

A peaceful flight near Saint-Benin, France.

[youtube]http://www.youtube.com/watch?v=_EMD8Hvcxsg[/youtube]

A little "ad" for multicopters πŸ™‚

[youtube]http://www.youtube.com/watch?v=muKquqGi12Y[/youtube]

More to come soon πŸ™‚

The octocopter

One of the first flights
One of the first flights

We recently built a brushless gimball for our Gopro but our quadcopter became too heavy to fligh safely, so it was time to get something bigger. We first thought about a nice hexa, but we couldn't resist to the appeal the octocopter. We wanted to get enough power to carry a lightweight DSLR such as my 550D, or simply all the FPV equipment we have, plus our Gopro on its brushless gimbal; all of this with a 10 minutes autonomy.

It all went so fast. Add to cart. Pay. Bam, it's delivered. We chose this time not to build the frame ourselves, just to put everything together, and have fun.

The Hobbyking X930 895mm glass fiber frame.

We bought this big and cheap octocopter frame from Hobbyking, the X930. The arms are in aluminum and the rest of the frame is made with pretty thick glass fiber.

[notice]THE MOTOR MOUNTS ARE VERY WEAK.[/notice]

If you look at the comments on Hobbyking's website for this frame, you will see that many people (including us) broke several of them while flying. So don't even try to fly with them, they will eventually break. We reproduced these motor mounts in aluminum with our CNC and mounted them under the original ones to get Β rock solid motor mounts.

Turnigy 3536 910kV
The Turnigy 3536 910kV motors mounted with 12x4.5 props. You can see the CNC milled aluminum motor mount under the original one.

The Turnigy 910kV motors provide plenty of power to lift anything you'll throw at the octocopter. They are controlled by 40A controllers (Turnigy Plush 40A), which are fed by an octocopter power board.We use two 3S 5000mAh batteries in parallel to reach our desired autonomy.

Our octocopter power stage
The power board and the 8 ESCs.

Be careful with this board, it is only certified to deliver 8x10A, which is really low (our motors can take up to 35A). We chose to add a lot of solder on the PCB in order to increase the amount of current it could deliver and it seems to be working fine so far.

We flashed our Ardupilot with the latest octocopter firmware and tried to find the best PID values for the octocopter. It does fly pretty well now but there is definitely room for improvement.

Our octocopter
The "command" part of the system.
Our octocopter
Ready to fly. (Yes, we broke one prop so we replaced it with a 9x4.7 :D)

We'll try to fly FPV with it as soon as we can with our new new brushless gimbal (article to come πŸ™‚ ) and we will obviously post videos of it here and on YouTube on our channel.Β 

We'll be back soon πŸ™‚