Ultrasonic Range Finder

Devantech SRF05
Devantech SRF05

When you would like to detect an object(s) or person(s) at a distance greater than what the IR Range Finders support, the Ultrasonic Range Finders work well. In this overview we will look at the Devantech SRF05 Ultrasonic Range Finder. The ultrasonic range finder, SRF05, works just like any other sonar device. The range finder sends out an ultrasonic ping, and in turn times how long it takes for the ping to bounce back. The longer it takes for the ping to bounce back, the greater the distance to the target object.

The SRF05 has been designed to increase flexibility (SRF04 Compatibility) and to increase the range from 3 meters to 4 meters. The SRF05 introduces a new operating mode, activated by tying the mode pin to ground, allows the SRF05 to use a single pin for both trigger and echo. When the mode pin is left unconnected, the SRF05 operates with separate trigger and echo pins – SRF04 compatible mode.

We will use the SRF05 in SRF04 compatible mode (Mode 1), this is the simplest mode to use as the SRF05 uses separate trigger and echo pins. If you want to use a single pin for both the trigger and echo, connect the mode pin to ground – activating Mode 2. The timing chart for Mode 1 provides the information on how to Trigger the SRF05 (10uS) and to read a Echo pulse (25mS).

SRF05 Timing Chart (SRF04 Mode)
SRF05 Timing Chart (SRF04 Mode)
SRF05 & Arduino
SRF05 & Arduino

Arduino code for the SRF05 in Mode 1:

#define SONAR_TRIGGER_PIN     2
#define SONAR_ECHO_PIN        3

unsigned int measure_distance()
{
   // Trigger the SRF05:
   digitalWrite(SONAR_TRIGGER_PIN, HIGH);
   delayMicroseconds(10);
   digitalWrite(SONAR_TRIGGER_PIN, LOW);

   // Wait for Echo Pulse
   unsigned long pulse_length = pulseIn(SONAR_ECHO_PIN, HIGH);

   // Ensure the ultrasonic "beep" has faded away
   delay(50);

   // Convert Pulse to Distance (inches) 
   // pulse_length/58 = cm or pulse_length/148 = inches
   return( (unsigned int) (pulse_length / 148) );
}

void setup()
{
   pinMode(SONAR_TRIGGER_PIN, OUTPUT);
   pinMode(SONAR_ECHO_PIN, INPUT);
   Serial.begin(9600);
}

void loop()
{
   unsigned int current_distance = measure_distance();
   Serial.println(current_distance);
   delay(125);
}