ESP32-Cam based photo trap
So, we meet again – with esp32-cam board . My first encounter was rather disappointing. I’ve tried to used it for streaming, and the image was poor quality (OV2640) and what is more troublesome, the board itself was unstable.
Recently I had a need, for some kind of Photo Trap – to see what animals are finding food (that we left for them) close to my land. It could be moose or some kind of deer. Of course I could buy one, but where is the fun in it – and it would be probably much worst. The one I saw was old type, powered with four AA batteries etc. but it had also cellular modem used to send MMS with picture in 21 century.
So ESP32-cam board is back again on the table. Quick idea for the devices is to use Li-ion battery (I’ve ordered some time ago few 3Ah Huawei batteries from disassembled phones) with some BMS for it, boost board to get 5V (ESP32 requires 3,3V, but camera requires 4V+, also the sensor can be quite picky here) of course ESP32-Cam with OV2640 (later I’ve upgraded to OV5640) camera and some kind of movement sensor.
Since power part is kind of easy – I’ll skip it now. Lets focus on movement sensor. My first approach was with PIR sensor, that was laying around in the box. It was working, while testing it at home. But when I’ve tried to utilize it outside, and it happened to be snowing that day – I had it triggering all the time. No matter what sensitivity I set up on it. So back to the desk, and I’ve found a bunch of microwave sensors on Aliexpress. Quick study and I’ve chosen RCWL-0516. There is a great deal of information on this topic, on Joe Desbonnet github page. This sensor has also a lot of problems – but I think I’ve manage to tame it.
For the software part… there are some code examples on the net, and I’ve used one as a base for my project (details on github), but it was just a draft and not exactly what I needed.
Having introduction done, let’s get to details!
So what I needed?
- battery powered and possibly long lasting (in days, not weeks) device – this automatically excludes all the camera motion sensing and image processing where ESP32 would have to be working all the time
- possibly small enclosure and quite weather resistant
- since it’s forest (branches, leaves, rain, snow) – motion sensing should not be prone to it
- best possible quality of photos
- I don’t have any WiFi there – so no need for communication, just SD card
- I want to know when something has happened – so I need some kind of clock
- I should be cheap – mostly because I can’t protect it. It’s a forest, and it’s not gone be easy to find, but it’s also still a public place.
In addition, to those initials requirements, what occurred to me later:
- There has to be some kind of feedback interface, what’s going on on the device
- We need easier way to upgrade firmware, then to take it home and disassemble (ESP32Cam does not have build-in USB interface).
ESP32Cam (as a whole) uses roughly 100mA @ 5V when powered on (with WiFi) and 200mA when working with camera. So this gives us 500mW to 1W. Quick calculation shows, that with even large 3Ah cell phone battery (its nice and easy to fit those batteries in cases, and it’s cheaper then 18650 in most cases) – that is rated as 13Wh, would last for 13 hours with full streaming. And this is without looses for step-up to 5V. Of course we do not need WiFi all the time or at all. But still rough estimation, if use image analyze to sense movement, would made whole device last only for a day.
As I mentioned earlier, ESP32 requires 3,3V. But camera and sensor requires a bit more (around 4V) to work stable. Battery should also be protected with BMS (both for overdischarge and overcharge). And both sadly will drain our battery constantly.
When tested, device uses around 1,2-1,5W while working and 0,56W during sleep with OV5640 and 0,032W with OV2640. So standby power is rather severe with OV5640 :(. The boost-up and BMS consumes around 0,1W.
In terms of power, you should also be aware that microwave sensor is extremely sensitive to power supply. Best course of action would be isolate completely from other devices with (for example) DC-DC isolated B0505S. But this would required also some optocoupler signal transfer. I’ve tested this solution, but reverted back to direct connection and isolated interference as much I could with shielding and capacitors.
Movement detection sensor
Quite straightforward solution would be to install PIR sensor (IR sensor) – and this is what I did. During testing it worked ok, as expected. I could change sensitivity, to some extend, and trigger window period.
During the tests I’ve found that in some condition, the PIR sensor could be triggered even by a small mouse. If that’s what you want to “catch” (or small birds etc) – I would still go with PIR. And of course probably we could have different sensors, perhaps with better qualities (I’ve heared Panasonic has a good variety of PIR sensors). I’ve used sometimes called HC-SR501.
If not PIR then what? While searching some type of movement sensors, for my home automation system, I’ve found devices that combines PIR and microwave sensors – I haven’t found such a device for makers – but still there is a lot different microwave sensors available.
After some investigation I’ve ordered RCWL-0516 sensor and started to tinker with it. This is quite ingenious device, but since it’s not a real sensor by design its hard to predict all behavior conditions. Although you can change its sensitivity with additional resistor, but together with it you will also change it’s sensing distance. But there is no “scale” for it, and it’s heavily dependent on specific copy of the device. For example, when testing on desk RCWL-0516 it had few meter sensing distance, but when tied to tree close to the ground, it was triggered on distance 20cm only.
The code for the project you can find on my github project page.