Created
December 19, 2015 15:09
-
-
Save jamesabruce/9df4fcfb42911aed7baf to your computer and use it in GitHub Desktop.
Ping demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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