#include #include #define max_distance 200 LiquidCrystal lcd(12, 11, 5, 4, 3, 2); LcdBarGraph lbg(&lcd, 16, 0, 1); const int trigPin = 9; const int echoPin = 10; long duration; int distance; int kled = 6; int sled = 7; int yled = 8; int buzzer = 13; int mesafe,sure; void setup() { Serial.begin(9600); lcd.begin(16,2); // Initializes the interface to the LCD screen pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); pinMode(kled, OUTPUT); pinMode(yled, OUTPUT); pinMode(sled, OUTPUT); pinMode(buzzer, OUTPUT); } void loop() {digitalWrite(trigPin , HIGH); delayMicroseconds(1000); digitalWrite(trigPin , LOW); sure = pulseIn(echoPin , HIGH); mesafe = (sure/2) / 28.5; Serial.print(mesafe); if (mesafe <= 10) { digitalWrite(kled, HIGH); digitalWrite(buzzer, HIGH); delay(50); digitalWrite(kled, LOW); digitalWrite(buzzer, LOW); delay(100); } else if ( mesafe <= 25) { digitalWrite(sled, HIGH); digitalWrite(buzzer, HIGH); delay(50); digitalWrite(sled, LOW); digitalWrite(buzzer, LOW); delay(500); } else if ( mesafe <= 50) { digitalWrite(yled, HIGH); digitalWrite(buzzer, HIGH); delay(50); digitalWrite(yled, LOW); digitalWrite(buzzer, LOW); delay(1000); } else { digitalWrite(yled, HIGH); delay(1000); digitalWrite(yled, LOW); delay(1000); } long duration,distance; digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distance= duration*0.034/2; lcd.setCursor(0,0); lcd.print("Distance: "); lcd.print(distance); lcd.print(" cm"); lcd.setCursor(0,1); lbg.drawValue(distance, max_distance); delay(500); }