Hello,
I'm working on trying to measure distance using a PING))) sensor. The issue I'm having is the Arduino seems to hang on on the pulsein command.
I am using Arduino IDE 1.6.6 with the Arduino SAM Boards version 1.6.6
Code is below
int ping_pin = 53;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
pinMode(ping_pin, OUTPUT);
digitalWrite(ping_pin, LOW);
delayMicroseconds(2);
digitalWrite(ping_pin, HIGH);
delayMicroseconds(5);
digitalWrite(ping_pin, LOW);
pinMode(ping_pin, INPUT);
//int inches = 6;
long duration = pulseIn(ping_pin, HIGH);
long inches = microsecondsToInches(duration);
Serial.print("Length to board in inches = ");
Serial.println(inches);
// delay(100);
}
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 / 82 / 2;
}
It runs very slowly as in it takes anywhere between 0.5 to 5 seconds for a new line to appear on the COM window and the results always read 0.
Thanks