Go Down

Topic: Arduino Due PING))) Sensor read problems (Read 770 times) previous topic - next topic



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
Code: [Select]

int ping_pin = 53;

void setup() {
  // put your setup code here, to run once:

void loop() {
  // put your main code here, to run repeatedly:
  pinMode(ping_pin, OUTPUT);
  digitalWrite(ping_pin, LOW);
  digitalWrite(ping_pin, HIGH);
  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 = ");
//  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.


Go Up