int ledred = 10;
int ledyellow = 9;
int ledgreen = 8;
int buzzer = 11;
int ldr = A0;
void setup() {
// put your setup code here, to run once:
pinMode (ledred, OUTPUT);
pinMode (ledyellow, OUTPUT);
pinMode (ledgreen, 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>250) {
digitalWrite (ledred, HIGH);
digitalWrite (ledgreen, LOW);
digitalWrite (ledyellow, LOW);
tone (buzzer, 1000);
Serial.print("Too bright: ");
Serial.println(ldrstatus);
}
else if (ldrstatus<=250 && ldrstatus>100)
{
digitalWrite (ledred, LOW);
digitalWrite (ledgreen, HIGH);
digitalWrite (ledyellow, LOW);
noTone (buzzer);
Serial.print ("Ideal: ");
Serial.println (ldrstatus);
}
else
{
digitalWrite (ledred, LOW);
digitalWrite (ledgreen, LOW);
digitalWrite (ledyellow, HIGH);
noTone (buzzer);
Serial.print ("Too dim: ");
Serial.println (ldrstatus);
}
}