Saturday, August 13, 2016

Ultrasonic Sensor


INTRODUCTION:

Small low-cost ultrasonic distance measurement modules like this: SRF-06 are an effective way to sense the presence of nearby objects and the distance to them. Often Robots use these to sense objects or collisions and take appropriate action.







They have two transducers, basically a speaker and a microphone. Ultrasound is a high frequency sound (typically 40 KHz is used). A short burst of sound waves (often only 8 cycles) is sent out the "Transmit" transducer. Then the "Receive" transducer listens for an echo. Thus, the principle of ultrasonic distance measurement is the same as with Radio-based radar. Distance is calculated as: L = C × T/2 , where L is the length, C is the speed of sound in air, T is the time difference from the transmission from the transmitter to the receiver. This is divided by 2 for the two-directions the sound travels. Speed of sound is about: C = 344m / s (20 degrees C room temperature).

Speed of sound in air velocity is affected by the air density, and for high accuracy the temperature must be taken into account, either within the module electronics (In the SRF-06 module we have) or in the Arduino software.

Accuracy??

It's hard to get good information from the manufacturers. Here are numbers derived from some extensive tests
Note: The US-100 module has 5 pins but two are ground and 1 to 4 are the same.

To test a module with the following Software Sketch, connect 5.0V and Ground to your Arduino, and Trig to Arduino pin 11 and Echo to Arduino pin 10. This photo shows the easy way to do this using a wireduino nd part of a flat cable jumper

Software will do the following:
Turn the Trig pin on and off to send out a sound pulse
Monitor and time how long until the Echo pin sees the echo
Calculate the distance as shown above, possibly correcting for temperature



MATERIALS NEEDED:


1 PC


1 Keyboard and 1 Mouse


1 Wireduino Board


1 USB cable


1 US100 Ultrasonic Sensor


1 Battery or adaptor



PROCEDURE:

1. Connect 5.0V and Ground to your Arduino, and Trig to Arduino pin 11 and Echo to Arduino pin 10.






2. Below is a sample program for a single servo motor:


#include <NewPing.h>


#define TRIGGER_PIN 11

#define ECHO_PIN 10

#define MAX_DISTANCE 200


NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

int DistanceIn;

int DistanceCm;



void setup()

{

Serial.begin(9600);

Serial.println("UltraSonic Distance Measurement");

Serial.println("micro-ontroller.blogspot.com");

}



void loop()

{

delay(100);

DistanceIn = sonar.ping_in();

Serial.print("Ping: ");

Serial.print(DistanceIn);

Serial.print(" in ");

delay(100);

DistanceCm = sonar.ping_cm();

Serial.print("Ping: ");

Serial.print(DistanceCm);

Serial.println(" cm");


}






3 comments: