Let's Make Robots!

Problem with Ultrasound Sensor

Hello LMR.

I am working on a current project but seem to be having a ridiculous amount of difficulty implementing an SRF02 Ultrasound sensor. I am using it in serial mode and communicating with an Arduino Duemilanove. The problem is not in the wiring as I triple checked that.

The adruino is supposed to send 2 bytes to the SRF02 [ address, command ] and then receive 2 bytes in response giving the distance measured by the sensor.

In my setup the SRF02 blinks so I can see that it is receiving the command and doing a ranging operation. However for some reason I get no response from it. The problem is somewhere in the code and I could really use some help. I bet its something simple and silly.... Bellow is my code and the serial monitor output. Please tell me where I am wrong. My version of Arduino IDE is 17 but that shouldn't be a problem.

Documentation for SRF02


#define srfAdrs 00 // Address of the SRF02
#define rangeCM 84  // Byte for start of ranging data

void setup()

void loop()

void SRF_Range(){
int incomingByte;

Serial.write(byte(srfAdrs)); // send address byte
Serial.write(byte(rangeCM)); //send command byte

if (Serial.available() > 0)
   incomingByte = Serial.read(); // read serial response
   Serial.println("Range: ");
   Serial.print(incomingByte); // write distance measured
   Serial.flush(); // clear buffer

Serial Monitor Output:

0 TRange:
0 TRange:
0 TRange:


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ezekiel181's picture

It seems like you`re using the only hardware serial port to communicate with the PC and the SR02 at the same time. Try using the software serial library for one of them.

arbarnhart's picture

I have almost the same setup and I used NewSoftSerial for the range finder. Also, depending on where you got yours, getting a bad one seems more common than with some components. I got mine cheap from China and when I had a problem, the forst thing they did was send another. It worked.

merser's picture

I saw somewhere arduino uses 7 bit addresses and srf02 uses 8 bit. There's a bit of info here. Hope it helps.