PDA

View Full Version : Homemade camera trap: Canon 40D + PIR + LDR + ATtiny 85 in Lunch Box



Oki_
02-02-2023, 02:20 AM
Hello camera trappers,

I am a newbie in camera trapping, but after my first successful capture, I decided to share my initial prototype with you. The major drawback of this setup is (for now), that the first photo wakes the flash (so its black at night), and the second photo is lit (and animal already scared :D) Hopefully, Yongnuo rf603 II wireless triggers will solve this issue. I will post update after I test them.

https://ondrejzvozil.sk/img/gallery/63d6c85cd266e8.46017294.jpg


The goal was "as cheap as possible" so I do not loose hundreds of € in case of being stolen. Another goal was to have it "as compact as possible" as I usually carry everything in backpack on a bicycle. The setup barely fits in the box and it is very unpractical - e.g. I have no acces to lens focus wing when in housing. Next time, I would not make small separate lens housing, but rather used larger box with glass window.



Housings & mechanics

Lunch box Tescoma FRESHBOX 3.0 l,
2-part design 3D printed sealed lens housings ("standard" and "ultrawide" for 8 mm ,
3mm thick standard "window" glass for lens housing, attached with silicone,
3D printed PIR sensor cover with adjustable circular shield,
Adjustable mini-tripod with ball head


427
430
428
429


Photo gear & Elletronics

Canon EOS 40D, Tamron 17-50 f/2.8, Rokinon 800 f/3.5 fisheye, Canon 18-55 f/3.5-5.6
Nikon SB-24 flash ,
cable from remote shutter,
TTL Hotshoe cable for remote flash connection,
PIR module HC-SR501
ATTiny85 programmable microchip
photoresistor LDR5516,
Mini step-down (buck) converter,
2x optocoupler PC817X3NSZW
2x 18650 3.7 V cells in series (7.4 V)

220 Ohm resistors, sockets, wires, PCB, ...

Custom trigger electronics is powered from li-on cells, using step-down converter to 3.3V. This voltage is directly supplied to 3.3V pin of PIR module, bypassing its linear regulator. OUT signal from PIR module is an input for ATTiny85, as well as signal from LDR to distinguish day/night conditions. The 2 outputs "focus" and "shutter" are connected via separate optocouplers to the remote shutter pin on the camera. The usage of ATTiny85 gives me the freedom of what to do after signal from PIR is received - e.g. to program my own shutter release sequence.

My original idea was to power camera & trigger from one li-ion cells. I tested it with dummy battery made of dead camera battery without cells. After I switched on electronics, camera shut off. After inspection, I find out that protection circuit is dummy battery is dead - no voltage on the output to camera. So it looks like camera needs to be galvanically isolated from camera.

432

Code
Some features:

ATTiny85 is in a deep sleep most of time so the power consumption is negligible (microAmps). It is only awaken when signal from PIR module is received, or after specified time has passed ("watchdog" interrupt)
adjustable day/night/day & night operation according to LDRState variable from LDR and condition in which it is used.
ability to wake camera/flash after certain time passes,
own custom photo-sequence, currently taking 3-4 photos in fast sequence ("H" shutter mode of camera)



The particular code I share only triggers the camera in darkness:


#include <avr/sleep.h>
#include <avr/interrupt.h>

const int pirPin = PB1 ;
const int LDRPin = A1 ;
const int focusPin = PB3; // OK
const int shutterPin = PB4;
const int focusInt = 1440 ; //Now in minutes..... Trigger focus every X minutes, in reality more
int watchDogCounter = 0;
int pirState = 0;
int LDRState = 0;
volatile boolean f_wdt = 1; // Global flag when watchdog is triggered
void setup() {
pinMode(shutterPin, OUTPUT);
pinMode(focusPin, OUTPUT);
pinMode(pirPin, INPUT);
pinMode(LDRPin, INPUT);
setup_watchdog(6); // 0=16ms, 1=32ms,2=64ms,3=128ms,4=250ms,5=500ms
// 6=1 sec,7=2 sec, 8=4 sec, 9= 8sec
delay(5000);
}

void sleep() {
GIMSK |= _BV(PCIE); // Enable Pin Change Interrupts
PCMSK |= _BV(PCINT1); // Use PB1 as interrupt pin
ADCSRA &= ~_BV(ADEN); // ADC off
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // replaces above statement
sleep_enable(); // Sets the Sleep Enable bit in the MCUCR Register (SE BIT)
sei(); // Enable interrupts
sleep_cpu(); // sleep
}

void wakeUp() {
cli(); // Disable interrupts
PCMSK &= ~_BV(PCINT1); // Turn off PB1 as interrupt pin
sleep_disable(); // Clear SE bit
ADCSRA |= _BV(ADEN); // ADC on
pinMode(shutterPin, OUTPUT); // Setting shutterPin as output again
pinMode(focusPin, OUTPUT); // Setting focusPin as output again
pinMode(pirPin, INPUT);
pinMode(LDRPin, INPUT);
}


void setup_watchdog(int ii) {

byte bb;
int ww;
if (ii > 9 ) ii=9;
bb=ii & 7;
if (ii > 7) bb|= (1<<5);
bb|= (1<<WDCE);
ww=bb;

MCUSR &= ~(1<<WDRF);
// start timed sequence
WDTCR |= (1<<WDCE) | (1<<WDE);
// set new watchdog timeout value
WDTCR = bb;
WDTCR |= _BV(WDIE);
}


ISR(PCINT0_vect) { // If interupt from PIR is detected
wakeUp();
}

// Watchdog Interrupt Service / is executed when watchdog timed out
ISR(WDT_vect) {
watchDogCounter++;
while (watchDogCounter >= focusInt*60) {
watchDogCounter = 0;
wakeUp();
f_wdt=1; // set global flag
}
}


void loop() {
pirState = digitalRead(pirPin);
if (pirState == HIGH) { // If PIR sensor is triggered
LDRState = analogRead(LDRPin);
if(LDRState<150) { // If there is not enoug natural light
digitalWrite(shutterPin, HIGH);
delay(650);
digitalWrite(shutterPin, LOW);
delay(3500);
}
} else {
if (f_wdt==1) { // wait for timed out watchdog / flag is set when a watchdog timeout occurs
f_wdt=0; // reset flag
digitalWrite(focusPin, HIGH); // Just for testing, should be focusPin
delay(150);
digitalWrite(focusPin, LOW); // Just for testing, should be focusPin
}
pinMode(shutterPin, INPUT); // Setting shutterPin as input - saves energy while in sleep
pinMode(focusPin, INPUT); // Setting focusPin as input - saves energy while in sleep
sleep();
}

}

I hope someone will find this post helpful or inspiring. I will be grateful for any suggestions for improvements! :)

-jeff
02-02-2023, 07:20 AM
Excellent. Beautiful image.

J Formstone
02-02-2023, 12:00 PM
Well done. Looks like a neat set up.

Oki_
02-04-2023, 10:09 AM
Did somebody edited my post? there was a long structured description of my setup and now there is just 1 sentence and images...

-jeff
02-04-2023, 10:14 AM
The only person that could change it is me. I didn't do anything.

Oki_
02-05-2023, 01:36 PM
This is very strange, I have no explanation for it. I am sure that it was published. Could you please look at database/backup? I should be somewhere, I really do not want to write it again :D Thanks.

-jeff
02-05-2023, 04:56 PM
The database backup is not a simple to read text file. It is a MySQL database file that I would need to restore. Not a simple process.

Murray
02-05-2023, 09:18 PM
That sucks. I am thinking of copying your design and a description would be helpful. That being said I was able to look up all the components thanks to the part numbers you provided. What I’m not understanding is the photoresistor.(bottom centre of your schematic) I’ve spent considerable time researching dslr trigger systems and I’m looking at minimum $500(Canadian) for a decent manufactured system and thats not including flashes, box…I did find a active laser system made by Catus for $280 but they have since closed so no support or warranty. Figure I could learn a new hobby and save a bunch of money. Thanks for posting your setup.

Oki_
02-08-2023, 12:17 PM
I just edited the original post. It is not so complex as before, but if you have some questions, I will try to answer it here. Hopefully, this time the setup description will stay longer :)

Jeesib
02-20-2023, 07:15 AM
Hi, great post. I am trying to make a set up like this, only instead of the Attiny I thought of using an arduino nano (although I just found out the arduino micro pro should using less power during "sleep").
I understand you only want to make pictures at night, as you are using the LDR5516?

Is there a reason why you directly connected the 3.3v power to the PIR sensor?

Furthermore, you complain the first picture is black, but in your setup you do have the focus, which should wake the camera and the flash (as far as I understand at this point)
I was thinking to first sent the focus signal, and then shortly after that the shuttersignal so the first picture will already be ok (but I have to test this as soon as my stuff arrives)

I will be using a Panasonic lumix G5, I have it already a long time and if it gets stolen, well too bad but no problem.
For the box I will be using a airtight food container which opens from the top, 4,5l so I hope it will be big enough.
Last question, I am very interested in the STL files for the 3D printed parts, can I download them somewhere?

Thank you for all your work and information here, very convenient and interesting.

Oki_
02-21-2023, 10:25 PM
Jeesib: Hi, thanks, I am glad that my post is helpful for someone. I will answer your questions, but regarding STL - they are not available anywhere, as it was just "first trial" and the fit of counterparts is not ideal. But if you are aware of it and want them anyway, I can upload them somewhere in next few days.

The Arduino will work fine as a logic for camera trap, but I found it to obig overkill in terms of inputs/outputs and of course power consumption. The LDR is just a sensor for determining the amount of ambient light. What is it used for depends on code. Yes, I only want to take night photos (as only wildlife approaches it at night) currently, but with small code modification, I am able to change that behavior. But I am not able to change its behavior in a field with current setup (I need a computer with Arduino IDE and shield for programming ATtiny). I carry pre-programmed day/night/day&night spare chips if I need to change its function in the field.

The reason to connect the 3.3V directly to related PIN on pin sensor is to bypass the linear regulator and to have only single power loss in step-down converter. So In theory, this option is more energy efficient.

Regarding first black picture - you are right, this could be solved with TTL cable that transfers both shutter and focus signal. Unfortunately, I would need to make custom cable to connect Canon camera with Nikon flash and I found this is more expensive than going wireless - with Yongnuo rf603 II wireless triggers, which support cross-brand wireless operation (transfers both shutter and AF signal from Canon device to Nikon device, etc.).

Regarding box, I seek for bigger (and still cheap) option, so I can fit also whole lens inside.

Jeesib
02-23-2023, 04:22 AM
Hi Oki,
Yes, if you don't mind, I would like the files as is. Just let me know where to download.

Till I read your post I never heard of the Attiny85, :D that is why I choose for the Arduino....
So, I will test with the Arduino, it is already on it's way. But probably for the real set-up, I will use the Attiniy85. I should be able to stay somewhere in the mountains for a long time (the longer the better).

Good choice for the Yongnuo triggers I think. saves you a lot of work which is sometimes the better option.

thanks for your answers anyway, very happy with it.

Oki_
02-26-2023, 03:49 AM
The first photo of a red fox motivated me to continue in this genre of photography. In addition to the fox (and about a dozen cats �� ), a neech marten occasionally visits the garden. I was not able to recognize any frequently used route - it always comes from a different direction. However, I saw on the camera footage that it often climbs on the wheels of old farm equipment. So I tried my luck at an old "rooted" Zetor, which although I've never seen it on, it is a photographically and compositionally interesting spot. When I looked at the photos two weeks later, I couldn't believe my eyes - it was there! :)

https://ondrejzvozil.sk/img/gallery/63fb06359c41e0.79540280.jpg

446

The setup in the field is still the same, but I gear up: I managed to get two SB-28s as well as Youngnuo triggers. I only need to make some external power source to the receivers so it lasts at least 2 weeks.

Jeesib: I uploaded all related STLs to my personal page:
https://ondrejzvozil.sk/uploads/files/camera_trap_STLs.zip
The password to unzip is "CameraTrapper"

Jeesib
02-26-2023, 09:37 AM
Ow wow, what a great pictures.
Yes, I woiuld love to have two SB28's my self too.
But first to make my test setup.

Thanks for the STL files, I downloaded them.
I will open a thread for my self with my plans.

-jeff
02-26-2023, 12:18 PM
Beautiful images. The setting with the old tractor is really nice.

jeremyw
05-29-2023, 07:10 PM
great shots! thanks for the write up on your kit.

strixaluco
06-30-2023, 02:16 PM
Really an ingenious project Oki, well done!