0% found this document useful (0 votes)
14 views5 pages

Ultrasonic Sensor Module

The document provides an overview of the HC-SR04 ultrasonic sensor module, detailing its functionality for distance measurement and obstacle avoidance. It includes required components, working principles, connection schematics, and coding instructions using a specific library. The document emphasizes the importance of proper setup and installation of the library for successful operation.

Uploaded by

mohammedmofreh99
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views5 pages

Ultrasonic Sensor Module

The document provides an overview of the HC-SR04 ultrasonic sensor module, detailing its functionality for distance measurement and obstacle avoidance. It includes required components, working principles, connection schematics, and coding instructions using a specific library. The document emphasizes the importance of proper setup and installation of the library for successful operation.

Uploaded by

mohammedmofreh99
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Lesson 10 Ultrasonic Sensor Module

Overview
Ultrasonic sensor is great for all kind of projects that need distance measurements,
avoiding obstacles as examples.
The HC-SR04 is inexpensive and easy to use since we will be using a Library
specifically designed for these sensor.

Component Required:
(1) x Elegoo Mega2560 R3
(1) x Ultrasonic sensor module
(4) x F-M wires (Female to Male DuPont wires)

Component Introduction
Ultrasonic sensor
Ultrasonic sensor module HC-SR04 provides 2cm-400cm non-contact measurement
function, the ranging accuracy can reach to 3mm. The modules includes ultrasonic
transmitters, receiver and control circuit. The basic principle of work:
(1) Using IO trigger for at least 10us high level signal,
(2) The Module automatically sends eight 40 kHz and detect whether there is a pulse
signal back.
(3) IF the signal back, through high level , time of high output IO duration is the time
from sending ultrasonic tore turning.
Test distance = (high level time × velocity of sound (340m/s) /2
The Timing diagram is shown below. You only need to supply a short 10us pulse to
the trigger input to start the ranging, and then the module will send out an 8 cycle
burst of ultrasound at 40 kHz and raise its echo. The Echo is a distance object that is
pulse width and the range in proportion .You can calculate the range through the
time interval between sending trigger signal and receiving echo signal. Formula: us
/ 58 = centimeters or us / 148 =inch; or: the range = high level time * velocity
(340M/S) / 2; we suggest to use over 60ms measurement cycle, in order to prevent
trigger signal to the echo signal.

80 / 223
Connection
Schematic

81 / 223
Wiring diagram

82 / 223
Code
Using a Library designed for these sensors will make our code short and simple.
We include the library at the beginning of our code, and then by using simple
commands we can control the behavior of the sensor.
After wiring, please open the program in the code folder- Lesson 10 Ultrasonic Sensor
Module and click UPLOAD to upload the program. See Lesson 2 for details about
program uploading if there are any errors.
Before you can run this, make sure that you have installed the < HC-SR04> library or
re-install it, if necessary. Otherwise, your code won't work.
For details about loading the library file, see Lesson 1.

Example picture

83 / 223
Open the monitor then you can see the data as blow:
Click the Serial Monitor button to turn on the serial monitor. The basics about the serial
monitor are introduced in details in Lesson 1.

84 / 223

You might also like