close
Vcc→5V
Trig→12
Echo→13
Gnd→GND
#define Trig 12
#define Echo 13
void setup() {
pinMode(Trig,OUTPUT);
pinMode(Echo,INPUT);
Serial.begin(9600);
}
void loop() {
float cm;
digitalWrite(Trig, HIGH);
delayMicroseconds(10);
digitalWrite(Trig, LOW);
cm=pulseIn(Echo, HIGH)*0.0172413;
Serial.println(cm);
delay(1000);
}
全站熱搜