Home

How to Use the Grove Ultrasonic Ranger

The Grove Ultrasonic Ranger uses a pair of 40 kHz ultrasonic transducers to implement a sonar detection system. Circuitry on the module transmits chirps or "pings" from one tranducer and listens for echos on the other transducer. By measuring the delay between ping and echo you can calculate the distance to an object.

You will need to install the Seeed Ultrasonic Ranger library with the Arduino IDE library manager, invoked from either the Arduino sidebar icon
or the application command menu Tools → Manage Libraries....

Type Grove Ultrasonic in the search box below LIBRARY MANAGER and then click INSTALL in the result titled Grove Ultrasonic Ranger by Seeed Studio.

The following example sketch illustrates how to do something (like turn on the LED) upon detection of an object within a certain range. This is one of the most common methods for a mobile robot to detect obstacles in its path.

#include <Ultrasonic.h>

const uint8_t Sonar = 6;

Ultrasonic Sensor(Sonar);

void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop()
{
  long range     = Sensor.MeasureInInches();
  bool detection = (range > 0) && (range < 10);

  // Turn on the LED if an object is detected within 10 inches
  digitalWrite(LED_BUILTIN, detection);

  delay(100);
}

Home


Questions or comments to phil@munts.net