Ultrasonic Sensor Helps You Enforce Social Distancing

If you’re going outside (only for essential grocery runs, we hope) and you’re having trouble measuring the whole six feet apart from other people deal by eye, then [Guido Bonelli] has a solution for you. With a standard old HC-SR04 ultrasonic sensor, an audio module and a servo to drive a custom gauge needle he’s made a device which can warn people around you if they’re too close for comfort.

As simple as this project may sound like for anyone who has a bunch of these little Arduino-compatible modules lying around and has probably made something similar to this in their spare time, there’s one key component that gives it an extra bit of polish. [Guido] found out how intermittent the reliability of the ultrasonic sensor was and came up with a clever way to smooth out its output in order to get more accurate readings from it, using a bubble sort algorithm with a twist. Thirteen data points are collected from the sensor, then they are sorted in order to find a temporal middle point, and the three data points at the center of that sort get averaged into the final output. Maybe not necessarily something with scientific accuracy, but exactly the kind of workaround we expect around these parts!

Projects like these to help us enforce measures to slow the spread of the virus are probably a good bet to keep ourselves busy tinkering in our labs, like these sunglasses which help you remember not to touch your face. Make sure to check out this one in action after the break!

22 thoughts on “Ultrasonic Sensor Helps You Enforce Social Distancing

  1. I favor a self generating ORT field…. Olefactory Repellent Technology… just put on the same sweats you’ve been lounging around in all week to go shopping in. :-D

  2. The thing with sonar is it’s directional.
    A low power radio beacon in a wrist band with a vibration motor [or high voltage because some need it.]. Hand them out at work. Anyone comes within the bubble and they’ll know. :D

  3. Thing is, social distancing doesn’t really work. When you’re in a space with hundreds of people, like a supermarket, the ambient level of aerosols from other people has a half-life of minutes to hours so the people who have previously been there are still spreading the virus.

    Keeping distance only works for people who are literally coughing in your face. The rest is just too little, too late.

    1. Have you done experiments to prove this or is it just your opinion? Thought so.

      Social distancing isn’t to prevent you specifically from getting the virus in a particular situation. It’s to affect the statistical likelihood of transmission across the entire population. And you can’t argue with the fact that infection statistics in the countries that have introduced these measures show a significant downward impact compared to those that haven’t. So how is that “doesn’t really work”?

  4. Very interesting. I was hoping to hear more about the bubble sort. Thirteen data points are collected from the sensor, then they are sorted in order to find a temporal middle point, and the three data points at the center of that sort. I did a similar task.
    Only we are gathering pressure and delta pressure, temperatures, and power monitoring. We do not want leds flashing hi/lo. I did a rolling average to try to mitigate that but the response was…

    if you have 2 readings at 25C for an RTD, then get a spike from a radiated event, conducted event, sensor funny that is near the max value for an RTD, you’d still be displaying an out of limits message for 1 second, then probably returning after another second or two depending on how high the spike was -> (25+25+400)/3 = 150C (above the 70C limit), then the next reading you’d have -> (25+400+25)/3 + 150C, then another 150C, then it would drop again back to 25C. What this will do is display an out of limit message for 3 seconds (in this example case), then go back to normal for an event that obviously wasn’t a real event. I don’t think this would be what we want.
    I believe the 3 second persistence still needs to be implemented on those messages, also the decision point on whether or not to open/close a valve…

    So, I submitted code that would…
    If we bubble the largest sample(s) out of the samples every 10 samples then that would take care of events or spikes in the data. We are sampling at a 5Mhz sample rate so that would mean we would be refreshing data at a 500Khz rate. If we get a high or low osh or osl then we really have a bad sensor or issues… right?

    The response was:
    “So we are talking of getting rid of data points now? Hmm, not sure how I feel about this yet, I’m not familiar with the bubble method…” SMH… Hardware Engineers… Pssssst I google searched “bubble sort sensor data” and your project came up first… LOL. Cool.

    1. Well Erin,

      He bought off on it…

      I wrote:

      That is what we are talking about isn’t it? We want to throw away events or spikes in the data don’t we?

      Waiting three seconds means if there is a real event, we took three seconds to respond to it…

      We want to respond to real issues and not respond to events or spikes in the data… Bubbling out events seems to be the only solution.

      With bubble sorting you have continuous smooth averages constantly, if you have a hi/lo then you have a real situation you need to respond to…

      Plus, you respond to it immediately, not three seconds later…

      Before:
      uint8 inputPin1[NUM_READINGS] = {0xFF,0xFF,0x19,0xFF,0x19,0x19,0x19,0x19,0x19,0x19,0x19,0x19,0x19};
      uint8 inputPin2[NUM_READINGS] = {0x19,0x19,0xFF,0x19,0xFF,0x19,0x19,0x19,0xFF,0x19,0x19,0x19,0x19};
      uint8 inputPin3[NUM_READINGS] = {0x19,0xFF,0xFF,0xFF,0x19,0x19,0x19,0x19,0x19,0x19,0x19,0x19,0x19};
      After:
      uint8 inputPin1[NUM_READINGS] = {0x19,0x19,0x19,0x19,0x19,0x19,0x19,0x19,0x19,0x19,0xFF,0xFF,0xFF};
      uint8 inputPin2[NUM_READINGS] = {0x19,0x19,0x19,0x19,0x19,0x19,0x19,0x19,0x19,0x19,0xFF,0xFF,0xFF};
      uint8 inputPin3[NUM_READINGS] = {0x19,0x19,0x19,0x19,0x19,0x19,0x19,0x19,0x19,0x19,0xFF,0xFF,0xFF};

      His Reply:

      I think I’m OK with this now. I was thinking for some reason that you’d have to define some limit where if out of range of this limit, you would throw it away. But what your saying is, you take many readings and the bubbles (highest or lowest readings?) float the highest readings to the top and those are discarded? Does this have impacts on severely trending readings where thiss sort takes out the quick ramps?

      My Reply,

      It is constantly collecting every data point from the sensor, currently it collects 13 samples and throws away the highest three samples, if the data is ramping slowly or quickly you will still see real data trends since we are not throwing away continuous real data, just three of those data samples will be discarded, not all of it because it is “out of limit”.

      His Reply,
      I’m happy with this – thanks.

      Keep on Hacking Doc!

Leave a Reply to RW ver 0.0.1Cancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.