Menu
Cart 0

Prototyping a Wildlife Camera

Posted by Matthew Little on

This blog post covers the main design choices and prototyping stages from developing a wildlife camera unit. I had seen the ESP32-CAM, which is based on the ESP32 wifi module. It's incredibly low cost and does some amazing things (including face recognition) with the example code other people have written.

I got hold of a couple of samples and thought they would be perfect for a low-cost, solar powered wildlife camera which might be useful in lots of applications. This post covers the work I did on firmware design and PCB design for the unit. I am hoping to have these in my shop sometime soon after a bit of field testing.

All of the code and PCB design is available in this open-source github repository:

https://github.com/curiouselectric/Wildlife_ESP_Cam

Please note: This is under development and may not work as expected as I add new features.

Firmware design

The first thing was to look at using the ESP32 with the Arduino IDE. There are lots of websites with information to get you started. Some websites that helped me were:

I would say that the Random Nerd Tutorials have been the most help and are the best starting point if you are interested in this kind of project.

One of the most annoying things with the EXP32-CAM is that it does not have a USB-Serial converter on-board. I assume this is for cost savings. You can use a USB to serial converter, along with adding a jumper to put the unit into programming mode when it starts up. This is a bit of a hassle so I invested 12 whole Euros in the cam-prog from bitluni on Tindie. This has the USB to serial converter on a nice header board. It also has an automatic reset so that you don't need to press the reset button after programming. This makes everything nice and easy, so I would recommend getting one from bitluni. 

This all got me to the point of uploading code to the ESP32-CAM. Uploading the ESP32->camera->cameraWebServer example through the Arduino got a pretty usable webcam which also had face recognition that worked pretty well! Amazing for just a few ££.

I looked around and saw that there was a huge variety of 'trail cameras' available. Most seem set up for hunting (which I'm not really into), but they also seem to be good for wildlife monitoring as well. They are available ready-made for prices from around £30 up to £400.

I wanted a slightly hack-able version with lots of features, but at a lower price point. I also like DIY kits, so this would be a DIY system, with through hole components as much as possible.

I developed my version of the code to achieve the following specifications:

  • Must react to a PIR trigger
  • Must react to an external switch input
  • Can be set to do timel-apse photos, if required
  • Flash can be set on/off
  • Unit will be in sleep mode most of the time to conserve power
  • Unit is solar powered with a li-po 18650 cell
  • Unit must be easy to configure in the field with no code upload required.
  • Timestamp added to photo file

I almost have all of that working now, please check out the github repository for the code, which hopefully has explanations of how it works.

Settings file

I developed the code so that, when the unit wakes up, it looks for a "settings.txt" file on wake up. From that file the unit can be configured.

The settings are:

  • FLASH_FLAG - Use a flash with the photo? (0 (OFF) or 1 (ON))
  • NUMBER_PHOTOS - How many photos to take when waking up?
  • TIME_TO_SLEEP - How long (in seconds) between wake-ups (when in SLEEP mode)
  • MODE - The mode to use is either SLEEP (wake up every TOME_TO_SLEEP seconds) or TRIGGER (either wake up on PIR trigger or external trigger)
  • PHOTO_DELAY - delay (in milli Seconds) between taking the photos.
  • FLASH_START_DELAY - Flash will switch on then wait this time before taking photo (in milli Seconds)
  • FLASH_STOP_DELAY - Flash will be on and wait this time after taking photo (in milli Seconds)
  • DEBUG_FLAG - See debug info on serial port (0 (OFF) or 1 (ON))
  • DEBUG_PHOTO - See debug info on serial port (0 (OFF) or 1 (ON))

This allows for multiple configuration settings. If there are no settings uploaded then the defaults (programmed into the unit) are used.

Real Time Clock

I added a DS3231 real time clock module. This is read using the I2C interface. Some pins have to be shared with this line, so eventually I found that using GPIO14 and GPIO15 worked as the I2C interface when configures with the "wire.begin(I2C SCL, I2C DAT)" line. Please check the code for the details on this.

One thing I still need to implement is how to configure the time. At the moment I set the RTC clock time directly using another sketch then use the RTC module in my circuit.

There is an annoying red power LED on the RTC module I used. This needs to be removed to save a bit of power, as every mA matters when things are solar powered!

The RTC module can be seen in this photo of the prototype, along with the repurposed solar 18650 charger PCB I used below.

Triggering

I wanted the unit to wake up either with a sleep timer, so that it wakes up at regular intervals, or with an external trigger. The external trigger happens on GPIO13.

PIR

I wanted to use a low cost PIR sensor to trigger the unit when a moving heat source goes by. Most of the PIR sensors I found work at 5V but not at 3.3V. Eventually I found the AM312 module which is designed to run at 3V so will work with the 3.3V I have available.

You can adapt other PIR modules to work at 3.3V by bypassing the regulator, but I din't want that hassle!

External

I also added an input to run the camera from an external switch input. This is buffered through a transistor. There is also a push switch to trigger this, so you could make your own little photo booth!

This switch input could be used to trigger the camera, say when a trap or external detector has been set off.

Night Vision

The last thing I wanted for the camera was to run some external LEDs to add to the flash capability. This can be done by taking an output from GPIO4 (which controls the on-board bright white LED) and using an external transistor to run even more LEDs. This worked perfectly for adding a 3W white LED to give an even brighter flash (the on-board LED is pretty darn bright, though).

I also needed to check if the camera would react to infra red (IR) light, so I could then do some basic night vision.

I ran a bank of 950nm IR LEDs from the power supply to trigger along with the flash. These were picked up by the camera, so I think it does react quite well to IR light. At the moment a bank of 4 IR 940nm LEDs does not give a very bright image, even when run at high current.

I am ordering some more ultra-bright IR LEDs to add to this and test. It might be that many more IR LEDs are required to produce the brightness required. This needs more testing - any input useful, if you can comment!

I tested the unit by putting it all in a cardboard box and triggering the camera (with the flash white LED covered in tape.

There are two main wavelengths for infra red LEDs, 850nm and 940nm. As 850nm is closer to visible wavelengths then they sometime have a visible red/purple glow, whereas 940nm LEDs cannot be seen by humans.

I read that most cameras are sensitive to 850nm, but fewer are sensitive to 940nm.

Also, with most cameras there is an IR filter on the lens. This blocks the IR so that the unit works well in daylight, but means that it is not sensitive to the IR light for night vision. I found this very useful post on removing the IR filter from the ESP32-CAM: https://marksbench.com/electronics/removing-ir-filter-from-esp32-cam/.

So it seems that there will have to be two options - a daylight version and an IR version. I'll try one with the IR lens removed.

Here are some more links for using the ESP32-Cam with IR for night vision:

I have added an electronic controller IR cut filter. This mechanically adds an IR filter to the camera. It requires an H-bridge power control circuit to reverse the applied voltage to the IR cut filter unit. This needs two more digital pin to control the filter, with the pins set high-low or low-high to set or remove the filer. When the filter has been set then these pins can be left floating. This might be more pins than we have available on the ESP32-CAM unit. This needs more work!

    Solar Power

    I had already designed a 18650 li-po battery charger using the BQ24210 from Texas Instruments. This IC can take a solar PV panel input voltage from 4.5 to 18V DC and recharge a single lithium-polymer cell (such as the commonly available 18650 cells) with up to 800mA. This can give up to 2.5W into the battery, so a maximum of 2.5Wp solar PV panel should be used. I had some 1W panels so have rigged that up to work with the prototype.

    Problems

    There are still a few problems to iron out with this unit:

    1. I keep getting a camera vsync error, maybe every 1 in 10 times the unit wakes up. I am unsure why this is. I have read that it could be related to the ESP32-CAM unit I have, as some are 'a bit dodgy'. I'll check it out and record this to an error file to see how often it is happening.
    2. I need to sort out the IR LEDs and make sure they are bright enough for relatively good quality night time images. - Actually need to remove the IR filter.
    3. I need to sort out how to program the unit with the correct time and date. I'd like to do this without having to upload code.
    4. I need a nice, low-cost and waterproof enclosure for the unit. Most I see have camouflage covering as well, which would be a nice touch!

    Share this post



    ← Older Post Newer Post →


    2 comments

    • Hi Paul,
      Thanks very much for the comment and the links and information.
      I think this could be useful for lots of applications, especially for the price!
      I do have a microwave radar unit to play around with as I have also had problems with the triggering of PIRs. I’ll keep this page updated with any tests and info.
      It would be really intereting to add the AI element to the system – I was amazed by how good the face recognition was for the ESP32-cam out of the box!
      Best regards,

      Matt

      Matt on
    • I really like what you are doing here.

      There is an enormous amount of effort going into AI and wildlife cameras for good, y’know, conservation, anti poaching etc.

      This project should really get picked up by them.

      I don’t want to pull you off track when you are clearly full-tilt into this, but I’m having pretty good results with RCW-0516 microwave radars (https://github.com/jdesbonnet/RCWL-0516) instead of PIRs, they are really cheap.

      Take a look also at Andreas Spiess’ efforts to find the best performing ‘super power’ project https://www.youtube.com/watch?v=-SJbdPvgQnE and corresponding discord channel https://discord.com/invite/dCr86Hk – single battery, low power, solar charging. He’s got together some known low power designers there from what I’ve seen (@burgduino)

      Paul Geraghty on

    Leave a comment

    Please note, comments must be approved before they are published.