Close

Ultrasonic ping-pong

A project log for Internet of Trash

Trashcan sending the data to the internet!

tomislav-mamiTomislav Mamić 08/23/2016 at 11:120 Comments

All this time we were busy getting the system to work, making it light on battery usage, making it presentable to our clients - so much so that we kinda forgot to delve deeper into the problem of ultrasonic distance measurement!

When one thinks about it, possible problems are blatantly obvious - sound is a wave and waves bounce and interfere. There may be multiple paths your sound ping can take in a given environment, and you may or may not measure the one you'd actually want to.

After messing around with the sensors a bit, we found two critical problems, and a blessing in disguise.

Problem 1: Some sound paths may take quite a long time to hit your sensor. Thinking about it, one can say "Well why is that a problem if I only want the shortest one (the one directly in front of the sensor?" and be completely right.... If all you want is one measurement. But what if you don't trust your sensor completely, so you'd like several measurements to gauge reliability? Well, what happened to us was, we were trying to get multiple measurements too fast one after another. So fast in fact, that the next measurement would occasionally catch an echo of the previous ping and, obviously, return nonsense. This was easily fixed simply by increasing the time delay between individual measurements. Since we're not dealing with a particularly fast process, we can afford to take our time checking the trash cans.

Problem 2: Reflection. We used a hard cardboard box as our target for measurements. When sending the wave perpendicular to the flat surface of the box, all sensors returned expected values, but put the box at an angle and things get weird very quickly. A basic knowledge of university level physics lets one assume that this is likely to happen when sound waves hit hard flat surfaces, but we still wanted to verify it. Here's the setup we used:

What one's desire in this situation is, is to measure the distance to Box1, but if sides of boxes are reflective enough, one actually measures the time it takes the ping to go around the entire triangle, which leads to our measurement returning half the circumference of it rather than the distance to Box1.

One can't predict the kinds of silly things people will throw in the trash, so how do we fight this? Turns out the situation isn't as dire as this example can make it look. For one, we can estimate the worst case error! Since trash is actually deposited some distance below the sensor even when the container is full, we can estimate that the difference in distance from sensor to boxes 1 and 2 isn't all that different. This means that our error will amount approximately to half the distance between the two boxes. Assuming "box 1" and "box 2" are thrown into our can in the worst possible way, that is so that one sits below the sensor and aims the sound signal at a corner where the other is readily waiting to execute their vicious plan - our maximum error is a quarter of the diagonal of the bottom of our trash can (they're square... ish).

But what about all the bounces that are not so well aimed? Well, turns out the trash bag is as good a dampener as one can wish for - the scenario where an entire trash compartment rings with ultrasonic goodness, sending nearby dogs on a bloodthirsty Hitchcock-style rampage is highly unlikely.

Mind you, this is the worst case scenario! Now we know the extent to which we can (dis)trust our sensors.

Summary: one problem dealt with, another compensated for. Today was a good day.

Discussions