QB042 Ultrasonic Sensor

1.Product Introduction

../../_images/Ultrasonic-1.png

Ultrasonic sensor is a sensor used to measure distance, can be used to help the car to avoid obstacles or other related distance obstacle avoidance projects.

The ultrasonic transmitter emits ultrasonic waves in a certain direction, at the same time the timer starts timing, ultrasonic waves spread in the air, on the way to encounter obstacles will immediately return, ultrasonic receiver received reflected waves immediately stop timing. The propagation speed of sound wave in the air is 340m/s. According to the time t recorded by the timer, the distance s between the launching point and the obstacle can be calculated, that is, s=340*t/2.

Application reference: obstacle avoidance car, handheld range finder, water level monitoring, ultrasonic counter, etc.

2.Parameter Specification

Parameter Value//Description
Operating voltage 3.3V~5V
Operating temperature -40°C~+85°C
Range of distance measurement 3cm~500cm
Detection accuracy 0.1cm
Blind area of measurement <3cm
Frequency of emission 40KHz
Size 4.9cm*2.2cm
../../_images/Ultrasonic-5.jpg

3.Wiring Diagram

../../_images/Ultrasonic-2.png
Ultrasonic Sensor UNO
VCC 5V
GND GND
Echo Digital Pin 11
Trig Digital Pin 12

4.Sample Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
//www.acebott.com
#include "SR04.h"
#define TRIG_PIN 12
#define ECHO_PIN 11 
SR04 sr04 = SR04(ECHO_PIN,TRIG_PIN);//Initializing the ultrasonic sensor
long a;//Create a long integer variable to store the distance detected by the ultrasound

void setup() {
   Serial.begin(9600);//Initialization of Serial Port
   delay(1000);
}
void loop() {
   a=sr04.Distance();//Obtain the ultrasonic sensor detection value
   Serial.print(a);//The value of the ultrasonic sensor is displayed on the serial port
   Serial.println("cm");
   delay(1000);
}

5.Test Result

After uploading the code to the controller board, open the serial port monitor of the Arduino IDE and set the baud rate to 9600.

Move your hand or object in front of the sensor and you can see their distance value.

../../_images/Ultrasonic-3.png
../../_images/Ultrasonic-4.png

6.Related Resources

7.Get One Now