Buzzer Alarm Using LDR and Arduino
by abhirooprobotics in Circuits > Arduino
27321 Views, 19 Favorites, 0 Comments
Buzzer Alarm Using LDR and Arduino
Hello Guyz
I Wanted To Build A LDR Buzzer And Got Many Instructables Which Were Using Transistors To Do This Project.
So I Bulid This Project With The Help Of Arduino Which Many People Have.
Just Follow The Steps And You'll Get Your LDR Buzzer Ready Within 5 Minutes!
REQUIREMENTS
So,For Making This Project You Need A Couple Of Things Which Are Described Below:-
1. 1 X Arduino (UNO/MEGA/NANO)
2. 1 X Piezzo Buzzer
3. 1 X 470k Resistor
4. 1 X Breadboard
5. 1 X LDR
6. Some Wires
Wiring
Just Follow The Fritzing Diagram And Do The Wiring As Described In The Image!
You Will Get Your LDR Buzzer Circuit Ready In A Couple Of Minutes!
CODE
Here's The Code Which You Have To Upload To Your Arduino :-
int rcvpin=A0;
int buzzpin=9;
void setup()
{
pinMode(rcvpin,INPUT);
pinMode(buzzpin,OUTPUT);
buzz(200);
buzz(200);
buzz(200);
delay(2000);
Serial.begin(9600);
}
void loop()
{
int ldrval=analogRead(rcvpin);
Serial.println(ldrval);
if(ldrval>=900)
{
buzz(50);
}
}
void buzz(unsigned char time)
{
analogWrite(buzzpin,170);
delay(time);
analogWrite(buzzpin,0);
delay(time);
}
FINISHED!
Upload The Code And BOOM! There You Go!
You Just Made Your LDR Buzzer Without Any Hassles!
Congrats!