Results 11 to 17 of 17

Thread: Homemade camera trap: Canon 40D + PIR + LDR + ATtiny 85 in Lunch Box

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Lightbulb Homemade camera trap: Canon 40D + PIR + LDR + ATtiny 85 in Lunch Box

    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 ) Hopefully, Yongnuo rf603 II wireless triggers will solve this issue. I will post update after I test them.




    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


    1675321028908.jpg
    1675321028960.jpg
    1675321028924.jpg
    1675321028941.jpg


    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.

    schematics.jpg

    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:

    Code:
    #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!
    Last edited by Oki_; 02-08-2023 at 12:15 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •