Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Lesson 11 Ultrasonic Sensor Module

This lesson teaches how to use the HC-SR04 Ultrasonic Sensor for distance measurements in various projects. It includes hardware requirements, principles of operation, code interpretation, and step-by-step experimental procedures for setting up the sensor with an Arduino UNO R3. The document also provides troubleshooting tips for ensuring proper functionality.

Uploaded by

Euronymous
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Lesson 11 Ultrasonic Sensor Module

This lesson teaches how to use the HC-SR04 Ultrasonic Sensor for distance measurements in various projects. It includes hardware requirements, principles of operation, code interpretation, and step-by-step experimental procedures for setting up the sensor with an Arduino UNO R3. The document also provides troubleshooting tips for ensuring proper functionality.

Uploaded by

Euronymous
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Lesson 11 HC-SR04 Ultrasonic Sensor

Module

Introduction

In this lesson, you will learn how to use an HC-SR04 Ultrasonic Sensor to
distance measurements,which is great for all kind of projects that need
distance measurements,avoiding obstacles as examples.

Hardware Required

 1 * RexQualis UNO R3

 1 * Ultrasonic Sensor Module

 4 * F-M Jumper Wires

Principle

HC-SR04 Ultrasonic Sensor Module

Ultrasonic Sensor emits ultrasound at 40000 Hz which travels through the air
and if there is an object or obstacle on its path It will bounce back to the
module. Considering the travel time and the speed of the sound you can
calculate the distance.

In order to generate the ultrasound ,you need to set the Trig on a High State for
10us. That will send out an 8 cycle sonic burst which will travel at the speed
sound and it will be received in the Echo pin. The Echo pin will output the time
in microseconds the sound wave traveled.
Test distance = (high level time × velocity of sound (340m/s) /2

For example, if the object is 10 cm away from the sensor, and the speed of the
sound is 340 m/s or 0.034 cm/µs the sound wave will need to travel about 294
u seconds. But what you will get from the Echo pin will be double that number
because the sound wave needs to travel forward and bounce backward. So
in order to get the distance in cm we need to multiply the received travel time
value from the echo pin by 0.034 and divide it by 2.

Code interpretation

#include "SR04.h"

#define TRIG_PIN 12 //pin 12 on the arduino

#define ECHO_PIN 11 //pin 11 on the arduino

SR04 sr04 = SR04(ECHO_PIN,TRIG_PIN);

long a;

void setup() {
Serial.begin(9600);

delay(1000);

void loop() {

a=sr04.Distance();

Serial.print(a);

Serial.println("cm");

delay(1000);

Experimental Procedures

Step 1:Build the circuit

The HC-SR04 Ultrasonic Module has 4 pins, Ground, VCC, Trig and Echo.
The Ground and the VCC pins of the module needs to be connected to the
Ground and the 5 volts pins on the Arduino Board respectively and the trig and
echo pins to any Digital I/O pin on the Arduino Board.
Schematic Diagram
Step 2:Open the code:HC-SR04_Ultrasonic_Sensor_Module_Code
Step 3: Attach Arduino UNO R3 board to your computer via
USB cable and check that the 'Board Type' and 'Serial Port' are
set correctly.

Step 4: Load the Library:HC-SR04


Step 5:Upload the code to the RexQualis UNO R3 board.

Step 6:Open the Serial Monitor then you can see the data as
below:

(How to use the Serial Monitor is introduced in details in


Lesson 0 Preface)
Then, You can test the distance between the ultrasound
module and the wall by moving the ultrasound module,and it
will show on the monitor.
If it isn’t working, make sure you have assembled the circuit
correctly, verified and uploaded the code to your board. For
how to upload the code and install the library, check Lesson 0
Preface.

You might also like