We did this by choosing the smallest and fastest of the creatures in the typical backyard: the Hummingbird. Their speed provides a challenge to even the best of photographers. With our Arduino, we put speedy, motion-sensing photography into the hands of even the most amateur of photographers.
Our "Birdhouse" contains a DSLR camera, the motion sensor, and our Arduino. The Infrared Motion Sensor peers out and detects the hummingbird's motion. When motion is detected, the Arduino tells an Infrared LED to flash a pattern that mimics a camera remote control. This pattern tells the camera to take a picture.
Due to some limitations within the camera's programming, we had to add a few lines in the code that made it take a picture after 14 minutes of inactivity (to keep it from shutting off).
The camera contains an "Eye-Fi" SD card that uploads the images automatically via WiFi to a computer which then posts the photos to a Flickr account. (http://www.flickr.com/photos/97290453@N03/)
Our final code is as follows:
iint motion_1 = 2; //put the sensor on pin 2
int light_1 = 9; //this used to be pin 13
unsigned long timecheck;
void wait(unsigned int time){
unsigned long start = micros();
while(micros()-start<=time){
}
}
void high(unsigned int time, int freq, int pinLED){
int pause = (1000/freq/2)-4;
unsigned long start = micros();
while(micros()-start<=time){
digitalWrite(pinLED,HIGH);
delayMicroseconds(pause);
digitalWrite(pinLED,LOW);
delayMicroseconds(pause);
}
}
void take_picture() {
int _freq = 40;
high(2000,_freq,light_1);
wait(27830);
high(390,_freq,light_1);
wait(1580);
high(410,_freq,light_1);
wait(3580);
high(400,_freq,light_1);
timecheck = millis();
}
void setup(){
// This runs once on boot up. Put stuff here that runs at
// start up and then not again
pinMode (motion_1,INPUT);
pinMode (light_1, OUTPUT);
take_picture();
delay(1000); // allow motion sensor to settle down
}
void loop (){
if ( HIGH == digitalRead(motion_1)){
take_picture();
delay(5000);
} else {
delay(500); // wait a half second between checks of motion sensor
}
if (millis() - timecheck > 840000) { //14 minutes=840000
take_picture();
}
}
No comments:
Post a Comment