Grove Ultrasonic Ranger¶
Using ultrasonic grove sensor from Seedstudio to detect obstacle or measure range.
Specification¶
Parameter | Value/Range |
---|---|
Operating voltage | 3.3~5V |
Operating current | 15mA |
Ultrasonic frequency | 42kHz |
Measuring range | 3-400cm |
Resolution | 1cm |
Output | PWM |
Wiring¶
Sketch¶
Download and move this library to the Arduino library folder.
For more info how to install this library see the Getting Started page.
#include "Ultrasonic.h"
// Connect the signal pin of the sensor to Digital pin 7 on the Autonomo
Ultrasonic ultrasonic(7);
void setup (){
Serial.begin(9600);
}
void loop(){
long RangeInInches;
long RangeInCentimeters;
// Measure the distance to the Obstacle in Inches
SerialUSB.println("The distance to obstacles in front is: ");
RangeInInches =ultrasonic.MeasureInInches();
SerialUSB.print(RangeInInches); //0~157 inches
SerialUSB.println(" inch");
delay(250);
// Measure the distance to the Obstacle in Centimeters
RangeInCentimeters =ultrasonic.MeasureInCentimeters();
// two measurements should keep an interval
SerialUSB.print(RangeInCentimeters); //0~400cm
SerialUSB.println(" cm");
delay(250);
}