gpt4 book ai didi

c - 使用带有arduino的两个超声波流量计

转载 作者:行者123 更新时间:2023-12-04 18:00:42 25 4
gpt4 key购买 nike

我正在做一个由两个超声波、LCD 和 Arduino 组成的项目。

超声波也用于流量测量。其背后的概念是通过第一个超声波向第二个发送波,计算时间1。接下来,从第二个发送波,第一个接收波并计算时间2。

如果没有流量,time1 必须等于 time2。
但我不确定我的 arduino 代码是否正确,因为它没有向我展示真实的结果。

这是概念
http://www.universalmetering.co.uk/images/mobile/ultrasonic-diagram.gif

你能检查一下吗,如果你有代码给它..

谢谢..

LiquidCrystal LCD(11,10,9,2,3,4,5); 
//Create Liquid Crystal Object called LCD
#define trigPin1 12 #define echoPin1 13
#define trigPin2 8
#define echoPin2 7
//Simple program just for testing the HC-SR04 Ultrasonic Sensor with LCD dispaly //URL:

void setup()
{
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);
LCD.begin(16,2);
//Tell Arduino to start your 16 column 2 row LCD
LCD.setCursor(0,0); //Set LCD cursor to upper left corner, column 0, row 0
LCD.print("Difference in time:"); //Print Message on First Row

}


void loop()
{
long duration1, duration2, diff;
digitalWrite(trigPin1, LOW);
delayMicroseconds(2);
digitalWrite(trigPin1, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin1, LOW);
duration1 = pulseIn(echoPin2, HIGH);

digitalWrite(trigPin2, LOW);
delayMicroseconds(2);
digitalWrite(trigPin2, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin2, LOW);
duration2 = pulseIn(echoPin1, HIGH);
diff = (duration2) - (duration1);
LCD.setCursor(0,1); //Set cursor to first column of second row
LCD.print(" "); //Print blanks to clear the row
LCD.setCursor(0,1); //Set Cursor again to first column of second row
LCD.print(diff); //Print measured distance
LCD.print(" sec"); //Print your units.
delay(250); //pause to let things settle

}

最佳答案

SR-04 在触发时提供回声响应。这发生在同一个模 block 中。 IE。用 trigPin1 触发一个模 block 并使用 echoPin2 阅读其他模 block 带来几乎随机且不相关的结果。

阅读 echoPin1触发后 trigPin1 .

SR-04 可以记录从 20 厘米或更远距离返回空气中的声音。大约需要最短的时间。 0.6 毫秒(588 纳秒)。对于 SR-04 来说,低于这个值就是“无”。

声音在水中的传播速度大约是在空气中的 5 倍。此外,SR-04 中的接收器和发射器之间的距离非常小。管宽也很窄,不是为 SR-04 设计的。

因此,即使将发射器和接收器放置在 10 厘米之外,使用 1 英寸宽的管道,在水中的预期返回时间约为 0.1 毫秒(100 纳秒)。这是 SR-04 注册功能的背后。

但是,您可能希望使用 TDC-GP22 构建自己的 TOF 计。模 block 加上分离的超声波接收器和发射器加上适当的电源管理。
这是一个非常复杂(而且不像 SR-04 那样便宜)的项目,它受益于非侵入性液体流量测量。

关于c - 使用带有arduino的两个超声波流量计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35823423/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com