[Diao Ye learns programming] Arduino hands-on (58) --- HC-SR04 ultrasonic sensor module 3

insert image description here

The reference to 37 sensors and modules has been widely circulated on the Internet. In fact, there must be more than 37 sensor modules compatible with Arduino. In view of the fact that I have accumulated some sensor and actuator modules on hand, in accordance with the concept of true knowledge (must be hands-on), for the purpose of learning and communication, here I am going to try and do more experiments one by one. Whether it is successful or not, it will be recorded ——Small progress or unsolvable problems, I hope to be able to throw bricks and spark jade.

[Arduino] 168 kinds of sensor module series experiment (data code + simulation programming + graphic programming)
Experiment 58: wide voltage HC-SR04 ultrasonic module 3.3V-5V distance sensor board with UART IIC interface

insert image description here

3. HC-SR04 Ultrasonic Range Finder Sensor Module
1. This HC-SR04 - Ultrasonic Range Finder is a very popular sensor that can be found in many applications that need to measure distance and detect objects. There are two eye-shaped items on the front of the module that form the ultrasonic transmitter and receiver.

The HC-SR04 ultrasonic sensor uses sonar to determine the distance to objects such as bats or dolphins. This ultrasonic sensor module is a transmitter, a receiver and a control circuit in one package! ! It has a very convenient and compact structure. It offers excellent range accuracy and stable readings in an easy-to-use package. Its operation is not affected by sunlight or black materials like sharp rangefinders (although acoustically soft materials like cloth are difficult to detect).

The Trigger and Echo pins are the I/O pins of this module, so they can be connected to the I/O pins of the microcontroller/Arduino. When the receiver detects a return wave, the Echo pin goes high for a specific time, which will be equal to the time it takes for the wave to return to the sensor. Ultrasonic distance sensors provide very short (2CM) to long distance (4M) detection and ranging. The sensor provides precise and stable non-contact distance measurement from about 2 cm to 4 meters with very high accuracy. It can be easily interfaced with any microcontroller. The module sends 8 40Khz square wave pulses and automatically detects whether a return signal is received. Send a high pulse on the echo pin if there is a signal coming back. The length of this pulse is the time it takes for the signal to return an echo from the first trigger.

insert image description here

2. Module electrical schematic diagram

insert image description here
3. Main technical specifications of the module
(1) Wide voltage: DC—3.3V-5V
(2) Quiescent current: less than 2mA
(3) Level output: high 5V (4
) Level output: bottom 0V
(5) Induction angle: No more than 15 degrees
(6) Detection distance: 2cm-450cm
(7) High precision up to 0.2cm
(8) Wiring method: VCC, trig (control terminal), echo (receiving terminal), GND

4. Module performance parameters

insert image description here
5. Working principle of the module
First apply a 5V pulse with a duration of 10us on the Trig pin, and then the sensor will emit 8 40KHz ultrasonic pulses together with the transmitting transducer. At the same time, the Echo pin goes high and if the sound waves return to the sensor, the receiving transducer will catch them and the Echo pin will go low to generate a pulse of duration equal to the time the sound wave takes. Go from the sensor and back.

insert image description here
If there is no object in front of the sensor detection area (2cm to 4.5cm), the sound wave will not be reflected and the Echo pin will return LOW after a duration of 38ms. This pulse means that there is no object in front of the sensor.

insert image description here
6. A ranging example
Suppose there is a pulse of 280us on the echo pin, we need to divide this number by 2, because the pulse represents the time it takes for the wave to travel from the sensor and then return to the sensor. We also have the speed of sound in dry air at 20°C = 343m/s = 0.0343cm/us.

The formula is D = T * S, where D = distance, T = time and S = speed.

Then D = 0.0343 * 140 = 4.8cm

insert image description here
7. The HC-SR04 ultrasonic distance sensor module has 4 pins,
VCC and GND are connected to 5V and GND pins on the Arduino,
Trig and Echo are connected to any digital Arduino pins.
We use the Trig pin to send ultrasonic waves from the transmitter and the Echo pin to listen for the reflected signal.

insert image description here

Experimental environment of HC-SR04 ultrasonic ranging sensor module
1. Hardware list required for HC-SR04 ultrasonic ranging sensor module experiment

TM1637 four-digit digital tube X1
Arduino Uno development board X1
DuPont lines (9 pieces are prepared)
LED light-emitting diode (blue, green) X2
IIC/I2C 1602 LCD screen module X1
HC-SR04 ultrasonic distance sensor module X1
Proto Shield prototype Expansion board (with mini breadboard) X1

insert image description here
2. Software platforms required for sensor module experiments
Code programming Arduino IDE (version 1.8.19),
simulation programming Linkboy (version V4.6.3),
graphics programming Mind+ (version V1.7.0 RC2.0)
and learning by playing (online platform https ://ide.codepku.com/?type=Arduino)

3. Search and install "HC-SR04" related library
1. Open Arduino IDE - Tools - Manage Library, search for HC-SR04

insert image description here

2. Open the webpage https://github.com/, search for HC-SR04

insert image description here
4. Precautions for experiment
(1) This module should not be connected with electricity. If you want to connect with electricity, please connect the Gnd terminal of the module first. Otherwise it will affect the module work.
(2) When measuring the distance, the area of ​​the measured object should not be less than 0.5 square meters and should be as flat as possible. Otherwise it will affect the test results.
(3) It is recommended that the measurement period be more than 60ms to prevent the influence of the transmitted signal on the echo signal.
(4) If the test surface is not very regular or when testing a distant object, multiple measurements can be used to correct it.
(5) The interval between two tests should be greater than 200mS.
(6) The module is not suitable for testing very irregular objects and cotton objects.
(7) Echo is connected to D2 port to receive distance signal, Trig is connected to D3 port to trigger distance measurement. It takes about 60 seconds to warm up and stabilize after power on.
(8) HC-SR04 is a simple and general-purpose model without temperature compensation. The actual measurement error of 200CM is about 3CM.

5. Schematic diagram of experimental wiring

insert image description here

insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/weixin_41659040/article/details/132333623