loading
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

}
}
<p>Simple .. i like it!</p>
<p>Instead of using led u can actually go with buzzer </p>

About This Instructable

7,693views

175favorites

License:

Bio: Go to jackshow2s.weebly.com for more! Also Check Out Me On YouTube!
More by Jacks how2s:555 Timer Blink Circuit! 555 Timer Monstable Circuit! How to Make a Remote Fire Starter! 
Add instructable to: