For Beginners

Using an ultrasonic distance sensor

Code snippet

Here’s the code you’ll need to measure distance with your ultrasonic sensor
#include <Ping.h>
 
Ping ping = Ping(13,0,0);
 
void setup(){
  Serial.begin(115200);
}
 
void loop(){
  ping.fire();
  Serial.print("Microseconds: ");
  Serial.print(ping.microseconds());
  Serial.print(" | Inches ");
  Serial.print(ping.inches());
  Serial.print(" | Centimeters: ");
  Serial.print(ping.centimeters());
  Serial.println();
  delay(1000);
}