I am trying to to a research if my goal would be possible via ESPHome and ESP8266 MCU.
I would like to attach photoresistor to ESP8266 and measure ADC values (basically I need to measure accurately, how long the light source is ON). I would like to measure the duration, how long the value stays above some sort of threshold, i.e. like… if say we have 1024 max ADC value, I would like to measure, how long it stays above 800 before going down below 800. After the duration is determined, MQTT message will be published.
The problem is that I need relatively high accuracy (at least 0.1s and below). I need to measure durations starting from ~0.5s to roughly 10-15s. I would say that I need around 50ms sampling rate to measure durations accurately enough. I learned somewhere, that lambdas are executed at ~60Hz, but not sure, how that will work together with ADC readings.
Do you think it is plausible to implement this kind of logic?
Thanks for you suggestions. Actually I was not aware of Pulse Width Sensor and it seems interesting enough. But I do not understand how it actually works.
If it does have “update interval” of, let’s say, 60s, so what will it return if a given pin had multiple ups and downs within that timeframe? There is another sensor, Pulse Width Counter and I would think that it can, for example, return count of rises etc. within a specific timeframe, but how should this pulse width work, when it actually measures duration and can return a single duration as a result?
Not a solution, but, I’m testing something right now and with the ESP8266 connected to an AP I cannot go faster than 4ms between samples without some magic (250Hz). If it itself an AP, it can go a bit faster but I did not benchmark it yet. Only tested at 80MHz and without ESPHome.