Control Lab 464-5
Control Lab 464-5
Control Lab 464-5
Experiment #5
Ultrasonic Sensor
• Ultrasonic is made up of two words “Ultra” meaning “Beyond” and “Sonic” meaning
“Sound”
• Sound waves in which the frequencies are above the limits of human audibility i.e. > 20 KHZ
are called Ultrasonic.
An ultrasonic sensor is an electronic device that measures the distance of a target object by
emitting ultrasonic sound waves “ pulse”, and converts the reflected sound into an electrical
signal “echo”
They have two main components: the transmitter (which emits the sound using piezoelectric
crystals) and the receiver (which encounters the sound after it has travelled to and from the
object “target”).
3
Ultrasonic sensors are often called as Sonar sensors and we can use them for many
applications like:
Since we can measure the time gap between the trigger signal and echo signal we can measure the distance to the
obstacle. (for normal calculations we take the speed of sound in Air as 340 m/s.
7
1.We need to transmit trigger pulse of at least 10 us to the HC-SR04 Trig Pin.
2.Then the HC-SR04 automatically sends Eight 40 kHz sound wave and wait for rising edge output at Echo pin.
3.When the rising edge capture occurs at Echo pin, start the Timer and wait for falling edge on Echo pin.
4.As soon as the falling edge is captured at the Echo pin, read the count of the Timer. This time count is the time required by
the sensor to detect an object and return back from an object.
8
9
Features of an Ultrasonic Sensor
13
Interfacing Ultrasonic with Arduino
15
Programming
16
pulseIn() pulseIn(pin, value)
Reads a pulse (either HIGH or LOW) on a pin. For example, if value is HIGH, pulseIn() waits for the
pin to go from LOW to HIGH, starts timing, then waits for the pin to go LOW and stops timing.
Returns the length of the pulse in microseconds or gives up and returns 0 if no complete
pulse was received within the timeout.
17