Parallax Ping Interface

I currently have a Parallax ping sensor, and some code I found and modified to actually return accurate results... well as accurate as i can get without being able to print Floats.. the Ping is supposed to read out to 3m..

It works great out to about 12-16" however after that my echo jumps to ~21000 ms

Do I have a problem with my code or hardware ... I have adjusted my holdoff from 0 to 500 with no effect I have removed the Pullup and used while to wait for LOW I have increased and decreased my trigger to both acceptable extremes.

Any help would be appreciated.

I've turned this in a function that is called every delay(250);

unsigned long ping(){

pinMode(ultraSoundSignal, OUTPUT); // Switch signalpin to output digitalWrite(ultraSoundSignal, LOW); // Send low pulse delayMicroseconds(2); // Wait for 2 microseconds digitalWrite(ultraSoundSignal, HIGH); // Send high pulse delayMicroseconds(5); // Wait for 5 microseconds digitalWrite(ultraSoundSignal, LOW); // Holdoff delayMicroseconds(400); // Wait for 4 microseconds pinMode(ultraSoundSignal, INPUT); // Switch signalpin to input digitalWrite(ultraSoundSignal, HIGH); // Turn on pullup resister echo = pulseIn(ultraSoundSignal, HIGH); //Listen for echo //cursorSet(1,0); // from my LCD conroller lib // Serial.print(" "); //cursorSet(1,0); // from my LCD conroller lib //Serial.print(echo); // used for debug... ultrasoundValue = (echo / 58.138) * .39; //convert to CM then to inches return ultrasoundValue; }

what does a ping sensor sense?

I used to work for Parallax and have a lot of experience with the Ping -- give this program a try, it seems to work correctly (please note that I'm new with Arduino, so I'm not as good with C as I am with PBASIC).

// Parallax Ping Demo // -- Jon McPhalen // -- // -- 27 DEC 2007

define pingPin 8

void setup() { Serial.begin(9600); delay(5); Serial.println("Parallax Ping Demo"); }

void loop() { long distance = 0;

delay(500); distance = getPing(); Serial.print("Raw distance is "); Serial.println(distance, DEC); }

long getPing() { long measure = 0;

digitalWrite(pingPin, LOW); // ensure output starts low pinMode(pingPin, OUTPUT); // make it output delayMicroseconds(1); // let it settle digitalWrite(pingPin, HIGH); // ping! delayMicroseconds(5); digitalWrite(pingPin, LOW); // remove ping delayMicroseconds(1); pinMode(pingPin, INPUT); // configure to measure return

measure = pulseIn(pingPin, HIGH);

measure >>= 1; // reduce to one-way trip return measure; }