to mate with the connector. That is why the
SONAR board connections are called out as
U2 pin numbers. See Figure 2 to locate U2
on the board.
Okay, that takes care of the hardware ...
now for the code. The Arduino does a very
good job at hiding the complexity of
embedded programming. This means that
what would normally be a complicated
program using interrupts, hardware timers,
Data Direction Registers, and the like turns
out to be very simple.
Listing 1 is the entire SONAR program.
This program gives the range in both cm and
inches; you can choose your favorite unit of
measure to use. I removed 200 µs from the
time returned because I noticed that my
ranges were about two inches ( 5 cm) too
long (using my tape measure held in two
hands while aiming). This problem occurs
because I use C1 to delay the rise of the
Init/Echo line which causes the pulse to
stretch a little bit there. Also, the conversion that I use to
calculate the range is based on the speed of sound at sea
level at 15 degrees C. I live at 5,000 feet and my room was
closer to 25 degrees C. Combining my inaccurate measurement
technique, air pressure, temperature differences, and my
delay capacitor together — along with some amount of
code latency — means that my times are a little off. You’ll
need to experiment to see what error the system introduces
when you build this setup. I have typically found that the
Polaroid boards hacked from cameras are a little off — some
of this error may even be in the board itself. Regardless,
after you apply a little fudge factor you’ll find that the
SONAR boards are a handy addition to many projects.
I don’t think these cameras have been made in nearly
20 years, but you can still find them at thrift stores for a
small cost and even eBay has them all frequently for
between $4 and $10.
Figure 3. Using the serial monitor in Arduino.
The code in Listing 1 does a SONAR cycle every
second to send the code to the serial port that you can
configure and run in the Arduino IDE (see Figure 3). This is
a convenient way to know what your program is doing. My
layout uses a SparkFun Bluesmirf Gold Bluetooth
connection, but just a serial cable for the typical Arduino
board works fine.
I hope you’ve learned something this month or at least
been entertained in the process. I enjoyed getting back to
this old project and I hope that I may have re-invigorated you
to look into your closet and pull out that dusty old Polaroid
and look at it in a different light. Next year, I’m planning to
enter the SparkFun AVC with a ground based vehicle. I’m
not brave enough to risk a flying machine just yet! (See the
sidebar on this year’s event.) As usual, if you have any robotics
questions don’t hesitate to let me know at roboto@servo
magazine.com. I’ll do my best to answer you! SV
Autonomous Vehicle Competition
In the Ides of April, SparkFun in Boulder, CO, held
their second Autonomous Vehicle Competition. It was
well attended and well played. The competitors were
trying to get their autonomous robots to circumnavigate
the SparkFun building in the fastest time. There were
two classes: ground-based and flying. The competition
included five aerial and 13 rolling robots. The audience,
as well as the competitors, had fun. Everyone was
treated very well by the SparkFun staff.
This competition was a blast to watch and listen to
(more on that later) because there was such a wide
variety of solutions to root for! All of the aerial entries
were fixed wing (no helicopters) and made of foam.
Since foam is more durable, easy to fix, and fairly
inexpensive.
Here are the results of the competition:
Aerial Category:
1. Robota, - 4 seconds
2. Death by Pinetree, 3 seconds
3. UofA Robotics, 5 seconds
4. DIY Drones, 37 seconds
5. Donuts, Coffee, Muffins, 30% complete
Ground Category:
1. Team Tobor, 1 minute 55 seconds
SERVO 07.2010 15