SRF08 Ultra Sonic Range Finder

SRF08 Sensor layout

Circuit

Below is the diagram for setting up the SRF08 sensor for a typical Arduino. The only additional circuitry necessary are two 1.8kOhm pullup resistors as seen below.

Circuit diagram

BreadBoard

Code

  1. //
  2. // SonarSRF
  3. // Arduino Library for controlling SRF sonar sensors
  4. // http://www.arduino.cc/playground/Main/SonarSrf08
  5. //
  6. // MIT License
  7. // Copyright(c) 2009 Zach Foresta
  8. // Copyright(c) 2012 Leo Colombaro
  9. // Copyright(c) 2012 Philipp A. Mohrenweiser
  10. //
  11.  
  12. #include <Wire.h>
  13. #include <SonarSRF02.h>
  14. #include <SonarSRF08.h>
  15.  
  16. #define leftAddress ( 0xF2 >> 1)
  17. #define rightAddress ( 0xE0 >> 1)
  18. #define mainAddress ( 0xF8 >> 1)
  19. SonarSRF02 LeftSonar;
  20. SonarSRF02 RightSonar;
  21. SonarSRF08 MainSonar;
  22.  
  23. char unit = 'c'; // 'i' for inches, 'c' for centimeters, 'm' for micro-seconds
  24.  
  25. void setup() {
  26.     Serial.begin(115200);
  27.  
  28.     LeftSonar.connect(leftAddress);
  29.     Serial.println("Left SRF02 US-Sensor ");
  30.     Serial.println(LeftSonar.getSoft());
  31.  
  32.     RightSonar.connect(rightAddress);
  33.     Serial.println("Right SRF02 US-Sensor ");
  34.     Serial.println(RightSonar.getSoft());
  35.  
  36.     MainSonar.connect(mainAddress);
  37.     Serial.println("Main SRF08 US-Sensor ");
  38.     Serial.println(MainSonar.getSoft());
  39. }
  40.  
  41. void loop() {
  42.     float sensorReading = 0;
  43.  
  44.     sensorReading = LeftSonar.getRange(unit);
  45.     // print out distance
  46.     Serial.print("Distance from left: ");
  47.     Serial.print(sensorReading);
  48.     Serial.print(" ");
  49.     Serial.print(unit);
  50.     Serial.println();
  51.  
  52.     sensorReading = RightSonar.getRange(unit);
  53.     // print out distance
  54.     Serial.print("Distance from right: ");
  55.     Serial.print(sensorReading);
  56.     Serial.print(" ");
  57.     Serial.print(unit);
  58.     Serial.println();
  59.  
  60.     sensorReading = MainSonar.getRange(unit);
  61.     // print out distance
  62.     Serial.print("Distance from main: ");
  63.     Serial.print(sensorReading);
  64.     Serial.print(" ");
  65.     Serial.print(unit);
  66.     Serial.println();
  67. }

Useful Links

Share