2 MINUTE ARDUINO LASER ALARM

8,173

178

2

About: Your one stop place for electronics tutorials, components and services!

Intro: 2 MINUTE ARDUINO LASER ALARM

WHAT YOU NEED

Arduino
Laser
Breadboard
Jumper wires
LED
10K Resistor

Step 1: 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!

Step 2: 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

}
}

Share

    Recommendations

    • Fix It! Contest

      Fix It! Contest
    • Furniture Contest 2018

      Furniture Contest 2018
    • Audio Contest 2018

      Audio Contest 2018

    2 Discussions

    0
    None
    Ahmedqatar

    2 years ago

    Simple .. i like it!

    0
    None
    Niranjan_Niru

    2 years ago

    Instead of using led u can actually go with buzzer