Skip to content

Instantly share code, notes, and snippets.

@mskf1383
Created August 3, 2024 07:57
Show Gist options
  • Select an option

  • Save mskf1383/e76ef0ebb0cada2aac3833cf02e7b829 to your computer and use it in GitHub Desktop.

Select an option

Save mskf1383/e76ef0ebb0cada2aac3833cf02e7b829 to your computer and use it in GitHub Desktop.
int getDistance() {
// reset ulterasonic
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
// send signal
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
// recive signal
duration = pulseIn(echoPin, HIGH);
// calculate distance
return duration*0.034/2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment