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
- There has to be an IR light – for night vision, and this also requires camera module to be IR sensitive (so no IR filter)
- 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 🙁 – this is some kind of design problem, because OV5640 camera is all the time powered with 3,3V (only lower voltages are disconnected) – more explanation and workaround later. 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.
Also, since most of the animals are active during night hours, there has to be some kind of illumination available. ESP32cam has bright LED builtin, but this (in my experience) could make board unstable and since it’s visible light, it will point to our trap from far away, so definitely not desirable. Because of that I started to use IR leds. This is another problem, because most of the camera IR lights are made for 12V. So either we need to add another step-up converter, or go with a custom design.
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. So If that’s what you want to “catch” (or small birds etc) – I would still go with PIR instead microwave. But you should probably use some better quality one, I’ve heard Panasonic has a good variety of PIR sensors. I’ve used sometimes called HC-SR501.
If not PIR then what? While searching for some other types 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. And there is no “scale” for it, it’s also 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. Also the temperature and surrounding environment is not without meaning, so this is quite troublesome device. I’ve managed to use it – but not every copy will be suitable. And you have to test it in usage condition – not at home only. In my case some examples where working flawlessly in large room, sensing even hand movement, but when used outside in low temperatures (I don’t know what was the main difference, if it was surrounding with open space and trees or temperature – so I mention both) it was barely registering at 30 cm distance. When replacing sensor to other copy, with the same sensing resistor value – it started to work, as it should.
Anyway, I’ll start now experimenting with directional sensor HB100 – perhaps, despite it’s few times more expensive and uses much more energy, it will be a better (more reliable) choice.
The code for the project you can find on my github project page.