1.Product Introduction
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 |
3.Wiring Diagram
Ultrasonic Sensor | UNO |
---|---|
VCC | 5V |
GND | GND |
Echo | Digital Pin 11 |
Trig | Digital Pin 12 |
4.Sample Code
1//www.acebott.com
2#include "SR04.h"
3#define TRIG_PIN 12
4#define ECHO_PIN 11
5SR04 sr04 = SR04(ECHO_PIN,TRIG_PIN);//Initializing the ultrasonic sensor
6long a;//Create a long integer variable to store the distance detected by the ultrasound
7
8void setup() {
9 Serial.begin(9600);//Initialization of Serial Port
10 delay(1000);
11}
12void loop() {
13 a=sr04.Distance();//Obtain the ultrasonic sensor detection value
14 Serial.print(a);//The value of the ultrasonic sensor is displayed on the serial port
15 Serial.println("cm");
16 delay(1000);
17}
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.
6.Related Resources
7.Get One Now
B2B Business: info@acebott.com