const int trig = 12; const int echo = 11; const int buzer = 2; long sure; int uzaklik; void setup() { pinMode(trig, OUTPUT); pinMode(echo, INPUT); pinMode(buzer, OUTPUT); Serial.begin(9600); } void loop() { digitalWrite(buzer, 1); delay(5 * uzaklik); digitalWrite(buzer, 0); delay(5 * uzaklik); digitalWrite(trig, 0); delayMicroseconds(10); digitalWrite(trig, 1); delayMicroseconds(10); sure = pulseIn(echo, 1); uzaklik = (0.0343 * sure) / 2; if (uzaklik > 200) uzaklik = 200; Serial.print(uzaklik); Serial.println(" cm"); }
No responses yet