Programming Examples
Arduino program to interface buzzer with LDR and LED
Write Arduino program to interface buzzer with LDR and LED
Solution
void setup()
{
Serial.begin(9600);
pinMode(13,OUTPUT);
pinMode(8,OUTPUT);
pinMode(A0,INPUT);
}
void loop()
{
int signal;
signal=analogRead(A0);
Serial.println(signal);
if(signal>=400)
{
tone(8,1000);
digitalWrite(13,HIGH);
delay(100);
noTone(8);
digitalWrite(13,LOW);
delay(100);
Serial.println("ALARM ACTIVATED");
}
else
{
noTone(8);
digitalWrite(13,LOW);
Serial.println("ALARM DEACTIVATED");
}
}
Output
LDR : Light Dependent Resistor