Skip to content

Instantly share code, notes, and snippets.

@jamesabruce
Created December 19, 2015 15:09
Show Gist options
  • Save jamesabruce/9df4fcfb42911aed7baf to your computer and use it in GitHub Desktop.
Save jamesabruce/9df4fcfb42911aed7baf to your computer and use it in GitHub Desktop.
Ping demo
#include <NewPing.h>
//Tell the Arduino where the sensor is hooked up
NewPing sonar(12, 13);
long inches;
void setup() {
//Activate the serial monitor so you can see the output of the sensor
Serial.begin(9600);
}
void loop() {
delay(50);
//Ping the sensor to determine distance in inches
inches = sonar.ping_in();
//Print the distance in inches to the serial monitor
Serial.print(inches);
Serial.print(" in.");
Serial.print("\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment