Devantech SRf04 Sonar Ranger
This is where sonar is used- to measure distance and location based on return time of sound from an emitter. My favorite example of this in nature is the way bats operate when navigating and hunting. They use a process called “echolocation” to determine their distance to an object, including tiny little bugs they like to eat. Bats emit their voices, normally, at an ultrasonic range, so most of the time, we never hear them in their process of navigation and hunting. All of this information is highjacked from the following: http://science.howstuffworks.com/bat2.htm .
One of my favorite uses of Sonar technology comes from the marine world, and I don’t really mean the trillion dollar submarine development branch of the Navy and federal government, but something way more mundane: fish finders. Nothing better than sitting in a boat all day, out on a nice calm lake, trolling slowly along with the movement of schools of fish that you can “see” underneath the boat. Okay, there are many things better than that, but I still like the technology of the fishing world. For example, Humminbird makes some wonderful gear for tracking fish and navigating various aquatic terrain: http://humminbird.com/products.asp?ID=361
The Devantech SRF-04 Ultrasonic Sonar Ranger
-insert 1 front picture; one back picture-
This particular module is very popular for use in smaller robotics manufacturing and engineering. When you hunt down information about the unit, it is often tied to both home and academic research products that use the sensors as navigation tools for their robots. An example fitting of ITP’s often humorous approach to robotics: http://www.acroname.com/robotics/gallery/bugbot/bugbot.html
A good question to ask would be: why use this type of ranger when here are other methods, many of them cheaper? Take, for example, the Sharp range of IR: sensors:http://www.acroname.com/robotics/parts/R120-GP2Y0D02YK.html They are a little less bulky, and, come on, the concept of working with IR just sounds sexier. But there are two main reasons why the sonar sensors are a good solution to navigational needs, over the IR sensors:
1) They can detect further distances
2) IR and light tracking and sensing can be a giant pain. You take an IR sensor outdoors into the natural sunlight which puts off an immense amount of natural IR light, and your robot is, in effect, blind.
Sonar rangers do have their own quirks, which I will get to, but outdoor projects may be easier to negotiate with sonar.
Unfortunately, I was not able to find a specific data sheet for this product. Googling Devantech leads you here: http://www.robot-electronics.co.uk/ However, on both the Acroname and Parallax sites, you can find very handy data-sheet-esque reports that have code examples (mostly for the Basic Stamp and BX): http://www.acroname.com/robotics/parts/R93-SRF04p.pdf Also, when you purchase a unit from Acroname, they send you a small booklet which is a nicely condensed version of the Parallax data-report. The reports outline the following behaviors for this unit:
- It operates on +5v and uses between 30 and 50 mA (30 is typical)
- Emits at a frequency of 40khz (way beyond anything we can hear, though I am interested to see what it might do to a dog)
- The MAX range for detection is 3 meters (roughly 8.5 feet)
- The MIN range for detection is 3 centimeters (a little more than an inch)
- According to Lab testing, the sonar can detect the top of a broom handle, which is 3cm in diameter, from a distance greater than 2 meters (almost 6 feet). Testing this theory is a bit tricky, and as my tests later showed, that kind of accuracy is irrelevant due to other concerns.
How Does This Thing Work?
I hooked this sensor up to a Microchip Pic 18F252. They are pretty much my favorite that I have worked with thus far, mostly for size, convenience and functionality.
First, how it interfaces:
-insert picture of pins-
The INIT and ECHO pins go to any digital I/O pin on the Pic. You pulse the INIT pin for a minimum of 10uS, at 5V (TTL Level). This is the trigger for the sensor to send the 40khz tone. You ask the Pic to listen on the ECHO pin for 10mS for that tone coming back to the sensor. Using PicBasicPro, the PULSIN command allows you read the voltage coming back to the Pic. If we take that time and divide it by the constant of the Speed of Sound, we can determine distance. On the Pic with a 4mhz clock, you use 14. As Tom Igoe notes in his book Physical Computing, due to the differences in timing between the PULSOUT and PULSIN commands, this value differs from one microcontroller to the next. The BX, for example, uses 74 as its constant. That is included in the data report found on the Acroname page.
When I hooked up a multimeter to the ECHO pin, the voltage coming back ranged from .65V to 3.5V consistently, giving some idea as to the range the PULSIN command translates.
Below is the code I used to test this with a 4mhz clock. It is taken directly from the book Physical Computing by Tom Igoe and Dan O’Sullivan.
Define osc 4
distance var word ‘variable to store the distance
conversionFactor con 14 ‘constant for the speed of sound
initPin var portc.4 ‘what I used on the 18f252
echoPin var portc.3
txPin var portc.6
serout2 txPin, 16468, ["start"]
pause 500 ‘ pause the whole thing half a second before reading
pulsout initPin, 1
Pulsin echoPin, 1, distance
distance = distance/conversionFactor
serout2 txPin, 16468, ["Distance = ", DEC distance, "inches", 10, 13]
The end result of testing, with the sensor pointed at a roughly 15 foot ceiling, and using my hand as a movable target, was a seemingly maximum distance of 61 inches, and a minimum distance of 3 inches. As we can see, not quite what the guides give us as the parameters for the sensor.
<pictures: board, board and sensor, screen shot>
When I tilted the sensor angle, so the emitters were parallel with the table, and pointed it into space where I knew any items were out of range, I figured I would get roughly the same results as before. This was not the case. I kept getting readings of things being as close as a foot away, even though there were no items in front of the sensor.
When I went back to the Acroname page to see if there are any circuits for calibrating these devices, I came across a link to the following page:
The user here describes the problem inherent to the ranger. In the data provided with the sensor, Acroname lab tests show a roughly 45 degree angle of dispersion for the frequency. But that means it goes out in a 360 degree cone, not just on the X-axis. Subsequently, the floor of the work area became a “target.” The user here found that the best height for eliminating this distortion was at 5 feet. He describes this on a SRF10 ranger. The 04 has a shorter range, so the height would be a bit lower, but you still have to consider the floor a factor in measurement. He also discusses a solution for creating a narrower cone, eliminating distortion from object “way off boresight” (the angle where the sonar is aimed...straight ahead).
<picture of Acroname graph>