Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jonchen727
Last active October 12, 2017 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonchen727/e994fbfd1b77a7d6c823f0f4bf9a2adb to your computer and use it in GitHub Desktop.
Save jonchen727/e994fbfd1b77a7d6c823f0f4bf9a2adb to your computer and use it in GitHub Desktop.
#include <NewPing.h>
#define TRIGGER_PIN 3
#define ECHO_PIN 4
#define MAX_DISTANCE 200
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
void setup() {
Serial.begin(115200);
}
void loop() {
delay(50);
Serial.println((0.034027/2)*sonar.ping_median(10));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment