我正在做一个由两个超声波、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
}