Malzemeler:
- Arduino Uno
- Ultrasonik Mesafe Sensörü
- 4 adet LED
- Buzzer
int trigger = 13; int echo = 12; int led1 = 8; int led2 = 9; int led3 = 10; int led4 = 11; int buzzer = 7; int sure ; int mesafe ; void setup() { pinMode(led1 , OUTPUT); pinMode(led2 , OUTPUT); pinMode(led3 , OUTPUT); pinMode(led4 , OUTPUT); pinMode(buzzer , OUTPUT); pinMode(trigger , OUTPUT); pinMode(echo , INPUT); } void loop() { digitalWrite(trigger , HIGH); delayMicroseconds(1000); digitalWrite(trigger , LOW); sure = pulseIn(echo , HIGH); mesafe = (sure / 2) / 29.1; if (mesafe <= 10) { digitalWrite(led1 , HIGH); digitalWrite(led2 , HIGH); digitalWrite(led3 , HIGH); digitalWrite(led4 , HIGH); digitalWrite(buzzer , HIGH); delay(200); digitalWrite(buzzer , LOW); } else if (mesafe <= 30) { digitalWrite(led1 , HIGH); digitalWrite(led2 , HIGH); digitalWrite(led3 , HIGH); digitalWrite(led4 , LOW); digitalWrite(buzzer , HIGH); delay(300); digitalWrite(buzzer , LOW); } else if (mesafe <= 50) { digitalWrite(led1 , HIGH); digitalWrite(led2 , HIGH); digitalWrite(led3 , LOW); digitalWrite(led4 , LOW); digitalWrite(buzzer , HIGH); delay(400); digitalWrite(buzzer , LOW); } else if (mesafe <= 80) { digitalWrite(led1 , HIGH); digitalWrite(led2 , LOW); digitalWrite(led3 , LOW); digitalWrite(led4 , LOW); digitalWrite(buzzer , HIGH); delay(500); digitalWrite(buzzer , LOW); } else { digitalWrite(led1 , LOW); digitalWrite(led2 , LOW); digitalWrite(led3 , LOW); digitalWrite(led4 , LOW); digitalWrite(buzzer , LOW); } }