Just call it a “DistanceHat”…

[Update: 06/01/09]

- Added the source code to my Arduino sketch
- Found some interesting info on linearising the output from the sharp sensors
- Hack-a-day has an article on the very same subject
- I found the SensorWiki – What a great site!

So…

  1. You can’t buy any new parts
  2. You can’t be bothered getting your robot driving around the house
  3. You want a ‘quick win’ to make you feel better about going back to work tomorrow
  4. You just happen to have a Bare Bones Board Arduino clone and an old Sharp infrared distance sensor sitting around

What do you do? Well if you are me you first make this thing and then make a youtube video about it because one of your New Years Resolutions was to “get famous” hehe :)

Anyway, introducing the SUPER-INFRARED-DISTANCE-SENSING-HAT-MO-TRON! — Otherwise known as the DistanceHat.

This is not a difficult project. In fact it is perfectly suited to people starting out with microcontrollers who want to get something done and possibly impress their parents with how smart they are (in my case I told my fiancé that I was curing blindess of course). It does require you to have an Arduino and a Sharp distance sensor but, man, my grandma has that stuff in her house! (Ed: she doesn’t). And anyways this is Ausrobotics, you need to get that stuff STAT!!!

 

So how does it work? Well…

The Sharp distance sensor outputs an analog voltage on its output pin that is related to the sensor’s distance to a surface. This output value seems to be non-linear (although I must admit I did possibly blow the sensor slightly while mucking around beforehand – gulp) and is more accurate at short distances. Also the distance reported can be change depending on the surface itself – reflective objects -may- return misleading values.

The Arduino (in this case a Bare Bones Board Arduino clone from Modern Device Company) reads the voltage from the distance sensor using one of its analog input pins and converts the value into a beep delay value. The distance sensor reports 0 when it is not pointing at anything and approx 600 when it is really close to it so the Arduino code maps the value from this to a more logical 100-10000 value (100 being the closest).

The Arduino basically just sits in a loop reading values from the sensor and then beeping if its loop count is greater than the last saved beep delay or if the calculated beep delay is less than the previous beep delay. The reason I didn’t just sleep() in the loop is because if you move very quickly from far away to close the Arduino may still be sleep()ing and you could run into the wall before it wakes up and recalculates the distance.

[The requested file http://ausrobotics.com/Mods/http://ausrobotics.com/Mods/distance_hat.cpp could not be found]

The Arduino beeps using a piezo buzzer connected to one of its output pins. The code for the beeping is directly taken from from the bottom of the Arduino Playground code here. It also flashes an LED in time with the beeping for extra dork-factor. Whoooooo! I’m a robot!!!

This code/idea is exactly what you would need if you wanted to add distance sensing to your bot. Now that I have cured blindness around the world I will probably finally get around to adding sensors to Cheapo so that it can drive around the carpet and generally be useless. :) Or maybe I will continue to not do that while dreaming of building this.

Let me know in the comments or forums if you want more information on any aspect of this project.