Social Distancing Arduino Project!

As seen on Hackadays blog!

Well... it's official, I'm getting stir crazy just like the rest of us.

So I decided to make an Arduino project which might be useful if you absolutely must be around other people.

By the way, I am in no way advocating this! If you can stay home, stay at home but why not learn something in your spare time!

Initially, this project started as a way for me to experiment with the wildly popular HC-SR04 ultrasonic sensor.

I needed an application for it and thought, hey, why not turn it into a useful kind of device.

Something which could warn someone when they are getting too close to you, say less than 6 feet away!

This is the magic number that the CDC says is a safe distance if you have to be in public with others.

I just so happens that this sensor can measure up to 13 feet away and as close as 1".

There are some weird caveats that you need to be aware of when working with this little bugger though.

It can be rather squirely, here's why.

 

Erroneous Data

These modules are cheap for a reason, while they "most" of the time give you an accurate value, you do get erroneous data.

This drove me nuts because I just couldn't understand why.

Well after consulting the great google for a while, I realized that this is just the nature of this type of sensor.

For example, it would return data like this:

150", 148", 150", 30" ,147", 159" ,150", 148", 150", 28" ,147", 159", 150"

Since I was relying on this data to know how far something was away from me, getting that random 30" when clearly nothing was that close, was a real issue.

So what to do?

Well, I applied what's called a bubble algorithm and added a bit of a twist to it.

A bubble sorting algorithm just sorts your data from low to high or high to low depending on how you write your code.

If you noticed, the example data I gave had 13 data points. This was done on purpose.

If we apply a bubble sort to these numbers from low to high, here is what the data looks like now:

Sorted Array: 28,30,147,147,148,148,150,150,150,150,150,159,159

Now, the next step is to isolate the median number which in this case is 150 and is the 7th data point.

Which leaves us with 6 lower data points, and 6 higher data points hence choosing 13 data points!

Now we can get the exact middle of the data sequence which is 150.

28,30,147,147,148,148,150,150,150,150,150,159,159

I could have just left it at that and used that for making decisions, but I wanted a bit more accuracy.

So I ended up averaging the middle 3 data points (in red):

28,30,147,147,148,148,150,150,150,150,150,159,159

With that, we get a nice average value of 149.333", which is pretty stable in terms of data.

Using the Data

Now that I had the data which was pretty stable, I created a color-coded dial that visually indicated to the person approaching you how close they are.

And your current "distance mood" which ranges from A-ok, to BACK UP THE BUS! You're too close!!!

Using the data from the ultrasonic sensor, I then divided up the distance as follows:

Green = More than 13 feet or 150" away = A-Ok

Yellow/Green = Less than 150" but more than 114" = You're Good

Yellow/Orange= Less than 114" but greater than 93"=  Ummm....

Orange/Red = Less than 93" but more than 72"= You're a bit too close!

Red     = Less than 72 Inches = BACK UP THE BUS!

Once the person does get too close, the final touch was to add a very "New York" response. Watch the video to find out what it is!

The Hardware

While it's true that under the covers I'm using an Arduino Uno, servo, ultrasonic sensor and an ISD-1820......it's also built with the newest addition to the Dr.Duino product line, but I can't talk about it yet.

Here is a nice, crystal clear picture of it though...  does that help ? ;)


Sorry, couldn't help myself. But the details will be released in the next few weeks.

So stay tuned.

Well... that's it. I hope you enjoyed this little write up on using the HC-SR04 sensor to make your very own back up the bus detector!

If you liked this and would like a chance to win the hardware to build it, signup for my giveaway below!

It will do much more than just this social distancing example, its a full blown Arduino based, learning eco system.

Sign up for free below!

 

 


6 comments

  • Watched the videos, got the code. I assume “Pioneer” is the name of the servo?
    Also in looking at the code it seems like you are averaging the middle five readings instead of the middle three in the text above? Otherwise I can hardly wait for the second webinar tomorrow.

    Ben Townsend
  • @ Robert
    It currently does not distinguish between objects and humans. One way which this could be accomplished would be by adding a PIR sensor which can detect the presence of heat. Then you could logically check if motion was detected AND you are getting close.

    Dr.Duino
  • How does it distinguish objects from humans?

    Robert
  • Ii drew up a quick “social distance meter” and was about to take my robot apart to get the parts to build it. My first draft was not as pretty as yours but it would be effective as a “social distance” warning. I figured that I would not be the only bored person who would think of such a thing.

    Larry M Kistler
  • Hi Charles! Sign up for Dr.Duino’s labs and Ill be sharing the code there very soon. ;)

    Dr.Duino

Leave a comment

Please note, comments must be approved before they are published