sonar srf08

Hello, I have a probleme with my Serial.print.
Nothing is displayed on my monitor, not even my println or my distance someone could help me.
This is my program:

#include <Wire.h>

#define srfAddress 0x70                           // Address of the SRF08

#define cmdByte 0x00                              // Command byte

#define lightByte 0x01                            // Byte to read light sensor

#define rangeByte 0x02                            // Byte for start of ranging data



void setup(){

 Wire.begin();                                   // Initialize the I2C bus

 Serial.begin(115200);                           // Initialize the serial connection

 delay(100);                                     // Waits to make sure everything is powered up before sending or receiving data

 Wire.beginTransmission(srfAddress);             // Start communicating with SRF08

 Wire.write(0xFF);    // <-- CHANGE RANGE TO THE MAX AVAILABLE: 11 meters

 Wire.write(0x25);   // <-- THIS IS FOR THE MAX GAIN

 Wire.endTransmission();


}



void loop(){

 //int rangeData = getSoft();                     // Calls a function to get software version

 int rangeData = getRange();                      // Calls a function to get the range data

 int lightData = getLight();                      // Calls a function to get the light data



 Serial.print("Range: ");

 Serial.print(rangeData);

 Serial.println("cm");



 Serial.print("Light: ");

 Serial.print(lightData);

 Serial.println("");



 delay(100);                                      // Wait before looping

}



int getRange(){                                   // This function gets a ranging from the SRF08

 int range = 0; 


 Wire.beginTransmission(srfAddress);             // Start communicating with SRF08

 Wire.write(cmdByte);                             // Send Command Byte

 Wire.write(0x51);                                // Send 0x51 to start a ranging in cm

 Wire.endTransmission();

 delay(80);                                     // Wait for ranging to be complete

 Wire.beginTransmission(srfAddress);             // start communicating with SRFmodule

 Wire.write(rangeByte);                           // Call the register for start of ranging data

 Wire.endTransmission();


 Wire.requestFrom(srfAddress, 2);                // Request 2 bytes from SRF module

 while(Wire.available() < 2);                    // Wait for data to arrive

 byte highByte = Wire.read();                 // Get high byte

  byte lowByte = Wire.read();                  // Get low byte



  range = (highByte << 8) + lowByte;              // Put them together



 return(range);                                  // Returns Range

}



int getLight() {                                  // Function to get light reading

 Wire.beginTransmission(srfAddress);

 Wire.write(lightByte);                           // Call register to get light reading

 Wire.endTransmission();



 Wire.requestFrom(srfAddress, 1);                // Request 1 byte

 while(Wire.available() < 0);                    // While byte available

 int lightRead = Wire.read();                 // Get light reading


 return(lightRead);                              // Returns lightRead


}



int getSoft(){                                    // Function to get software revision



 Wire.beginTransmission(srfAddress);             // Begin communication with the SRF module

 Wire.write(cmdByte);                             // Sends the command bit, when this bit is read it returns the software revision

 Wire.endTransmission();



 Wire.requestFrom(srfAddress, 1);                // Request 1 byte

 while(Wire.available() < 0);                    // While byte available

 int software = Wire.read();                  // Get byte



   return(software);                               
}

Thanks

Hi,

Why don’t you try something simple first?
As you said nothing is being displayed on your serial monitor try this and see if Serial communications are working fine.

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println("Hello World");
  delay(1000000000);
}

Have you run the I2C Scanner sketch, to confirm that you have the correct address for the device?

If you see nothing in the Serial Monitor, it is because you assume that everything is connected correctly, and that you have the proper address. The behavior you see suggests that that is not a valid assumption.