Grove - Ultrasonic Ranger

Introduction

3.3V 5.0V

This Grove - Ultrasonic sensor is a non-contact distance measurement module which works at 40KHz, suitable for projects that require middle distance measurement.

Get one now

Product Update

We have made some update on this product in order to improve the power stability when working with some low-voltage main board. The update includes:

  • Added an capacitance C14
  • Redesigned the layout to make it more tidy
  • Compatible with 3.3V voltage system

Here we use 2 photos to show the difference:

Note

Please note that the new version shares the same sku with old version, so you can still use the old sku:101020010 to buy and we will ship new version to you.

Specification


Parameter Value/Range
Operating voltage 3.2~5.2V
Operating current 8mA
Ultrasonic frequency 40kHz
Measuring range 2-350cm
Resolution 1cm
Output PWM
Size 50mm X 25mm X 16mm
Weight 13g

Tip

More details about Grove modules please refer to Grove System

Platforms Supported

Getting Started


With Arduino

Connection

Here we will show you how this Grove - Ultrasonic Ranger works via a simple demo. First of all, you need to prepare the below stuffs:

Seeeduino V4 Grove - Ultrasonic Ranger Base Shield Grove - LCD RGB Backlight
enter image description here enter image description here enter image description here enter image description here
Get ONE Now Get ONE Now Get ONE Now Get ONE Now
  • Connect Ultrasonic Ranger to port D7 of Grove-Base Shield.
  • Connect LCD RGB Backlight to port I2C of Grove-Base Shield.
  • Plug Grove - Base Shield into Arduino.
  • Connect Arduino to PC via a USB cable.

Software

#include <Wire.h>
#include "rgb_lcd.h"
#include "Ultrasonic.h"

rgb_lcd lcd;
Ultrasonic ultrasonic(7);

const int colorR = 0;
const int colorG = 255;
const int colorB = 0;


void setup()
{
    // set up the LCD's number of columns and rows:
    lcd.begin(16, 2);
    lcd.setRGB(colorR, colorG, colorB);
}

void loop()
{   
    long RangeInCentimeters;
    RangeInCentimeters = ultrasonic.MeasureInCentimeters();
    delay(150);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("The distance:");
    lcd.setCursor(0,1) ;
    lcd.print(RangeInCentimeters,DEC);
    lcd.setCursor(5,1) ;
    lcd.print("cm");
}
  • Copy the code into Arduino and upload. We can see the distance display on the LCD.

With TI LaunchPad

Connection

Sensing the Distance (Ultrasonic Ranger Sensor)

This example shows how to measure the distance to obstacles using the ultrasonic sensor and display the value on a 4-Digital-Display (centimeters).

Software

/*
 Ultrasonic-Ranger to 4-digit-display
 Measure the distance to obstacles in front and display the value on
 4-digital-display

 The circuit:
 * Ultrasonic Ranger attached to SPI plug on Grove Base BoosterPack
 * one side pin (either one) to ground
 * the other side pin to +VCC
 * LED anode (long leg) attached to RED_LED
 * LED cathode (short leg) attached to ground

 * Note:  


 This example code is in the public domain.

 http://www.seeedstudio.com/wiki/Grove_-_Ultrasonic_Ranger
 */

#include "TM1637.h"
#include "Ultrasonic.h"
/* Macro Define */
#define CLK               40                  /* 4-digital display clock pin */
#define DIO               39                 /* 4-digital display data pin */
#define BLINK_LED         RED_LED            /* blink led */
#define ULTRASONIC_PIN    38                  /* pin of the Ultrasonic Ranger */

/* Global Variables */
TM1637 tm1637(CLK, DIO);                  /* 4-digital display object */
Ultrasonic ultrasonic(ULTRASONIC_PIN);    /* Ultrasonic Ranger object */
int distance = 0;                         /* variable to store the distance to obstacles in front */
int blink_interval = 0;                   /* led delay time */
int8_t bits[4] = {0};                     /* array to store the single bits of the value */

/* the setup() method runs once, when the sketch starts */
void setup() {

    /* Initialize 4-digital display */
    tm1637.init();
    tm1637.set(BRIGHT_TYPICAL);

    /* declare the red_led pin as an OUTPUT */
    pinMode(RED_LED, OUTPUT);

}

/* the loop() method runs over and over again */
void loop() {   

    distance = ultrasonic.MeasureInCentimeters();   /* read the value from the sensor */   

    memset(bits, 0, 4);                             /* reset array when we use it */
    for(int i = 3; i >= 0; i--) {
        /* get single bits of the analog value */
        bits[i] = distance % 10;
        distance = distance / 10;  
        tm1637.display(i, bits[i]);                 /* display by 4-digital display */
    }
    delay(100);
}

With Raspberry Pi

Connection

Raspberry pi Grove - Ultrasonic Ranger GrovePi_Plus
enter image description here enter image description here enter image description here
Get ONE Now Get ONE Now Get ONE Now
  • Follow instruction to configure the development environment.
  • Connect Ultrasonic ranger to Port D4 and Run the program below. It will print distance information on you terminal, as the figure below.

Software

# GrovePi + Grove Ultrasonic Ranger

from grovepi import *

# Connect the Grove Ultrasonic Ranger to digital port D4
# SIG,NC,VCC,GND

ultrasonic_ranger = 4

while True:
    try:
        # Read distance value from Ultrasonic
        print ultrasonicRead(ultrasonic_ranger)

    except TypeError:
        print "Error"
    except IOError:
        print "Error"

Run The Program

  • Find the path to the file(According to your own path)
 cd GrovePi/Software/Python/
  • Run Program
 sudo python grove_ultrasonic.py
  • Here is the result.

If you want to make some awesome projects by Grove - Ultrasonic Ranger, here are some projects for your reference.

Automatic Water Level Controller

There are many ways like using a float sensor to determine the water level, or using probes to detect peak and low level in the tank. How to measure water level without using probe or contacting with water? yeah there is a way just using a Ultrasonic sensor, and it is very simple! You can even determine the water depth in the tank by setting the maximum and minimum level.

Indoor Lightning Cloud

Make an indoor lightning Cloud, hang it to your ceiling, to make a joke, blast whoever passing under it, have fun!

The Color Helix

Our artist Shihui Wang recently showed me her another amazing work of art: the Colour Helix. Again with few simple components she presented us the beauty of the combination of art and electronics.

With a Grove - Ultrasonic Ranger she can magically control the number of illuminated LEDs inside the Helix by raising or lower her palm in the air.

Resources



ArduinoWioBeagleBoneRaspberry PiLinkIt ONE

Caution

The platforms mentioned above as supported is/are an indication of the module's hardware or theoritical compatibility. We only provide software library or code examples for Arduino platform in most cases. It is not possible to provide software library / demo code for all possible MCU platforms. Hence, users have to write their own software library.

Techsupport

For any technical issue, you are most welcome to contact techsupport@seeed.cc, our techsupport engineers will help you. Thank you!

Help us make it better

Welcome to the new documentation system of Seeed Studio. We have made a lot of progress comparing to the old wiki system and will continue to improve it to make it more user friendly and helpful. The improvement can't be done without your kindly feedback. If you have any suggestions or findings, you are most welcome to submit the amended version as our contributor via Github or give us suggestions in the survey below, it would be more appreciated if you could leave your email so that we can reply to you. Happy Hacking!