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.
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.
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):
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!
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 want to see more of my projects, sign up on my email list below!
Oh... and when you do sign up, you'll also be notified when this newest edition to the Dr.Duino family is available!