In my chicken coop I have builded a long pipe filled with grains, the chickens eat from the bottom. I figured I would install an ultrasonic sensor (HC-SR04) and measure the distance from the top of the pipe to the top of the grains. It’s not working well because the measured distances change
The problem is that when empty the sensor measures between 0.43 to 0.36 (big differences) when full it shows between 0.10 to 0.13 (the variation when full can be normal, as it can have a little more or little less grains, besides when full the variation is little, when empty the variation is bigger).
Also when half full, the sensor sometimes will change the measure, so it can show 0.25, and suddently a few minutes later (not chickens involved) it will show 0.20 and then later 0.24 or 0.26…
you see the pattern. It’s the first time I’m using an ultrasonic sensor, but it seems very unprecise measurements, so I wonder what I’m doing wrong. I played with the filters, but I don’t understand how to use them properly, so pretty sure it’s not okay.
Did you consider the time factor when you did your measurements? Your code outputs median of values over 7minutes.
Does it give better results if you set update intervals to 2s and window_size to 5?
Also, sensor’s wide beam of view will not work in narrow pipes, as it will get reflections from pipe walls.
I don’t understand well how it works for median and window size or stuff like that, what should I put to make it work better ? I don’t need readings very often, just a way to know when the food is getting low.
I have a couple different ultrasonic sensors for my sump pit and softer salt and the one’s I’ve tested are noisy like this as well. You can look into filters for esphome to try to get more consistant numbers, but it will delay changes.
It’s ok to have long interval and large window in final setup. But when you are testing it, it might be confusing since any changes to the level can affect the readings for next 7 minutes.
The problem I’m having it’s that the sensor gives me 0.43 and 10 min later 0.36 (it’s getting emptyer ? but it was already empty) and a while later 0.41 (what ?? it magically got filled up ???). There was no food in the tube all along…
so the sensor seems to be not acurate nor precise…
yes, well fixed in place, powered by a small usb phone charger, it power the wemos and the sensor with 5v. It’s outside and it’s cold (-2C today) well protected from rain and humidity, not exposed to elements. I have other HC-SR04, maybe I will swap the sensor itself in case it’s the sensor who doesn’t work well.