使用Arduino和超声波传感器测量声速

news2024/7/7 17:35:17

使用Arduino和超声波传感器测量声速

Step 1: 硬件

在这里插入图片描述

  1. Arduino Uno单片机
  2. 超声波传感器(HC-SR04)
  3. 标尺
  4. 跳线(母/公)
  5. 计算器

Step 2: Arduino Uno 微控制器

The Arduino Uno is a credit card size microcontroller board.
Arduino Uno是一款信用卡大小的微控制器板。

It has the following important components:
它具有以下重要组件:

  • Power pins 电源引脚

  • 14 digital I/O pins
    14 个数字 I/O 引脚

  • 6 analog inputs 6 个模拟输入

  • 16 MHz crystal oscillator
    16 MHz晶体振荡器

  • Reset button 复位按钮

  • USB connection. USB 连接。

We can connect it to a computer with a USB cable or battery to get started.
我们可以使用USB电缆或电池将其连接到计算机以开始使用。

Arduino Uno can sense the environment by receiving input from a variety of sensors and can control LEDs, Servo motors, motors, and other actuators.
Arduino Uno 可以通过接收来自各种传感器的输入来感知环境,并可以控制 LED、伺服电机、电机和其他执行器。

Step 3: 关于超声波传感器

a Little Bit About Ultrasonic Sensors

a Little Bit About Ultrasonic Sensors

a Little Bit About Ultrasonic Sensors

a Little Bit About Ultrasonic Sensors

HC-SR04 ultrasonic modules have two transducers: one acts as a speaker (S) which converts electric pulses into sound waves and emits them with a frequency of 40000 Hz (40 kHz), the other acts as a microphone (M) to receive the ultrasonic waves that have bounced off an object (O).
HC-SR04超声波模块有两个换能器:一个充当扬声器(S),将电脉冲转换为声波并以40000Hz(40kHz)的频率发射,另一个充当麦克风(M)接收从物体(O)反射的超声波。

The timer will start on the microcontroller when the pulse is transmitted and timer will stop when echo waves are received by the microphone. That is how we get the total time for the wave to travel from S --> O --> M.
当脉冲传输时,定时器将在微控制器上启动,当麦克风接收到回波时,定时器将停止。这就是我们如何获得波从 S --> O --> M 传播的总时间。

Step 4: 将超声波传感器连接到微控制器

Now Connect Ultrasonic Sensor to the Microcontroller

Now Connect Ultrasonic Sensor to the Microcontroller

HC-SR04 Ultrasonic sensor has four pins:
HC-SR04超声波传感器有四个引脚:

  • Vcc: Operating Voltage pin
    Vcc:工作电压引脚

  • Trig: Signal transmitting pin
    Trig:信号发射引脚

  • Echo: bounced off signal sensing pin
    回波:从信号感应引脚反弹

  • Gnd: Ground pin Gnd:接地引脚

Connect all these 4 pins to microcontroller board with jumper wires.
使用跳线将所有这 4 个引脚连接到微控制器板。

  1. Connect Vcc to 5V pin
  2. 将Vcc连接到5V引脚
  3. Gnd to ground pin
  4. Gnd接地引脚
  5. Trig to pin 13
  6. 三角到销 13
  7. Echo to pin 7
  8. 回声到引脚 7

You can choose any digital pins on the microcontroller for connecting Trig and Echo of the ultrasonic sensor.
您可以选择微控制器上的任何数字引脚来连接超声波传感器的 Trig 和 Echo。

Step 5:Arduino 软件程序 (Sketch)

The Arduino program basically will do the following steps:
Arduino程序基本上会执行以下步骤:

  1. Turn on Trig pin 打开 Trig 引脚
  2. Send out a 10 microsecond width pulse
    发出 10 微秒宽度的脉冲
  3. Turn off theTrig pin
    关闭Trig引脚
  4. Print the total time of travel of the pulse on the serial monitor.
    在串行监视器上打印脉冲的总行程时间。

----------------------------------------------------------------

int trigPin = 13;  // set pin 13 as trig pin
int echoPin = 7;   // set pin 7 as echo pin
int time;
void setup() {

  Serial.begin(9600);

  pinMode(trigPin, OUTPUT);  // set trig pin as output, we send pulse through this

  pinMode(echoPin, INPUT);  // set echo pin as input, we detect echo through this pin
}
void loop() {
  //sending 10 microsecond width pulses, frequency ~ 40KHz

  digitalWrite(trigPin, LOW);
  delayMicroseconds(2000);

  digitalWrite(trigPin, HIGH);    //trig pin 
  delayMicroseconds(10);  //pulse width 10 microseconds
  digitalWrite(trigPin, LOW);     //trig pin off
  time = pulseIn(echoPin, HIGH);  //pulseIn(), function return time in microseconds

  //print time on the serial monitor

  Serial.print(" Time taken for the pulse to travel:  ");
  Serial.print(time);
  Serial.println(" microseconds");
  delay(2000);
}

Step 6: 实验设置、程序和数据采集

Experimental Setup, Procedure and Data Aquisition

在这里插入图片描述
在这里插入图片描述

Before starting the experiment note down the room temperature, in our case it was 75 degrees F.
在开始实验之前,记下室温,在我们的例子中是 75 华氏度。

  1. We need to put the sensor at 0 cm on the ruler

我们需要将传感器放在尺子上的0厘米处

  1. Put your object at any desired position on the ruler, we kept it at 5cm, so the total distance (D) is 10 centimeters.

    将您的物体放在尺子上任何想要的位置,我们将其保持在 5 厘米,因此总距离 (D) 为 10 厘米。

  2. Upload the program to microcontroller with USB cable.

    使用USB线将程序上传到微控制器。

  3. open the serial monitor, and we can see the total time of travel of the pulse, write that on data sheet.

打开串行监视器,我们可以看到脉冲的总行程时间,写在数据表上。

  1. Move the object to 10 cm position on the scale, now the total distance is 20 cm, and write down the time from serial monitor.

    将物体移动到刻度上的 10 厘米位置,现在总距离为 20 厘米,然后记下串行监视器的时间。

  2. We took data (time) for 6 trails (at different positions), if you have a longer ruler then you can take data for more data points.

    我们采集了 6 条轨迹(不同位置)的数据(时间),如果您有更长的尺子,那么您可以获取更多数据点的数据。

Step 7: Data Analysis and Experimental Result. 第 7 步:数据分析和实验结果。

Data Analysis and Experimental Result.

After noting down the total time for different distances, now we can calculate the speed of sound:
记下不同距离的总时间后,现在我们可以计算声速:

Speed of sound = Distance/Time (S=D/T)
声速 = 距离/时间 (S=D/T)

For example: 例如:

Distance = 10 cm, Time = 289 microseconds = 28910-6 s
距离 = 10 厘米,时间 = 289 微秒 = 289
10^-6 秒

S = D/T = 10 cm / 28910-6 s = 0.03460207612 *104 m/s
S = D/T = 10 cm / 289
10-6 s = 0.03460207612 *104 米/秒

S = 346.02 m/s
小号 = 346.02 米/秒

After calculating the speed of sound for different distances, finally take the average (sum of all speeds divided by 6).
在计算不同距离的声速后,最后取平均值(所有速度的总和除以 6)。

The average S = 343.8 m/s at 75 F.
75 F 时的平均 S = 343.8 m/s。

Step 8: Confirmation 第 8 步:确认

Confirmation

The speed of sound in our experiment is 343.8 m/s
我们实验中的声速为 343.8 m/s

Speed of sound waves traveling in a medium will change based on the temperature (T) of the medium.
声波在介质中传播的速度会根据介质的温度 (T) 而变化。

Speed of sound in air as a function of temperature : S = 331.4 + 0.6Tc m/s
空气中的声速随温度的函数:S = 331.4 + 0.6Tc m/s

where Tc = temperature in degrees centigrade.
其中 Tc = 温度,单位为摄氏度。

Based on this formula, the accepted speed of sound at 75 F (23.88 degree Centigrade), S = 345.9 m/s
根据该公式,75 F(23.88 摄氏度)时可接受的声速,S = 345.9 m/s

percent error = [ |accepted value - experimental value| / (accepted value) ] * 100 %
误差百分比 = [ |接受值 - 实验值| / (接受值) ] * 100 %

percent error = 0.6 % (pretty close)
误差百分比 = 0.6 %(非常接近)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1886643.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

信息学奥赛初赛天天练-42-CSP-J2020基础题-变量地址、编译器、逻辑运算、逻辑与运算、逻辑或运算、冒泡排序、递归应用

PDF文档公众号回复关键字:20240702 2020 CSP-J 选择题 单项选择题(共15题,每题2分,共计30分:每题有且仅有一个正确选项) 1.在内存储器中每个存储单元都被赋予一个唯一的序号,称为( &#xff0…

JavaScript中的Array(数组)对象

目录 一、Array数组对象 1、介绍 2、创建数组对象并赋值 3、访问数组元素 二、Array对象属性 1、constructor属性 2、length属性 3、prototype属性 三、Array对象的常用方法 1、isArray() 2、concat() 3、pop() 4、shift() 5、push() 6、unshift() 7、reverse(…

VQA视觉问答系统

这是一个典型的多模态问题,融合了CV与NLP的技术,计算机需要同时学会理解图像和文字。 Joint embedding 首先,图像和问题分别由CNN和RNN进行第一次编码得到各自的特征,随后共同输入到另一个编码器中得到joint embedding,最后通过解码器输出答案。 值得注意的是,有的工作…

我与C++的爱恋:list的使用

​ ​ 🔥个人主页:guoguoqiang. 🔥专栏:我与C的爱恋 一、list介绍 1.list是可以在常数范围内在任意位置进行插入和删除的序列式容器,并且该容器可以前后双向迭代 2.list的底层是双向链表结构,双向链表中…

python: create Envircomnet in Visual Studio Code 创建虚拟机

先配置python开发环境 1.在搜索栏输入“>" 或是用快捷组合键ctrlshiftP键 就会显示”>",再输入"python:" 选择已经安装好的python的版本,选定至当前项目中,都是按回车 就可以看到创建了一个虚拟机的默认的文件夹名".venv" 2 te…

KUKA仿真教学8:设备保养屏蔽

目录 一、屏蔽步骤 一、屏蔽步骤

ghost恢复?电脑文件恢复如何操作?电脑数据恢复工具!5款!

在数字化时代,电脑数据的价值日益凸显。然而,数据丢失、误删、系统崩溃等问题时有发生,给个人和企业带来巨大损失。本文将为您详细介绍Ghost恢复方法,同时推荐五款高效的电脑数据恢复工具,助您轻松应对数据丢失的困扰。…

Node.js学习(一)

Node.js安装与入门案例: 需求:点击按钮,请求本地目录指定文件的内容,并显示在页面上 刚入门肯定想着直接写相对路径请求指定路径数据就行了,可是会发现不行。 网页运行在浏览器端,通常后续要发布&#xf…

全面了解机器学习

目录 一、基本认识 1. 介绍 2. 机器学习位置 二、机器学习的类型 1. 监督学习 2. 无监督学习 3. 强化学习 三、机器学习术语 1. 训练样本 2. 训练 3. 特征 4. 目标 5. 损失函数 四、机器学习流程 五、机器学习算法 1. 分类算法 2. 聚类算法 3. 关联分析 4. …

高通骁龙(Qualcomm Snapdragon)CDSP HVX HTP 芯片简介与开发入门

1. Hexagon DSP/HVX/HTP 硬件演进 说到高通骁龙芯片大家应该不会陌生,其作为最为广泛的移动处理器之一,几乎每一个品牌的智能手机都会使用高通骁龙的处理器。 高通提供了一系列骁龙芯片解决方案。根据性能强弱分为了5个产品系列:从最高端的…

verilog实现PID控制

1 原理讲解 距离上一次说PID算法的事情过去蛮久了,今天又重新看了看PID的代码,其实还是存在一些不合理的地方。 整理归纳了一下原理,位置式和增量式的变化。 2 工程实现 timescale 1ns / 1psmodule pid_controller(input clk,input r…

MySQL——事务ACID原则、脏读、不可重复读、幻读

什么是事务 要么都成功,要么都失败 一一一一一一一 1. SQL执行:A给B转账 A 1000 ---->200 B 200 2. SQL执行:B收到A的钱 A 800 B 400 一一一一一一一 将一组SQL放在一个批次中去执行~ 事务原则:ACI…

从零搭建Prometheus到Grafana告警推送

目录 一、Prometheus源码安装和动态更新配置 二、Prometheus操作面板和常见配置 三、Prometheus常用监控组件exporter配置 3.1 exporter是什么 3.2 有哪些exporter 3.3 exporter怎么用 3.4 实战 node_exporter ​3.5 其它exporter都怎么用 四、Promethus整合新版Sprin…

线程状态转换总结

1. NEW -> RUNNABLE 创建线程后是 NEW 状态&#xff08;只是 Java 层面新建的&#xff0c;还没有关联到操作系统实际的线程上&#xff09;&#xff0c;调用线程的 start() 方法会将 Java 线程和操作系统的线程关联起来&#xff0c;进入 RUNNABLE 状态 2. RUNNABLE <->…

入门PHP就来我这(纯干货)05

~~~~ 有胆量你就来跟着路老师卷起来&#xff01; -- 纯干货&#xff0c;技术知识分享 ~~~~ 路老师给大家分享PHP语言的知识了&#xff0c;旨在想让大家入门PHP&#xff0c;并深入了解PHP语言。 1 数组及创建 数组&#xff0c;顾名思义&#xff0c;本质上就是一系列数据的组合…

【Linux进程通信】使用匿名管道制作一个简单的进程池

进程池是什么呢&#xff1f;我们可以类比内存池的概念来理解进程池。 内存池 内存池是在真正使用内存之前&#xff0c;先申请分配一定数量的、大小相等(一般情况下)的内存块留作备用。当有新的内存需求时&#xff0c;就从内存池中分出一部分内存块&#xff0c;若内存块不够再继…

docker-compose搭建prometheus、grafana

一、安装prometheus 1、安装 version: 3.1services:prometheus:image: prom/prometheus:v2.48.0container_name: prometheushostname: prometheusrestart: alwaysvolumes:- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml- ./prometheus/:/etc/prometheus/port…

淘宝扭蛋机小程序开发,新玩法、新收益体验!

近几年&#xff0c;随着娱乐消费的火爆&#xff0c;潮玩市场得到了快速发展&#xff0c;从而带动了扭蛋机市场的发展&#xff0c;扭蛋机也逐渐风靡在消费市场中。对于年轻人消费者来说&#xff0c;愿意为扭蛋机的热门IP商品而买单。目前&#xff0c;价格低、颜值高、种类多样的…

大科技公司大量裁员背后的真相

每周跟踪AI热点新闻动向和震撼发展 想要探索生成式人工智能的前沿进展吗&#xff1f;订阅我们的简报&#xff0c;深入解析最新的技术突破、实际应用案例和未来的趋势。与全球数同行一同&#xff0c;从行业内部的深度分析和实用指南中受益。不要错过这个机会&#xff0c;成为AI领…

试用笔记之-汇通计算机等级考试软件一级Windows

首先下载汇通计算机等级考试软件一级Windows http://www.htsoft.com.cn/download/htwork.rar