|
概念 聲音:頻率 20 HZ~2000 HZ
物體表面積 >=0.5m2
pulsein(elco,HIGH);
float dist;
int TRIG=2;//接2腳
int echo=3;//接3腳
void setup() {
pinMode(TRIG,OUTPUT);
pinMode(echo,INPUT);
Serial.begin(9600);// put your setup code here, to run once:
}
void loop() {
digitalWrite(TRIG,LOW);
delayMicroseconds(4);// 發(fā) 送 一 個(gè) 4us 的
digitalWrite(TRIG,HIGH);// put your main code here, to run repeatedly:
delayMicroseconds(10);
digitalWrite(TRIG,LOW);
dist=Pulsein(echo,HIGH)/58;
Serial.println(dist);
delay(1000);
}
|
|