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:
Please note: This is under development and may not work as expected as I add new features.
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 time-lapse 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.
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.
This has been updated to a smaller RTC module (but samer IC) and also the solar charger has been added to a circuit board:
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.
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!
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.
Real Time Clock
I added a DS3231 real time clock module. This works through I2C, so I added the SCLK and SDA lines to two pins on the ESP32-Cam. I chose the wrong ones initially and it stopped the unit programming along with SD card! I used
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.
As we have WiFi on the module, I added a bit more code to send the photos to an email address. I followed this guide, again from Random Nerd Tutiorials.
I used the ESP32 Mail Client library by Mobizt.
I set up a new email account from which to send my photos (as you need to make it un-secure, don't use your normal email for this!).
I took AGES trying to figure out how to both use 1 bit mode for the SD card (and hence get more pins to control the LEDs and the I2C) but also use the mail client. It turns out this is quite easy. When you set up your SD card you can use the line " MailClient.sdBegin(14, 2, 15, 13) " rather than SD_MMC, which what I used before. This solved everything (but took several nights of figuring it out).
I designed a PCB for this and got some made up. I made a few mistakes, but eventually got it work, as shown here:
I have updated the PCB and schematic file in the github, but have not had any new circuit boards made yet. I'm going to develop a bit more with what I have until I know it's working OK.
Edit: Night vision is a bt difficult. It involves removing the IR filter from the ESP camera and then adding an additional IR cut filter, which I found a unit with simple cut in/out. I'll try and add this on my next version.
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:
There are still a few problems to iron out with this unit:
- 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.
- 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!
- Figure out adding IR and night vision to this.
Share this post