#define G 22
#define Y 18
#define R 2
#define PIR 13
#define LDR 35
#define PIN_TRIG 12
#define PIN_ECHO 14
void setup() {
  Serial.begin(115200);
  pinMode(G, OUTPUT);
  pinMode(Y, OUTPUT);
  pinMode(R, OUTPUT);
  pinMode(PIR, INPUT);
  pinMode(LDR, OUTPUT);
  pinMode(PIN_TRIG, OUTPUT);
  pinMode(PIN_ECHO, INPUT);
}

void loop() {
  digitalWrite(PIN_TRIG, HIGH);
  delay(5);
  digitalWrite(PIN_TRIG, LOW);
  int duration = pulseIn(PIN_ECHO, HIGH);
  int distance = duration/58;
 if(digitalRead(PIR)==HIGH)
  {
    digitalWrite(G, HIGH);
    delay(500);
  }
  digitalWrite(PIR, LOW);
  if(analogRead(LDR)>2500)
  {
    digitalWrite(Y, HIGH);
  }
  else
  {
    digitalWrite(Y, LOW);
  }
  if(distance<300)
  {
    digitalWrite(R, HIGH);
  }
  else
  {
    digitalWrite(R, LOW);
  }
  delay(1000);
  Serial.print("LDR Senson : ");
  Serial.println(analogRead(LDR));
  Serial.print("Distance in CM: ");
  Serial.println(distance);
}