const int LDR = 4;
const int LED = 5;
const int BUZZER = 21;
// put function declarations here:
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(LDR, INPUT);
pinMode(LED, OUTPUT);
pinMode(BUZZER, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int LDRval = analogRead(LDR);
Serial.println(LDRval);
//delay(2);
if(LDRval<=400){
digitalWrite(LED, HIGH); // if LDR senses darkness
tone(BUZZER, 1000); // 1KHz sound signal
}
else{
digitalWrite(LED, LOW); // if LDR senses light
noTone(BUZZER);
}
}
// put function definitions here: