Page 1 of 2 12 LastLast
Results 1 to 10 of 17

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

  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.

  2. #2
    Administrator -jeff's Avatar
    Join Date
    Jan 2018
    Location
    Nebraska!
    Posts
    280
    Excellent. Beautiful image.

  3. #3
    Member
    Join Date
    Sep 2020
    Location
    United Kingdom
    Posts
    115
    Well done. Looks like a neat set up.

  4. #4
    Did somebody edited my post? there was a long structured description of my setup and now there is just 1 sentence and images...

  5. #5
    Administrator -jeff's Avatar
    Join Date
    Jan 2018
    Location
    Nebraska!
    Posts
    280
    The only person that could change it is me. I didn't do anything.

  6. #6
    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 Thanks.

  7. #7
    Administrator -jeff's Avatar
    Join Date
    Jan 2018
    Location
    Nebraska!
    Posts
    280
    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.

  8. #8
    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.

  9. #9
    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

  10. #10
    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.

Posting Permissions

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