HI!
I have an srf02 attached to a Mega 2560 in seriell mode. i can see that the sensors led is flashing but i cant get the correct values from it. the output is
Range: 0 Range: 171 Range: 0 Range: 171 Range: 0 Range: 171 Range: 0 Range: 171 Range: 0 Range: 171 Range: 0 Range: 171
then after a while i just get 0
here is my code
//SRF02
define srfAdrs 00 // Address of the SRF02
define rangeCM 84 // Byte for start of ranging data
void setup() { Serial1.begin(9600); Serial.begin(9600); }
void loop() { SRF_Range(); }
void SRF_Range(){
int incomingByte=0;
Serial1.write(byte(00)); // send address byte delay(100); Serial1.write(byte(84)); //send command byte delay(70);
if (Serial1.available() > 0) { //Serial.write(byte(94)); incomingByte = Serial1.read(); // read serial response Serial.print("Range: "); Serial.println(incomingByte); // write distance measured Serial1.flush(); // clear buffer delay(100); } }
what is wrong?