超声波介绍 HC SR04 Ultrasonic Module User Guide

HC-SR04_Ultrasonic_Module_User_Guide

User Manual: Pdf

Open the PDF directly: View PDF PDF.
Page Count: 6

1
HC-SR04
HC-SR04
HC-SR04
HC-SR04 User
User
User
User Guide
Guide
Guide
Guide
Part
Part
Part
Part 1
1
1
1 U
U
U
U ltrasonic
ltrasonic
ltrasonic
ltrasonic Introduction
Introduction
Introduction
Introduction
1.
1.
1.
1. 1
1
1
1 Ultrasonic
Ultrasonic
Ultrasonic
Ultrasonic Definition
Definition
Definition
Definition
The human ear can hear sound frequenc y around 20HZ ~ 20KHZ, and
ultraso nic is the sound wave beyond the human ability of 20KHZ .
1.2
1.2
1.2
1.2 Ultrasonic
Ultrasonic
Ultrasonic
Ultrasonic distance
distance
distance
distance measurement
measurement
measurement
measurement principle
principle
principle
principle
Ultrasonic transmitter emit ted an ultrasonic wave in one direction, and started
timing when it launch ed. U ltrasonic spread in the air, and would return
immediately when it encounter ed obstacles on the way . At last, the ultrasonic
receiver would stop timing when it receive d the reflected wave. As Ultras onic
spread velocity is 340m / s in the air , based on the timer record t
t
t
t, we can
calculate the distance (s) between the obstacle and transmitter, namely: s =
340t / 2, which is so- called time difference distance measurement principle
The principle of ultrasonic distance measurement use d the already- known air
spreading velocity, measuring the time from launch to reflection when it
encountered obstacle , and then calculate the distance between the transmitter
and the obstacle according to the time and the velocity. Thus, the principle of
ultrasonic distance measurement is the same with radar.
Distance Measurement formula is expressed as: L = C X T
In the formula , L is the measured distance, and C is the ultrasonic spreading
velocity in air, also, T represents time (T is half the time value from transmit ting
to receiving ).
2
1.3
1.3
1.3
1.3 Ultrasonic
Ultrasonic
Ultrasonic
Ultrasonic Application
Application
Application
Application
U ltrasonic Application
T
echnology is the thing which developed in recent
decades . W ith the ultraso nic advance , and the electronic technology
development, especially as high-power semiconductor device technology
matures, the application of ultra sonic has become increasingly widespread:
Ultrasonic measurement of distance, depth and thickness;
Ultrasonic testing;
Ultrasound imaging;
Ultrasonic machining, such as polishing, drilling;
Ultrasonic cleaning;
Ultrasonic welding;
Part
Part
Part
Part 2
2
2
2 HC-SR04
HC-SR04
HC-SR04
HC-SR04 Ultrasonic
Ultrasonic
Ultrasonic
Ultrasonic Module
Module
Module
Module Introductio
Introductio
Introductio
Introductio n
n
n
n
2.1
2.1
2.1
2.1 Product
Product
Product
Product Features
Features
Features
Features
Stable performance
A ccurate distance measure ment
H igh-density
S mall blind
A
A
A
A pplication
pplication
pplication
pplication A
A
A
A reas:
reas:
reas:
reas:
Robotics barrier
O bject distance measurement
L evel detection
P ublic security
P arking detection
3
2.2
2.2
2.2
2.2 Product
Product
Product
Product Image
Image
Image
Image
2.3
2.3
2.3
2.3
Module
Module
Module
Module pin
pin
pin
pin definitions
definitions
definitions
definitions
Types Pin Symbol Pin Function Description
HC-SR04
VCC 5V power supply
Trig Trigger pin
Echo Receive pin
GND Power ground
2.4
2.4
2.4
2.4
Electrical
Electrical
Electrical
Electrical parameters
parameters
parameters
parameters
Electrical P arameters HC-SR04 Ultrasonic Module
Operating Voltage DC-5V
Operating Current 15mA
Operating Frequency 40KHZ
Farthest Range 4m
Nearest Range 2cm
Measuring A ngle 15 Degree
Input T rigger S ignal 10us TTL pulse
Output Echo S ignal
O utput TTL l evel s ignal, proportional
with range
Dimensions 45*20*15mm
4
2.5
2.5
2.5
2.5 Module
Module
Module
Module operating
operating
operating
operating Principle
Principle
Principle
Principle
S et low the Trig and Echo port when the module initialize s , firstly, transmit
at least 10us high level pulse to the Trig pin (module automatically sends eight
40K square wave), and then wait to capture the rising edge output by echo port,
at the same time, open the timer to start timing. Next, once again capture the
falling edge output by echo port , at the same time, read the time of the counter,
which is the ultrasonic running time in the air . A ccord ing to the formular: test
distance = (high level time * ultrasonic spreading velocity in air ) / 2 , you can
calculate the distance to the obstacle .
Part3
Part3
Part3
Part3 Use
Use
Use
Use Freaduino
Freaduino
Freaduino
Freaduino UNO
UNO
UNO
UNO to
to
to
to test
test
test
test HC-SR04
HC-SR04
HC-SR04
HC-SR04
3.1
3.1
3.1
3.1 Freaduino
Freaduino
Freaduino
Freaduino uno
uno
uno
uno and
and
and
and HC-SR04
HC-SR04
HC-SR04
HC-SR04 Connection
Connection
Connection
Connection
Connection Description D2<------>Trig D3<------>Echo ( The user s
can define the connection pin by themselves)
Note You need to set the Freaduino UNO switch in 5V Side when use
together with HC-SR04 Module.
5
3.2
3.2
3.2
3.2 HCSR04
HCSR04
HCSR04
HCSR04 library
library
library
library function
function
function
function description
description
description
description
Long
Long
Long
Long timing()
timing()
timing()
timing()
Function name: timing
Parameters: None
Return Value: the time of ultrasonic from the transmitter to the receiver
float
float
float
float CalcDistance(long
CalcDistance(long
CalcDistance(long
CalcDistance(long microsec,int
microsec,int
microsec,int
microsec,int metric)
metric)
metric)
metric)
Function name
CalcDistance
microsec: the time of ultrasonic from the transmitter to the receiver
metric: Set the unit of the return value ( the value of 1 for cm, and the value
of 0 for in )
Return Value : the measured distance
3.3
3.3
3.3
3.3 Add
Add
Add
Add the
the
the
the HC-SR04
HC-SR04
HC-SR04
HC-SR04 Library
Library
Library
Library
Step1:Download the Demo Code of HCSR04 Ultrasonic from address
http://www.elecfreaks.com/store/download/product/Sensor/HC-SR04/HCSR04Ultrasonic_demo.zip and
then unpack it to get the file of HCSR04 Ultrasonic .
Step2: Add the file of HCSR04 Ultrasonic in the file of Arduino-1.0.X / libraries.
Step3:If you can see the Example of HCSR04 Ultrasonic in Arduino IDE, the
adding of HC-SR04 library has been successful.
3.4
3.4
3.4
3.4 Test
Test
Test
Test the
the
the
the Module
Module
Module
Module with
with
with
with the
the
the
the Examples
Examples
Examples
Examples of
of
of
of Library
Library
Library
Library File
File
File
File
1. Open Arduino IDE 1.0.X, and choose the corresponding board and
serial port.
2. Click file/ examples/ HCSR04Ultrasonic until the code pop up.
3. Compiling sketch until Done uploading appears, which represents the
uploading has been successful.
4. Open serial monitor and set the corresponding BaudRate.
5. If you see similar information in serial monitor as below, you succeeded.
6
Chart 3 HC-SR04 testing results

Navigation menu