//write an ardino uno code to read data from ultrasonic sensor and if the distance is less than 5cm  glow an led. also display the distance in lcd screen//
#include <LiquidCrystal.h>

const int trigPin = 2; 
const int echoPin = 3; 
const int ledPin = 13; 
const int rs = 12, en = 11, d4 = 10, d5 = 9, d6 = 8, d7 = 7; 

LiquidCrystal lcd(rs, en, d4, d5, d6, d7); 

void setup() {
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(ledPin, OUTPUT);
  
  lcd.begin(16, 2); 
  lcd.print("Distance: "); 
}

void loop() {
  long duration, distance_cm;
  
  digitalWrite(trigPin, LOW); 
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW); 
  
  duration = pulseIn(echoPin, HIGH); 
  distance_cm = duration / 58; 
  
  lcd.setCursor(0, 1);

  lcd.print(distance_cm); 

  
  if (distance_cm > 100) {
    digitalWrite(ledPin, HIGH); 

  } else {
    digitalWrite(ledPin, LOW); 

  }
  
  delay(500); 

}