The PING)))™ Ultrasonic Distance Sensor is an all-in-one module for accurately measuring distances between itself and objects nearby. The effective range is from about 1 inch to 10 feet (2 centimeters to 3 meters). The PING))) sensor consumes only modest power, and is ideal for use in mobile robots, security systems, and any other application for detecting nearby objects, or measuring their distance from the sensor.
In operation, object detection or distance measurement is initiated by sending a short high frequency (40 kHz) tone from the PING))) module. The time it takes to detect the return echo represents the distance between the PING))) module and any objects in front of it. Using basic arithmetic, you can convert the amount of delay of the echo to inches or centimeters. The sound frequencies used in the sensor are in the ultrasonic range, and are beyond human hearing.
Code & Schematic
Upload this code to arduino and open the serial monitor.
kindly change the "pingpin" to pin no. 7