People counting has a long history which I won't repeat here. There are several available solutions that can be purchased including those using IR emit/detect (so two devices required), cameras and AI (not cheap and cameras present a privacy concern), and even radar (also not cheap). The problem with these solutions is that they don't meet some or all of the (OK, my) criteria for a ubiquitous IoT people counter. Reiterating my ideal design specifications:
1) small and unobtrusive (say, 50 cc or less)
2) ultra low power so it can run on two AAA batteries for 2 years or more
3) inexpensive, say $40 or less BOM cost
4) connected via LPWAN (low-power wide-area network), either LoRaWAN or BLE 5.0
5) utterly reliable, meaning 100% no false positives or negatives
6) no cameras or imagers that might compromise people's demand for privacy (added to the list, but no camera-based technology can meet 2) and 3) anyway).
I am restricting the people counting I have in mind to a device that counts the number of ingresses and egresses at a portal. Some of the devices mentioned above might do other things as well and could be worth the cost, size, and otherwise be perfectly good products that deserve your attention for whatever use case you have in mind. But for the specific task of counting individual human ingress and egress events at a portal and sending the data via LPWAN to a smart device there are currently no solutions that meet the six criteria above.
This project's goal is to design and test such a device.
In order to reach the goal, the right choice of sensor(s) is going to be critical, so let's start there and consider some of the options.
First, in order to reach acceptably low power operation it is necessary that any sensors have an interrupt. This is because the optimal way to run a low power device is to put the MCU to sleep in an ultra-low power (~2 uA) state until woken up by an interrupt, either a timer interrupt or a sensor data ready or threshold crossing interrupt. So any MCU that lacks a state-preserving low-power mode (like the nRF52 and ESP32) can't be a candidate for this people counter. Any sensor that requires continuous monitoring by a host MCU must also be discarded. This rules out most analog sensors. And while there are a spectrum of remaining options, I seriously considered only four:
The AMG8833 is an attractive option since although it is technically a camera, it is simply not possible to identify anyone from their 8 x 8 pixel AMG8833 thermal image. So this allays privacy concerns. It has a range from 0 to 5 meters, so can easily detect people passing a portal. The fastest frame rate is 10 Hz, a bit on the slow side for people counting. The AMG8833 has the rather unique ability to generate an interrupt when a pixel exceeds a temperature threshold. Yes, that's right, this device has a pixel-specific interrupt. Once the user specifies a temperature threshold, the user can query after interrupt reception which specific pixel or set of pixels caused the interrupt condition. This is extremely useful for people counting, since typically the set of pixels on one side of the device will reach the threshold condition before the set of pixels on the opposite side of the device providing the directional information required for proper egress and ingress discrimination. We successfully developed a prototype using this sensor (which is an uber-kool sensor to play with in any case) but the Achilles Heel here is power consumption. Normal (continuous 10 Hz) mode uses 4.5 mA, standby mode (0.1 Hz, measure every 10 s and too slow for this application) uses 0.8 mA, and while there is a sleep mode for the sensor the lowest current draw is 200 uA. Ouch!...
Read more »
Kris, I appreciate your comments and concerns mentioned!
+ I will be glad to share my code with you once I get it to an "adequately working" condition. It is not nearly as elegant as your code, but will be working in my prototype (with RAK Wireless RUI3 based code for LoRaWAN communications to my ChirpStack Gateway).
+ Once I get my STHS34P80 parameters tuned with Fresnel lens in place, I can try with just a reduced aperture. My thinking is the Fresnel lens reduces the FOV while maintaining the full amount of photons to the sensor (hence the specified increased range which I do not need). Plus the lens acts as a "dust cover" over the STHS34P80 which has some benefit.
+ The "wishful thinking" of an ML approach is the ability to assess ingress/egress progression across the two sensors FOV beyond the "fixed" threshold for STHS34P80 "presence" determination or "fixed" parameters for the STHS34P80 filtering algorithm, hysteresis, etc. I can make the threshold for interrupt very sensitive and with enough training, the ML inference MAY be better at identifying motion thru the two FOV regions based upon the thermal values read from each STHS34P80, particularly as the environment background thermals vary ?
+ I've yet to wrap my head around how the STHS34PF80 ability to provide "motion" and "shock" detection might be used to increase accuracy; perhaps they may be usable to reduce "false positive" detections?
+ I don't expect the MCU to be awake too much longer for each ingress/egress event, with the STHS34P80 configuration and LoRa transmissions to still dominate the average power consumption. But as you mention, a Nordic Power Profiler evaluation will be needed to quantify. In my case 3 x AA or even 4 x AA or similar is a viable part of my design tradeoff decision.
Please continue to stay tuned...