Verkabelung
|
Sensor |
Arduino |
Funktion |
VCC |
5V |
positive Versorgungsspannung |
Trig |
8 |
10uS TTL pulse |
Echo |
9 |
Input TTL lever signal and the range in proportion |
GND |
GND |
Masse (0 Volt Potential) |
|
Code
|
double time, m; const int vSound = 343; // [v] = 1 m/s
void setup() { Serial.begin(9600);
pinMode(8,OUTPUT); pinMode(9,INPUT); }
void loop() { digitalWrite(9,LOW); delayMicroseconds(2); digitalWrite(8,HIGH); delayMicroseconds(5); digitalWrite(8,LOW); time = pulseIn(9,HIGH); // [t] = 1 µs
m = time / 2 / 1000000 * vSound; // [s] = 1 m Serial.print(m,3); Serial.println(" m"); delay(1000); }
|
|