#include <NewPing.h>//include Library for ultrasonic sensor
int triggerPin = 4;
#define EchoPin 3
#define maxDistance 400// detect object upto 400cm
NewPing varName(triggerPin, EchoPin, maxDistance);
//libraryName varName(pin no. or name of the pin no.)
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
delay(300);
unsigned int dist = varName.ping_cm();
//ping_cm() is the library function of NewPing library
Serial.print(dist);
Serial.println("cm");
}