2 MINUTE ARDUINO LASER ALARM
by Jacks how2s in Circuits > Arduino
8884 Views, 180 Favorites, 0 Comments
2 MINUTE ARDUINO LASER ALARM
WHAT YOU NEED
Arduino
Laser
Breadboard
Jumper wires
LED
10K Resistor
Arduino
Laser
Breadboard
Jumper wires
LED
10K Resistor
CONNECTIONS
First connect you resistor to the photo resistor and then that end will go to the - row in the board then the photo resistor will go to A0 on the arduino and the other end to 5V and the LED simply goes to pin 13 on the arduino!
CODING
HERE IS THE CODE!
int flag=0;
void setup() {
pinMode(4, OUTPUT);
pinMode(13, OUTPUT);
pinMode(2, OUTPUT);
}
int checkStatus()
{
if(analogRead(0) < 25)
{
digitalWrite(13,HIGH); // Used pin 13 to debug. Not required for the final make. All references to pin 13 can be removed.
return 1;
} // Light not found(:D)
else
{
digitalWrite(13,LOW);
return 0;
} // Light reaches uninterrupted
}
void setAlarm()
{
digitalWrite(2,HIGH); // pin 2 is used to show when a breach occurs.
flag=1;
loop();
}
void loop(){
if(!flag)
{
digitalWrite(4,HIGH);
delay(5); // This is to give the resistor a little time to react. You might not need this.
if(checkStatus())
setAlarm();
delay(10); //change delay here
digitalWrite(4,LOW);
delay(5);
if(!checkStatus())
setAlarm();
delay(10); // and here to get a custom strobe
}
}
int flag=0;
void setup() {
pinMode(4, OUTPUT);
pinMode(13, OUTPUT);
pinMode(2, OUTPUT);
}
int checkStatus()
{
if(analogRead(0) < 25)
{
digitalWrite(13,HIGH); // Used pin 13 to debug. Not required for the final make. All references to pin 13 can be removed.
return 1;
} // Light not found(:D)
else
{
digitalWrite(13,LOW);
return 0;
} // Light reaches uninterrupted
}
void setAlarm()
{
digitalWrite(2,HIGH); // pin 2 is used to show when a breach occurs.
flag=1;
loop();
}
void loop(){
if(!flag)
{
digitalWrite(4,HIGH);
delay(5); // This is to give the resistor a little time to react. You might not need this.
if(checkStatus())
setAlarm();
delay(10); //change delay here
digitalWrite(4,LOW);
delay(5);
if(!checkStatus())
setAlarm();
delay(10); // and here to get a custom strobe
}
}