ultrasonic sensor problem

Hi am using the following ultrasonic sensor module


i tried the follwing code for just reading the received the string but in serial monitor am receiving nothing…but the receiver led blinks continuously.which means its receiving something…am stuck with coding…could you guys help me out…

int serialport=0;/* pin initialization for serial port*/
char buffer[10];
int range;
void setup()
void loop()
int i;

  • Serial.println(buffer);*

First, you call Serial.flush() which discards all the data in the serial buffer.

Then, without regard for whether there is data to read, or not, you (try to) read the next 3 bytes.

Finally, regardless of whether you read anything, or not, you try to print a non-null-terminated array of characters as if it was a string.

This fails. I admit that I am not surprised.

Why are you flushing the buffer?

By the way, that link is to a fingerprint scanner, not an ultrasonic sensor. And, no where in your code do you activate the sensor. Is it externally powered. Are the sensor's ground and the Arduino's grounds connected?

sorry for the wrong link..here is the correct link.. http://www.sunrom.com/index.php?main_page=product_info&cPath=55&products_id=710

also the datasheet says it has only 3 pins..supply,ground and serial input which receives the distance as array of characters..i don know how to trigger the sensor.. please help me..am a novice

The data sheet also says that the device outputs 9 characters per reading, yet you are only reading 3, after throwing away all of the data.

char sensorData[10];
int index = 0;
void loop()
   // While there is data, and we have read less than 9 characters
   while(Serial.available() > 0 && index < 9)
      char inChar = Serial.read(); // Read a character
      sensorData[index] = inChar; // Store it
      sensorData[index] = '\0'; // Null terminate the string

   Serial.print("Sensor data: ");

   // Do whatever else you need to do to parse the string and use the data

   index = 0;