Measure Distance with UltraSonic Distance Sensor (PWM O/P)

The “ECHO”(PWM) ,Ultrasonic Distance Sensor from Rhydolabz is an amazing product that provides very short (2 cm) to long-range (400 cm) detection and ranging. The sensor provides precise,Stable non-contact distance measurements from about 2 cm to 400 cm with very high accuracy. Its compact size, higher range and easy usability make it a handy sensor for distance measurement and mapping. The board can easily be interfaced to microcontrollers where the triggering and measurement can be done using Single I/O pin. The sensor transmits an ultrasonic wave and produces an output pulse that corresponds to the time required for the burst echo to return to the sensor. By measuring the echo pulse width, the distance to target can easily be calculated.

 This UltraSonic Distance Sensor is perfect for any number of applications that require you to perform measurements between moving or stationary objects. Naturally, robotics applications are very popular but you’ll also find this product to be useful in security systems or as an infrared replacement if so desired.This is extreamily suitable for Roboic Application, since it need only one I/O pin and very fast. The “ECHO”(PWM) does not require any ADC or USART to meassure the distance. Since it is very stable ,the “ECHO”(PWM) Ultrasonic sensor module can be used for Micromouse application instead of IR sensor

Features:

  • Professional EMI/RFI Complaint PCB Layout Design for Noise Reduction
  • Range: 2 cm to 400 cm 
  • Accurate and Stable range data
  • Data loss in Error zone eliminated
  • Modulation at 40 Khz
  • Mounting holes provided on the circuit board
  • Triggered externally by supplying a pulse to the signal pin
  • 5V DC Supply voltage
  • Bidirectional TTL pulse interface on a single I/O pin can communicate with 5 V TTL or 3.3V CMOS microcontrollers 
  • Comparable to Parallax PING.
  • Echo pulse: positive TTL pulse, 87 µs minimum to 30 ms maximum(PWM) 
  • On Board Burst LED Indicator shows measurement in progress
  • 3-pin header makes it easy to connect using a servo extension cable, no soldering required
PIN Diagram:
  • UltraSonic Distance Sensor (PWM O/P) PIN descriptions are as below
 Layout:

COMMUNICATION PROTOCOL:Communication protocol based on ,Ultrasonic Distance Sensor(PWM) as shown below

Under control of a host microcontroller (trigger pulse), the ECHO(PWM) sensor emits a short 40 kHz (ultrasonic) wave. This burst travels through the air, hits an object and then bounces back to the sensor.The ECHO (PWM) sensor provides an output pulse,to the host (through its signal pin) when the echo is detected; hence the distance to the target can be measured from the width of this pulse. Timing of sensor parameters are shown below.

PRACTICAL CONSIDERATION FOR USE

Object Positioning :

The ECHO(PWM) sensor cannot accurately measure the distance to an object that:

  • That has its reflective surface at a shallow angle so that sound will not be reflected back towards the sensor (Angle θ < 90°) or is more than 4 meters away,that is shown below.
  • Is too small to reflect enough sound back to the sensor.
    In addition, if your ECHO(PWM) sensor is mounted low on your device, you may detect sound reflecting off the floor.Positioning of Ultrasonic Distance Sensor(PWM) as shown below

Calculations to be performed by your Host microcontroller:

  • Speed of ultrasonic wave is 347 m/s equivalent to 0.0347cm/µsec(Temperature dependent)Timer count multiplied with 200nsec (0.2µsec ), internal clock period gives the echo time (say, Et).
  • As per the eqn: Speed = distance/time => echo distance (Ed) = echo speed(Ev) *echo time(Et) ie, distance (Ed) = 0.0347cm per µsec (Ev) * Et µsec
    The obtained distance will be twice the actual distance since it gives the to and fro distance of the object as per the to and fro time equated to the equation: (ie, Et stands for 2Et).

Thus the obtained distance divided by 2 gives actual distance of the obstacle.
ie, Actual distance = Ed/2.As per the above illustration your equation is,

Ed = Ev *(Et/2) implies Et = 2 * Ed /Ev equivalent to Et = (2/0.0347) *Ed
Implies Et = 58 *Ed equivalent to Ed (in cm) = Et(in µsec)/58

Output waveform:

  • The width of the wave increases with increase in distance between ultrasonic sensor and obstacle.Above graph shows the width of wave i.e 11.617ms.Using this graph we can calculate the distance of object  from the sensor.Using above equation the resulting distance of the wave is 200cm.

ie,     Ed (in cm) = Et(in µsec)/58 ,
Echo time(Et)=11617 us
Ed=116170/58
Ed=200.29cm   

  • Above graph shows wave with width of 1.336ms(distance between sensor and obstacle) and the calculated distance is 23 cm.
    ie,    Ed (in cm) = Et(in µsec)/58 ,
    Echo time(Et)=1336 us
    Ed =1336/58
    Ed=23cm 
 

  • Above graph shows wave with  width of .271 ms(distance between sensor and obstacle) and the calculated distance is 4.67cm.
    ie,    Ed (in cm) = Et(in µsec)/58 ,
    Echo time(Et)=271 us
     Ed=271/58
     Ed= 4.67cm

How to Test:1. Test UltraSonic Distance Sensor ( PWM O/P) with Arduino  

  • Connection of UltraSonic Distance Sensor (PWM O/P)with Arduino board is as follows and connection is shown below: “5V”(Red jumper wire) pin  of sensor is directly connected 5V of the Arduino board. “GND” (Black jumper wire) pin of sensor  is connected to the “GND” pin of the Arduino board.”SIG”(signal,Blue jumper wire) pin of sensor is directly  connected “8” pin of  Arduino board.
  • In the above figure, the “SIG”(signal I/O) pin of the ECHO(PWM) sensor is connected to PIN8 of the Arduino board. PIN8 of your host controller has to be configured to both input and output accordingly to the function. It is your host controller that has to trigger the functioning of an ECHO(PWM) senor. At this time the pin PIN8 of the host controller has to be configured as output so that it can give (o/p) a trigger signal to the sensor. The trigger pulse should be of range 10µsec – 100µsec, typical value is 10µsec. 
  • After triggering the sensor, pin PIN8 has to be configured as input so that your host controller switches to the receiving mode. Any pin configured as input should be provided with either pull-up or pull-down voltages so that it isn’t affected by small static field variations. But here no external pull-ups or pull-downs are required since, the signal I/O pin of the ECHO(PWM) sensor which is connected to pin PIN8 has been provided with pull-down on-board. 
  • In the receiving mode, the host controller has to wait for the Low to High transition in the SIG pin. When a transition is detected, the host controller should start counting the time. The host controller can use a timer or any other programming logic to calculate the time. The counting should terminate when the next High to Low transition is detected. The time gap between transitions will vary (PWM) with respect to the distance to the target. The obtained value (pulse-width) in µSeconds represents the echo time and further calibrations of this data gives you the obstacle distance. ie, the echo time in micro-seconds divided by 58 (at 30° C) gives you the obstacle distance in centimeters and the same divided by 148 (at 30° C) gives the distance in inches. i.e Echo time in µsec /58 = distance in cm and Echo time in µsec /148= distance in inches. The calculated distance can be transmitted to your PC.

 Testing with Arduino board, sample program is shown below.

  • Triggering PIN 8 pin of Arduino board gives pulse which travels through the air, hits an object and then bounces back to the sensor. Hence the distance to the target can be measured from the width of this pulse.

  •  When Arduino board connected  with ultrasonic sensor(PWM),the distance value is displayed  on serial monitor  is as shown below
2. Interface  UltraSonic Distance Sensor ( PWM O/P) with PIC16F877A

Connection details of  UltraSonic Distance Sensor ( PWM O/P) with PIC16F877A is shown below  

  • In the above  figure, the “SIG”(signal I/O) pin of the ECHO(PWM) sensor is connected to RB2 (Pin<35>) of the HOST controller. Pin RB2 of your host controller has to be configured to both input and output accordingly to the function. It is your host controller that has to trigger the functioning of an ECHO(PWM) senor. At this time the pin RB2 of the host controller has to be configured as output so that it can give (o/p) a trigger signal to the sensor. The trigger pulse should be of range 10µsec – 100µsec, typical value is 10µsec. 
  • After triggering the sensor, pin RB2 has to be configured as input so that your host controller switches to the receiving mode. Any pin configured as input should be provided with either pull-up or pull-down voltages so that it isn’t affected by small static field variations. But here no external pull-ups or pull-downs are required since, the signal I/O pin of the ECHO(PWM) sensor which is connected to pin RB2 has been provided with pull-down on-board. 
  • In the receiving mode, the host controller has to wait for the Low to High transition in the SIG pin. When a transition is detected, the host controller should start counting the time. The host controller can use a timer or any other programming logic to calculate the time. The counting should terminate when the next High to Low transition is detected. The time gap between transitions will vary (PWM) with respect to the distance to the target. The obtained value (pulse-width) in µSeconds represents the echo time and further calibrations of this data gives you the obstacle distance. ie, the echo time in micro-seconds divided by 58 (at 30° C) gives you the obstacle distance in centimeters and the same divided by 148 (at 30°C)   gives the distance in inches.   i.e Echo time in µsec /58 = distance in cm and Echo time in µsec /148= distance in inches. The calculated distance can be transmitted to your PC.

Testing with PIC16F877A,sample program is shown below.

  • Triggering RB2 pin of PIC16F877A gives pulse which travels through the air, hits an object and then bounces back to the sensor. Hence the distance to the target can be measured from the width of this pulse.

  • When PIC16F877A connected  with ultrasonic sensor(PWM),the distance value is displayed  on serial monitor  as shown below 

How to Buy:Click here to buy rhydoLABZ UltraSonic Distance Sensor (PWM O/P)
Click here to buy rhydoLABZ USB to Serial Converter (5V/3V3)
Click here to buy rhydoLABZ UltraSonic Distance Sensor (Serial Ascii O/P) 

Support:Please share your ideas with us, visit our forum for discussion 

Frequently Asked Questions(FAQ):Q.Which type of target object material will effect this sensor?
Ans.In addition, objects that absorb sound or have a soft or irregular surface, such as a stuffed animal, may not reflect enough sound to be detected accurately. The ECHO sensor will detect the surface of water; however it is not rated for outdoor use or continual use in a wet environment. Condensation on its transducers may affect performance and lifespan of the device.

Q.How this sensor effect Air Temperature?
Ans.Temperature has an effect on the speed of sound in air that is measured by the ECHO sensor. If the temperature (degree Celsius) is known, the formula is
C_air = 331.5 + (0.6 * Tc)m/s
The percent error over the sensor’s operating range of 0 to 70 ° C is significant, in the magnitude of 11 to 12 percent. The use of conversion constants to account for air temperature may be incorporated into your program.

Q.What are the measurable distance of UltraSonic Distance Sensor (PWM O/P)?
Ans.The sensor provides precise,Stable non-contact distance measurements from about 2 cm to 400 cm with very high accuracy

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">