Arduino and GH-311 Ultrasond Motion Sensor Trouble

I'm in trouble using this ultrasonic sensor ( this is the datasheet :-/ http://www.sure-electronics.net/download/DC-SS014_Ver1.0_EN.pdf )

and this is my arduino code

/*

  • Ultrasound Sensor Test
    */

int pingPin = 8;
int ledPin =13;

void setup()
{
Serial.begin(9600);
pinMode(ledPin,OUTPUT);
}

void loop(){
long duration, inches, cm;

// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// We give a short LOW pulse beforehand to ensure a clean HIGH pulse.
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(10);
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);
//delayMicroseconds(1);
duration = pulseIn(pingPin, HIGH);

// convert the time into a distance
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);

Serial.print(duration);
Serial.print(" microseconds, ");
Serial.print(inches);
Serial.print(" in, ");
Serial.print(cm);
Serial.print(" cm");
Serial.println();

delay(10000);
}

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;
}

and this are the returned values trough serial...
(distance is a random nosense number,
and does not vary when real distance between object and sensor vary, real distance between sensor and a obstacle is 20 cm)

9940 microseconds, 67 in, 171 cm
8454 microseconds, 57 in, 145 cm
8358 microseconds, 56 in, 144 cm
5624 microseconds, 38 in, 96 cm
7152 microseconds, 48 in, 123 cm
6172 microseconds, 41 in, 106 cm
5617 microseconds, 37 in, 96 cm
6813 microseconds, 46 in, 117 cm
6065 microseconds, 40 in, 104 cm
5134 microseconds, 34 in, 88 cm
6329 microseconds, 42 in, 109 cm
5995 microseconds, 40 in, 103 cm
9449 microseconds, 63 in, 162 cm
7926 microseconds, 53 in, 136 cm
7564 microseconds, 51 in, 130 cm

could someone help me? :smiley:
is my code wrong or is my Ultrasound Motion Sensor broken? :cry:

Thanks :slight_smile:

markino,

No help from me, but is this sensor the same as the Parallax Ping? I'm looking for ultrasound sensors, and the price from sure-electronics is great.

I just noticed that the supply voltage listed in the document (first link in your post) shows that it needs 6 to 12V (maybe those are just the maximum allowed). How are you powering it?

-lilbuzz

I am interested in this sensor as well, but after searching for some information about this one, it appears that this cannot be used for distance measurement.

Got this info from this site:

http://www.seeedstudio.com/depot/ultrasonic-ranger-gh311rt-p-73.html

the output pin will be high when an object is within range, and low if no object is detected.

:frowning:

hmmm maybe we can hack this and have it output distance? ::slight_smile:

Just got a reply from Sure Electronics in their forum and how this 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.sureelectronics.net/forum/viewthread.php?tid=78&pid=266&page=1&extra=page%3D1#pid266

Umm I seem to have made the same mistake, it was cheap on ebay. Looking at the board the big chip is just a microcontroller

Google Holtek HT48R05A (I can not post links) for datasheet.

with PA5 driving the transmitter and another pin from the reciever (under chip so would need to probe to find which pin). Since these are just logic levels it should be easy to get the Arduino to generate the 40 KHz and measure the delay.

If I ever get around to trying it out I'll post the results.

Hi qswi271! Do you have news? I mean, had you success, to try measure with gh-311 module?
I have exactly the same problem!

Thanks!

Hi! I'm Electronic Engineering student, i bought three of them, and I want to measure obstacle distance, on robotic platform... But for this i need the technical datasheet and if it´s possible de source code of micro 48r05 to do the necessary modifications...
It is possible? Please i dont have money enought to buy a ultrosound distance measure from parallax, so can you help me?

Many thanks!

is anybody found any solution for this. i also have this sensor :frowning: . or anybody tell me how to interface this sensor with arduino, i planning to create a obstacle avoiding robot using two dc motors and a servo with this sensor.

Please help me with programming and circuit...

Thanks,
robotsmani

markino do u find any solution for that. i required it badly....

Thanks

Is anybody having answer for this question...

Thanks,
Mani

The sensor in the original post is not a sensor to measure distance. It simply has an output that will go high when someone (not something) is within range.
It requires at least 6V to drive it and it can be up to 12V. It's outputs are directly compatible with the arduino so you can feed it into an input pin and you will see that pin go high when it detects someone.
That's it, no range, no pinging like the code first posted.

I got the sensor today. I connected it to Arduino and with the following code I was able to detect obstacles in range of 50cm. the following code shows how:

/*
Ya Hoo
Code for connecting arduino to GH-311
Hamid
*/

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
}

You can connect + pin to AREF and - pin to GND and the OUT pin to 12 digital.

and how use it?

second pin its analog out or something else like ping from paralax?

maybe somebody show me code for this device?

@HamidS
There is some way to change the distace??
for example if i need to detect obstacles in range of 30 cm instead of 50 cm??
Thanks!!

So I got this sensor and was playing around with it and made an observation that indicates that this sensor has a range of over 2metres. It only reports a high value when something is under 25cm. it reports a low value when something is over 25cm. There is three logic conditions possible.

  1. Signal received is over threshold =1
    2 Signal received is under threshhold =0
    3 No signal received = hold last value
    It is the 3rd possibility that is important here. basically if you have your sensor setup with no objects for about 3 meters and you then place your hand within 25 cm your signal will go to high (1) if you move hand away from sensor it wil change to low (0) after 25 cm, however if you move hand away out of path within the 25 cm (ie sideways) the signal remains on high (1). If you then put something into the path at about 2 meters the signal will change to low (0). So all that remains is identifying the input before it gets converted to a digital signal. And calibrating it to give accurate distance

Below is the code

/* GH-311 hooked up to analog for testing

  • connected to 5V, - connected to GND and middle pin to analog 0
    */
    const int analogInPin = A0;

int sensorValue; // Value for sensor output
int d=20; // Delay

void setup()
{
Serial.begin(9600); // To check what is being read on the Serial Port
}
void loop() {

sensorValue = analogRead(analogInPin); // Read the analog value

delay(d); // Delay
Serial.println(sensorValue); //Print values
}

Seeedstudio is offering a sonic sensor for $15 that claims to be able to produce real measurements. I'll see when it comes in. Their example code is the Ping example taken from the Arduino Playground so I'm not terribly confident that it's going to work as well as most would need it to.

I've been asking around about distance sensors for one of my projects and the consensus seems to be that the MaxSonar sensors are among the best on the market. They're also the most expensive but like with most things, you get what you pay for..