//WHEN LIGHT THEN BUZZ FOR SEVEN SECONDS
#define time 7000;//defining time for 7s
const int LDR_PIN= A0;//define the LDR pin
unsigned long current_time= millis(),previous_ldr_time=0;
void setup() {
// FOR LED pin number 10 is used as output
pinMode(10, OUTPUT);
pinMode(8, OUTPUT);//FOR BUZZER pin number 8 is used as output
Serial.begin(9600);//initialising serial communication
}
void loop() {
int play,stop;
int ldr_value=analogRead(A0);//initializing the ldr pin
current_time=millis();//return the number of milliseconds at the time
previous_ldr_time=current_time;
Serial.print("LDR value");
Serial.println(ldr_value);
// based on the ldr value the LED will glow and buzzer will be on
if(ldr_value>250)
{
digitalWrite(10, HIGH);
tone(8,500,500);//plays 500HZ tone for 0.5seconds when led is ON
previous_ldr_time=current_time;
Serial.println("HIGH");
}
else
{
digitalWrite(10, LOW);//TO OFF LED
tone(8,0,0);//BUZZER SHOULD BE STOPPED AND LED OFF
previous_ldr_time=current_time;
Serial.println("LOW");
}
}