Programming Examples

Arduino program to interface buzzer with LDR and LED


LDR Session in Arduino

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/ Explanation:

LDR : Light Dependent Resistor 


Latest Current Affairs 2024 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad