本网页已闲置超过3分钟,按键盘任意键或点击空白处,即可回到网页
最热资讯


在本项目中,我们将使用超声波传感器来测量距离,检测物体并以常用的测量单位提供O / P。
硬件组件:
软件应用程序和在线服务:
可以在超声波传感器和Arduino之间直接建立连接(或),也可以使用Breadboard实现相同的功能。
• 将超声波传感器的Vcc引脚连接到Arduino上的5V
• 将超声波传感器的GND引脚连接到Arduino上的GND
• 将超声波传感器的Trig引脚连接到Arduino上的D6
• 将超声波传感器的回波针连接到Arduino上的D5
带有Arduino的超声波传感器-使用面包板的电路连接:
超声波传感器具有广泛的应用,例如距离测量,物体检测,避障等。
该项目的设计牢记要寻找使用Arduino的超声波传感器的基本设置的人员。任何类型的Arduino均可用于此项目。
工作非常简单,按照电路图进行连接并打开电源后,超声波传感器就会发送声波。当波与物体接触时,它们会反弹回传感器。因此,通过将速度乘以时间来计算距离。此处的速度是指声音的速度,即每秒340米。以厘米/微秒为单位为0.034,以英寸/微秒为单位0.0133858。我们必须将速度除以2,因为声波在撞击物体后向前传播并返回。
另一方面,时间是声波向前传播和向后反弹所花费的持续时间。因此,很容易确定物体与超声波传感器的距离。
您可以在下面的代码中找到计算。
在串行监视器中看到的输出:
相关代码:
/*
* Credits to all sources on Google, acting as reference to this code below. This code is not
* TechValer's own creation. TechValer has referred to different projects and websites to
* find an easy code for beginners to get started with Ultrasonic Sensor HC-SR04 and Arduino.
* TechValer does not claim this code to be its own. TechValer is greatly thankful for original
* creaters of this code and also all others who acted as reference.
*/
/*
* About TechValer
*
* What comes to mind when you think of tech...hmm, I'm sure you're thinking of iPhone,
* Alexa, Boston Dynamics robotic dog etc., at least that's what I would have thought of.
* My point here is, when you look inside this tech...you'll find weird boards with
* components attached to it. This stuff is electronics and we at Techvaler deeply appreciate
* this piece of tech. As the name suggests, we are Tech Enthusiasts who know the Worth and
* Potential of these amazing tech stuff! So, check out our website techvaler.com to find out
* more. I'm sure you will not regret...
*/
/*
* Note: Any model of Arduino can be used for this project. Just keep in mind the digital pins.
* The readings available in the serial monitor are almost accurate.
* Refer to the documentation for better understanding of this particular code and project.
*/
/*
* Thanks to Drona Automations Pvt.Ltd for Sponsoring this project!
*/
#define trigPin 6 // Connect trigpin to D6 on Arduino
#define echoPin 5 // Connect echopin to D5 on Arduino
// defines variables
long duration; // It's a variable for the duration of sound wave travel
int inchdistance; // It's a variable for measurement of distance in inches
int cmdistance; // It's a variable for measurement of distance in centimeters
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an OUTPUT
pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT
Serial.begin(9600); // // For Serial Communication
}
void loop() {
digitalWrite(trigPin, LOW); // Clears the trigPin condition
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH); // Reads the echoPin, returns the sound wave travel time in microseconds
// Calculating the distance
inchdistance = duration * 0.0133858 / 2; // To calculate the distance in inch
cmdistance = duration * 0.034 / 2; // To calculate the distance in cm
// Displays the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.print(inchdistance);
Serial.println(" inch");
Serial.print(cmdistance);
Serial.println(" cm");
}
用MCU的方式玩FPGA——Arduino MKR Vidor 4000评测
2018-11-26
基于esp8266的便携式无线PM2.5检测电路设计
2020-02-07
基于MEMS的惯性测量装置 (IMU) 检测电路设计
2020-02-06
基于Arduino+HC-05蓝牙模块的只能门禁系统电路设计
2020-02-03
基于PGA460-Q1器件的传感检测诊断电路设计
2020-02-17
基于树莓派和Arduino打造的PLC EtherCAT电路设计
2020-02-25
Arduino最小系统板设计PCB板及原理图
2020-01-17
远离冠状病毒,非接触式洗手液分配装置DIY
2020-03-18
入门指南:TFT彩色显示屏,带Arduino和ESP8266
2020-04-23
神创意!基于Arduino开发板以及电机diy的一个绘制时间的激光时钟
2020-01-14
讨论