Imran's personal blog

March 19, 2013

Ultrasonic Sensors

Filed under: Uncategorized — ipeerbhai @ 2:59 am

Hi All,

I’ve been working on sensors for a bit.  One of the things that bothers me is that 3d printers and mills use an open loop system.  I’ve found that open loop systems have error inherent in them, perhaps a 1/10K variance.  I’ve seen this error in multiple places, and it can sometimes show up on large objects.  So, I’ve been thinking of a closed loop system.  At the very least, replacing the contact-based microswitches with a positionable hall effect sensor and magnet makes a lot of sense.

So, my previous post was on how to code up and use a hall effect sensor.   I wrote it because the various tutorials online clash with each other, and I wanted to make one that matched my own experiments.

I just finished testing an UltraSonic sensor ( the HC-SR04 — about $6 on Amazon. ), and have discovered a few things.

1. At very short distances, there’s a large variance in the output.  It’s pretty much blind at some distance less than 1cm.

2. At distances beyond 20mm, the variance drops a lot.  Variance is around  4 micro-seconds( uS ).

3. The distance measurements computed from the output are off a bit, depending on variances in the speed of sound at the moment ( temperature, air density, and possible some interference from the surface material ).  

These errors make it a very difficult sensor to use for an accurate system like a linear motion platform.  However, I believe it may be possible to use it under some circumstances.  I may investigate further — I’m not sure.

To play with this sensor:

1. install the NewPing library —

2. Use the NewPing Sample code from Google.

Viola — it’s a pretty simple sensor, and doesn’t need a lot of explaining.  The hardest part for a newbie is installing the library.  Here’s how to do that:

Good Luck!


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at

%d bloggers like this: