Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

 An ultrasonic sensor is an electronic device that measures the distance of a

target object by emitting ultrasonic sound waves, and converts the reflected
sound into an electrical signal.
 Ultrasonic sensors have two main components:
 Transmitter (which emits the sound using piezoelectric crystals)
 Receiver (which encounters the sound after it has travelled to and from the target).

 In order to calculate the distance between the sensor and the object, the
sensor measures the time it takes between the emission of the sound by the
transmitter to its contact with the receiver.
 The formula for this calculation is D = ½ T x C (where D is the distance, T is
the time, and C is the speed of sound ~ 343 meters/second).
DAY-5 Arduino Programming Workshop 2
 Ultrasonic sensors are used primarily as proximity sensors.
 They can be found in automobile self-parking technology, anti-collision safety
systems, robotic obstacle detection systems also used as level sensors to
detect, monitor, and regulate liquid levels in closed containers.

 The HC-SR04 ultrasonic sensor offers excellent non-contact range detection


with high accuracy and stable readings from 2 cm to 400 cm.

 It comes complete with ultrasonic transmitter and receiver module.

 The HC-SR04 Ultrasonic Module has 4 pins, Ground (Gnd), VCC (5V) , Trig
and Echo. The trig and echo pins to any Digital I/O pin on the Arduino Board.

DAY-5 Arduino Programming Workshop 3


 Steps involved in measuring distance using HC-SR04 Ultrasonic module are,
 Transmit trigger pulse of at least 10 us to the HC-SR04 Trig Pin.

 Then the HC-SR04 automatically sends Eight 40 kHz sound wave and wait for rising
edge at Echo pin.

 When the rising edge capture occurs at Echo pin, start the Timer and wait for falling
edge on Echo pin.

 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 (to and from).

DAY-5 Arduino Programming Workshop 4


Distance = (Speed x Time)/ 2
Distance = (0.034 cm/µs x 500 µs) / 2
Distance = 8.5 cm

When no obstacles then timeout after 38ms When obstacle detected pulse width of 50 µS to 25 mS received
DAY-5 Arduino Programming Workshop 5
Read the distance value from HC-SR04 and print it on serial monitor

Write a program to read distance value from HC-SR04 ultrasonic sensor module in cm
and print it on the serial monitor. Simulate and verify this logic on Arduino Uno using
Tinkercad circuits simulator.

pulseIn() - 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.

DAY-5 Arduino Programming Workshop 6


Program & output Design

DAY-5 Arduino Programming Workshop 7


Reverse parking sensor module
Write a program to design a reverse parking sensor module. This module consist of
HC-SR04 ultrasonic sensor, LCD and buzzer interfaced with Arduino. The ultrasonic
sensor continuously measure the distance (in cm) between the car and obstacle, then
display it on LCD. Whenever the measured distance is lesser than 30cm generate
warning signal to driver using buzzer also display a message “Obstacle !!!” on the first
row of the LCD display. Simulate and verify this logic on Arduino Uno using Tinkercad
circuits simulator.

DAY-5 Arduino Programming Workshop 8


DAY-5 Arduino Programming Workshop 9

You might also like