using GH 311 for a project to detect distances.

Hey everyone,
We were combing through the internet and the forum for information on the GH 311 ultrasonic sensor.We don't have a clear understanding of the output that this sensor generates.We are familiar with the ping .How does the code and the output generated from both,differ?
We found this code on an old (read-only) post on the forum.Our output is just 0's on the serial monitor.
We are stuck here,so please help!

Thanks!

int led=13; // Arduino led
int sensorPin=12; // Digital Pin In
int sensorValue; // Value for sensor output
int d=250; // Delay

void setup()
{
Serial.begin(9600); // To check what is being read on the Serial Port
}
void loop() {
sensorValue=digitalRead(sensorPin); // Read the digital value
analogRead(0); // Read the analog value
digitalWrite(led,sensorValue);
delay(d); // Delay 
Serial.println(sensorValue); //Print values
}
analogRead(0); // Read the analog value

I don't see what this achieves.

We found this code on an old (read-only) post on the forum.

Link, please.

Hello,
Here's the link- Arduino and GH-311 Ultrasond Motion Sensor Trouble - Interfacing - Arduino Forum

Regarding the analogRead,we had the same question but couldn't post on that thread.We uploaded the ping example code .

const int pingPin = 7;

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
}

void loop()
{
  // establish variables for duration of the ping, 
  // and the distance result in inches and centimeters:
  long duration, inches, cm;

  // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);

  // The same pin is used to read the signal from the PING))): a HIGH
  // pulse whose duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(pingPin, INPUT);
  duration = pulseIn(pingPin, HIGH);

  // convert the time into a distance
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);
  
  Serial.print(inches);
  Serial.print("in, ");
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
  delay(2000);
  
  
}

long microsecondsToInches(long microseconds)
{
  // According to Parallax's datasheet for the PING))), there are
  // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
  // second).  This gives the distance travelled by the ping, outbound
  // and return, so we divide by 2 to get the distance of the obstacle.
  // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
  return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds)
{
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;
}

We don't get the correct distances,but arbitrary readings.Should any additons be made to the above code? We aren't sure ,but ,the ping sensor and the GH 311 seem to be doing the exact same thing(from internet data).Hence the uploading of the above code.Is the assumption wrong??

Thanks .

The GH311 ultrasonic sensor is not a sensor to measure distance.
How this GH311 works is really just High and Low: High level if an object is within it's detection range, and Low if no object.
http://www.techshopbd.com/uploads/product_document/User%20Guide.pdf
http://forum.arduino.cc/index.php?topic=20867.0