edit

# Ultra Sonic range measurement module

Seeed ultrasonic sensor is non-contact distance measurement module, which is also compatible with electronic brick. It’s designed for easy modular project usage with industrial performance.

## Features¶

• Detecting range: 3cm-4m
• Best in 30 degree angle
• Electronic brick compatible interface
• 5VDC power supply
• Dual transducer

## Specification¶

 Supply voltage 5V Global Current Consumption 15 mA Ultrasonic Frequency 40k Hz Maximal Range 400 cm Minimal Range 3 cm Resolution 1 cm Trigger Pulse Width 10 μs Outline Dimension 43x20x15 mm

## Getting started¶

A short ultrasonic pulse is transmitted at the time 0, reflected by an object. The sensor receives this signal and converts it to an electric signal. The next pulse can be transmitted when the echo is faded away. This time period is called cycle period. The recommend cycle period should be no less than 50ms. If a 10μs width trigger pulse is sent to the signal pin, the Ultrasonic module will output eight 40kHz ultrasonic signal and detect the echo back. The measured distance is proportional to the echo pulse width and can be calculated by the formula above. If no obstacle is detected, the output pin will give a 38ms high level signal.

### Play with Arduino¶

#### Hardware¶

• Step 1. Prepare the below stuffs:
Seeeduino V4.2 Base Shield Ultra_Sonic_range_measurement_module
Get One Now Get One Now Get One Now
• Step 2. Connect Ultra_Sonic_range_measurement_module to port D2 of Grove-Base Shield.
• Step 3. Plug Grove - Base Shield into Seeeduino.
• Step 4. Connect Seeeduino to PC via a USB cable.

Note

If we don't have Grove Base Shield, We also can directly connect this module to Seeeduino as below.

Seeeduino ???
5V Red
GND Black
Not Conencted White
D2 Yellow

#### Software¶

Step 1. Copy the code and flash it into the controller board. Step 2. Upload the code and open monitor window.

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 #include "Arduino.h" class Ultrasonic { public: Ultrasonic(int pin); void DistanceMeasure(void); double microsecondsToCentimeters(void); double microsecondsToInches(void); private: int this_pin;//pin number of Arduino that is connected with SIG pin of Ultrasonic Ranger. long duration;// the Pulse time received; }; Ultrasonic::Ultrasonic(int pin) { this_pin = pin; } /*Begin the detection and get the pulse back signal*/ void Ultrasonic::DistanceMeasure(void) { pinMode(this_pin, OUTPUT); digitalWrite(this_pin, LOW); delayMicroseconds(2); digitalWrite(this_pin, HIGH); delayMicroseconds(5); digitalWrite(this_pin,LOW); pinMode(this_pin,INPUT); duration = pulseIn(this_pin,HIGH); } /*The measured distance from the range 0 to 400 Centimeters*/ double Ultrasonic::microsecondsToCentimeters(void) { return duration/29.0/2.0; } /*The measured distance from the range 0 to 157 Inches*/ double Ultrasonic::microsecondsToInches(void) { return duration/74.0/2.0; } Ultrasonic ultrasonic(2); void setup() { Serial.begin(9600); } void loop() { double RangeInInches; double RangeInCentimeters; ultrasonic.DistanceMeasure();// get the current signal time; RangeInInches = ultrasonic.microsecondsToInches();//convert the time to inches; RangeInCentimeters = ultrasonic.microsecondsToCentimeters();//convert the time to centimeters Serial.println("The distance to obstacles in front is: "); Serial.print(RangeInInches);//0~157 inches Serial.println(" inch"); Serial.print(RangeInCentimeters);//0~400cm Serial.println(" cm"); delay(1000); } 

## Tech Support¶

Please submit any technical issue into our forum or drop mail to techsupport@seeed.cc.