int ledred1 = 13;
int ledred2 = 12;
int ledred3 = 11;
int ledyellow1 = 10;
int ledyellow2 = 9;
int ledyellow3 = 8;
int ledgreen1 = 7;
int ledgreen2 = 6;
int ledgreen3 = 5;
int buzzer = 4;
int ldr = A0;
void setup() {
// put your setup code here, to run once:
pinMode (ledred1, OUTPUT);
pinMode (ledred2, OUTPUT);
pinMode (ledred3, OUTPUT);
pinMode (ledyellow1, OUTPUT);
pinMode (ledyellow2, OUTPUT);
pinMode (ledyellow3, OUTPUT);
pinMode (ledgreen1, OUTPUT);
pinMode (ledgreen2, OUTPUT);
pinMode (ledgreen3, OUTPUT);
pinMode (buzzer, OUTPUT);
pinMode (ldr, INPUT);
Serial.begin (9600);
}
void loop() {
// put your main code here, to run repeatedly:
int ldrstatus = analogRead(ldr);
if (ldrstatus>=500) {
digitalWrite (ledred1, HIGH);
digitalWrite (ledred2, HIGH);
digitalWrite (ledred3, HIGH);
digitalWrite (ledyellow1, HIGH);
digitalWrite (ledyellow2, HIGH);
digitalWrite (ledyellow3, HIGH);
digitalWrite (ledgreen1, HIGH);
digitalWrite (ledgreen2, HIGH);
digitalWrite (ledgreen3, HIGH);
tone (buzzer, 1500);
Serial.println(ldrstatus);
}
else if (ldrstatus<500 && ldrstatus>=450) {
digitalWrite (ledred1, LOW);
digitalWrite (ledred2, HIGH);
digitalWrite (ledred3, HIGH);
digitalWrite (ledyellow1, HIGH);
digitalWrite (ledyellow2, HIGH);
digitalWrite (ledyellow3, HIGH);
digitalWrite (ledgreen1, HIGH);
digitalWrite (ledgreen2, HIGH);
digitalWrite (ledgreen3, HIGH);
tone (buzzer, 1350);
Serial.println(ldrstatus);
}
else if (ldrstatus<450 && ldrstatus>=400) {
digitalWrite (ledred1, LOW);
digitalWrite (ledred2, LOW);
digitalWrite (ledred3, HIGH);
digitalWrite (ledyellow1, HIGH);
digitalWrite (ledyellow2, HIGH);
digitalWrite (ledyellow3, HIGH);
digitalWrite (ledgreen1, HIGH);
digitalWrite (ledgreen2, HIGH);
digitalWrite (ledgreen3, HIGH);
tone (buzzer, 1200);
Serial.println(ldrstatus);
}
else if (ldrstatus<400 && ldrstatus>=350) {
digitalWrite (ledred1, LOW);
digitalWrite (ledred2, LOW);
digitalWrite (ledred3, LOW);
digitalWrite (ledyellow1, HIGH);
digitalWrite (ledyellow2, HIGH);
digitalWrite (ledyellow3, HIGH);
digitalWrite (ledgreen1, HIGH);
digitalWrite (ledgreen2, HIGH);
digitalWrite (ledgreen3, HIGH);
tone (buzzer, 1050);
Serial.println(ldrstatus);
}
else if (ldrstatus<350 && ldrstatus>=300) {
digitalWrite (ledred1, LOW);
digitalWrite (ledred2, LOW);
digitalWrite (ledred3, LOW);
digitalWrite (ledyellow1, LOW);
digitalWrite (ledyellow2, HIGH);
digitalWrite (ledyellow3, HIGH);
digitalWrite (ledgreen1, HIGH);
digitalWrite (ledgreen2, HIGH);
digitalWrite (ledgreen3, HIGH);
tone (buzzer, 900);
Serial.println(ldrstatus);
}
else if (ldrstatus<300 && ldrstatus>=250) {
digitalWrite (ledred1, LOW);
digitalWrite (ledred2, LOW);
digitalWrite (ledred3, LOW);
digitalWrite (ledyellow1, LOW);
digitalWrite (ledyellow2, LOW);
digitalWrite (ledyellow3, HIGH);
digitalWrite (ledgreen1, HIGH);
digitalWrite (ledgreen2, HIGH);
digitalWrite (ledgreen3, HIGH);
tone (buzzer, 750);
Serial.println(ldrstatus);
}
else if (ldrstatus<250 && ldrstatus>=200) {
digitalWrite (ledred1, LOW);
digitalWrite (ledred2, LOW);
digitalWrite (ledred3, LOW);
digitalWrite (ledyellow1, LOW);
digitalWrite (ledyellow2, LOW);
digitalWrite (ledyellow3, LOW);
digitalWrite (ledgreen1, HIGH);
digitalWrite (ledgreen2, HIGH);
digitalWrite (ledgreen3, HIGH);
tone (buzzer, 600);
Serial.println(ldrstatus);
}
else if (ldrstatus<200 && ldrstatus>=150) {
digitalWrite (ledred1, LOW);
digitalWrite (ledred2, LOW);
digitalWrite (ledred3, LOW);
digitalWrite (ledyellow1, LOW);
digitalWrite (ledyellow2, LOW);
digitalWrite (ledyellow3, LOW);
digitalWrite (ledgreen1, LOW);
digitalWrite (ledgreen2, HIGH);
digitalWrite (ledgreen3, HIGH);
tone (buzzer, 450);
Serial.println(ldrstatus);
}
else if (ldrstatus<150 && ldrstatus>=100) {
digitalWrite (ledred1, LOW);
digitalWrite (ledred2, LOW);
digitalWrite (ledred3, LOW);
digitalWrite (ledyellow1, LOW);
digitalWrite (ledyellow2, LOW);
digitalWrite (ledyellow3, LOW);
digitalWrite (ledgreen1, LOW);
digitalWrite (ledgreen2, LOW);
digitalWrite (ledgreen3, HIGH);
tone (buzzer, 300);
Serial.println(ldrstatus);
}
else {
digitalWrite (ledred1, LOW);
digitalWrite (ledred2, LOW);
digitalWrite (ledred3, LOW);
digitalWrite (ledyellow1, LOW);
digitalWrite (ledyellow2, LOW);
digitalWrite (ledyellow3, LOW);
digitalWrite (ledgreen1, LOW);
digitalWrite (ledgreen2, LOW);
digitalWrite (ledgreen3, LOW);
noTone (buzzer);
Serial.print ("hi sir pogi:");
Serial.println(ldrstatus);
}
}