PING))) Ultrasonic Distance Sensor

Item code: 28015


What It Can Do

  • Detects nearby objects within a range of 1 inch to 10 feet
  • Measures distances using high frequency sound
  • Simple signal connection requires just a single wire interface

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.

A light emitting diode on the front of the PING))) module indicates when it’s active. Use this visual indicator to verify that the module is operating.


Parts List

  • PING))) Ultrasonic Distance Sensor
  • BASIC Stamp HomeWork board, Propeller BOE, Propeller QuickStart, or Arduino Uno microcontroller
  • 22 gauge solid conductor hookup wire
  • 1 kΩ resistor (when using the Propeller QuickStart)

Basic Wiring

Note: Be sure to include 1 kΩ resistor when using a Parallax Propeller microcontroller.

  • Power requirements: +5 VDC
  • Communication: Positive TTL pulse
  • Dimensions: 0.81 x 1.8 x 0.6 in (22 x 46 x 16 mm)

Program KickStarts

Each KickStart example demonstrates using the PING))) to take successive readings, and display the results in a serial or debugging window. The value shown is the distance between PING))) and object, in inches.


BASIC Stamp 2 HomeWork Board

Download BASIC Stamp 2 code for the PING))) Sensor

’ {$STAMP BS2}
’ {$PBASIC 2.5}

Ping_Pin    CON   0
InConstant  CON   890
inDistance  VAR   Word
time        VAR   Word

DO
  PULSOUT Ping_Pin, 5              ’ Send short pulse to Ping
  PULSIN Ping_Pin, 1, time         ’ Wait for echo
  inDistance = inConstant ** time  ’ Convert to inches
  DEBUG CR, DEC inDistance         ’ Display result
  PAUSE 200			   ’ Short delay until next read
LOOP

When this program is run the BASIC Stamp Debug Terminal will automatically open.


Propeller BOE and Propeller QuickStart


Propeller BOE Wiring Diagram

 



Propeller QuickStart Wiring Diagram

 

Download Propeller Spin code for the PING))) Sensor

OBJ

  pst   : "FullDuplexSerial"
  ping  : "Ping"

CON

  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000

  ping_pin = 0                      ’ I/O pin for Ping
  
VAR

  long  range
  
PUB Go

  pst.start(31,30,0,115200)
  waitcnt(ClkFreq + Cnt)
    
  repeat                            ’ Repeat forever
    range := ping.Inches(ping_pin)  ’ Get range in inches
    pst.dec(range)                  ’ Display result
    pst.tx(13)
    WaitCnt(ClkFreq / 4 + Cnt)	    ’ Short delay until next read

Important! This program uses the following object libraries, which are included with the Propeller Tool software download:FullDuplexSerial.spin, Ping.spin.

To view the results of the demonstration, after uploading is complete run the Parallax Serial Terminal from the Run menu, or press F12. Momentarily depress the Reset button on the Propeller QuickStart board to restart the program.


Arduino Uno

Download Arduino Code for the PING))) Sensor

const int pingPin = 11;
unsigned int duration, inches;

void setup() {
  Serial.begin(9600);
}

void loop() {
  pinMode(pingPin, OUTPUT);          // Set pin to OUTPUT
  digitalWrite(pingPin, LOW);        // Ensure pin is low
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);       // Start ranging
  delayMicroseconds(5);              //   with 5 microsecond burst
  digitalWrite(pingPin, LOW);        // End ranging
  pinMode(pingPin, INPUT);           // Set pin to INPUT
  duration = pulseIn(pingPin, HIGH); // Read echo pulse
  inches = duration / 74 / 2;        // Convert to inches
  Serial.println(inches);            // Display result
  delay(200);		             // Short delay
}

To view the results of the demonstration, after uploading is complete click the Serial Monitor icon in the Arduino IDE. This displays the Serial Monitor window. Momentarily depress the Reset button on the Arduino board to restart the sketch.


For More Information