SRF08 Ultrasonic Ranger

This is the page for the SRF08 Ultrasonic Ranger, with I2C interface.

It is available at a number of places including :

The datasheet can be found from the Rapid Electronics website, or there is a good resources at Robot Electronics

Hello World!

#include "mbed.h"
#include "SRF08.h"

SRF08 srf08(p9, p10, 0xE0);      // Define SDA, SCL pin and I2C address

int main() {

    while (1) {
       printf("Measured range : %.2f cm\n",;



Import program

Public Member Functions

  SRF08 (PinName sda, PinName scl, int addr)
  Creates an instance of the class.
  ~SRF08 ()
float  read ()
  Reads the current temperature.

Alternative Library

This library does not use a wait statement so the micro can do something else while ranging is in progress.

Import library

Public Member Functions

  SRF08 (PinName SDA, PinName SCL, int i2cAddress)
  Create a SRF08 object connected to the specified I2C pins and address.
void  startRanging ()
  Send the "Start ranging in cm" command via I2C.
bool  rangingFinished ()
  Checks if the module has finished ranging.
int  getRange ()
  Gets the measured range from the module.
int  getLightIntensity ()
  Gets the measured light intensity from the module.
void  setRangeRegister (unsigned char rangeVal)
  Sets the range register of the SRF08 for faster ranging.
void  setMaxGainRegister (unsigned char gainVal)
  Sets the max gain register of the SRF08 .
void  setAddress (int i2cAddress)
  Changes the I2C address of the SRF08 .