The Arduino is great, you can make it do pretty much anything you want.

I wanted a tripwire. This is just the circuit and the code, you can use it for quite a few things, like a trigger for a camera, or you could make it shut down your computer if someone crosses it.

When I have the time, I want to hook it up to an electric airsoft gun with a relay and have it shoot you when you break the beam. I suppose I'll add to the Instructable when that happens.

So let's start!

Step 1: Components Needed

This is what you need for this project:

-10k Resistor
-Photo resistor (Practically any value will work, the program will just need to be changed slightly)
-Laser Pointer
-Jumper Cables
-Alligator clips

Step 2: Circuit

Below is a picture of the circuit.

Connect one leg of the photoresistor to Analog Input 0, and the other leg to +5v. Then, take the 10K resistor and connect one leg to GND (ground) and the other to Analog Input 0.

Also, I wired an LED to Digital I/O pin 13 to show when the laser beam is broken.

Step 3: The laser pointer

To control the laser pointer, I did this:

1) Remove the end cap and take out the batteries.
2) Inside there should be a spring, connect one of the alligator clips to this spring.
3) My laser pointer (and all of the others I have seen) have a completed circuit when the end cap is on, so I connected the other alligator clip to the bit of metal on the inside of the laser pointer.
4) Connect one of the alligator clips to GND, and the other to pin 4 (or any pin, so that you can control the laser).
5) Lastly, use masking tape to tape down the button so the laser pointer is always on.

Step 4: The Program

Here is the program I used.
Pin 4 is the laser pointer, pin 13 is the LED, and the Analog Pin 0 is the photoresistor.

void setup() {
pinMode(4, OUTPUT);
pinMode(13, OUTPUT);

void loop(){
digitalWrite(4, HIGH);
if(analogRead(0) < 750){
digitalWrite(13, HIGH);
} else{
digitalWrite(13, LOW);

This program is highly specialized to the room I'm sitting in right now, you will have to calibrate it to work in the lighting conditions you have. To do this, you must read the value of the photoresistor when the laser is hitting it. Then, measure it when the laser is not hitting it.
To do that, you can use this program, and then monitor the Serial Output.

void setup() {
pinMode(4, OUTPUT);

void loop(){
digitalWrite(4, HIGH);

When the laser beam hit the photoresistor I had a value of around 850. When I stopped the beam with my finger, I had a value of about 700. So, I made the LED turn on when the value drops below 750 in my program, indicating the beam has been broken.

Step 5: Test! (and troubleshoot)

Run the program and see how it goes!
First off, you have to make sure that the laser pointer is on. If it is not, check the following:
-That the on button really is on.
-That you didn't connect the alligator clips the opposite way they should be. To fix this, change one from GND to Pin 4, and the other from Pin 4 to GND.

I hope this was mildly interesting!
I have a video of it in action below. Excuse the LED bargraph, I use it to display how many emails I have waiting for me and I didn't want to remove it...
I looking to do something like this for a project with 6 different lasers to trigger 6 different sounds from a wave or MP3 shield. Is it just the software I need to tweak or totally redo the hardware?
<p>dude did you ever figure this out i am looking for almost the exact same thing. Please get back to me on this.</p>
<p>It should work as is, gust use different inputs in your ardino and add the if()... code for each photo resistor.</p>
Bad idea...<br>Just use if digitalRead(1, HIGH) || digitalRead(2, HIGH) etc.<br>(|| means or).<br>You can thank me later.
<p>Nope... @cclick1 said he wanted to play a different sound with each laser. Doing what you suggested will force him to make them all play the same sound. The right way would to be use multiple &quot;if&quot; blocks for each light sensor, and then play the appropriate sound within each block.</p>
<p>dude did you ever figure this out i am looking for almost the exact same thing. Please get back to me on this.</p>
I had an idea that could help people who want to build this: why don't you make the value below which the alarm should be triggered a variable that can be changed with a potentiometer? After all both components are resistors, which means they &quot;create&quot; an analogRead between 0-1023...<br>I hope this helped someone and good luck with the project.<br>
<p>hi. I was wondering if I could use the Keyes laser beam and the laser detector to activate a servo motor? I've already got code for activating a motion sensor but I would like to use a tripwire beam to activate a servo. Can this be done and is there any Arduino code for it?</p>
<p>can it be done on arduino uno?pls i need urgent answers</p>
<p>this is an arduino uno.</p>
<p>is there a way to set this so it counts every time the lazer is passed through?</p>
<p>there is!the code you'll have to add depends on what method you want to use to display that count though.</p>
<br>Hello, nice project. I just want to ask, if how can I integrate this one with a camera (webcam). When the laser is tripped.. It will take a photo and upload it directly. Need help.
Hello. This worked great. I used it as a base and made the laser do a very basic strobe. I reduced the delay and at this point the strobe-effect isn't even visible.&nbsp;<br> <br> int flag=0;<br> <br> void setup() {<br> pinMode(4, OUTPUT);<br> pinMode(13, OUTPUT);<br> pinMode(2, OUTPUT);<br> <br> <br> }<br> <br> <br> int checkStatus()<br> {<br> &nbsp;<br> &nbsp;&nbsp; if(analogRead(0) &lt; 25)<br> &nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; digitalWrite(13,HIGH);&nbsp;&nbsp;&nbsp; // Used pin 13 to debug. Not required for the final make. All references to pin 13 can be removed.<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br> &nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Light not found(:D)<br> &nbsp;&nbsp; else<br> &nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; digitalWrite(13,LOW);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br> &nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Light reaches uninterrupted<br> }<br> &nbsp;&nbsp;<br> &nbsp;&nbsp;<br> void setAlarm()<br> {<br> &nbsp;&nbsp;&nbsp; digitalWrite(2,HIGH);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // pin 2 is used to show when a breach occurs.<br> &nbsp;&nbsp;&nbsp; flag=1;<br> &nbsp;&nbsp;&nbsp; loop();<br> &nbsp;&nbsp;&nbsp;<br> }<br> <br> void loop(){<br> &nbsp;<br> &nbsp; if(!flag)<br> &nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp; digitalWrite(4,HIGH);<br> &nbsp;&nbsp;&nbsp;&nbsp; delay(5);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // This is to give the resistor a little time to react. You might not need this.<br> &nbsp;&nbsp;&nbsp;&nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp; if(checkStatus())<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setAlarm();<br> &nbsp;&nbsp;&nbsp;&nbsp; delay(10);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //change delay here<br> &nbsp;&nbsp;&nbsp;&nbsp; digitalWrite(4,LOW);<br> &nbsp;&nbsp;&nbsp;&nbsp; delay(5);<br> &nbsp;&nbsp;&nbsp;&nbsp; if(!checkStatus())<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setAlarm();<br> &nbsp;&nbsp;&nbsp;&nbsp; delay(10);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // and here to get a custom strobe<br> &nbsp;&nbsp;&nbsp;<br> &nbsp; }<br> }<br> <br> <br> Thank You @Login258!
I think this is not good enough for security proposes unless the laser is modulated and the receiver knows the modulation frequency.
<strong>thanks worked great!</strong><br> <br>
helo. i would like to request the circuit schematics. email me at luqmansemidin@gmail.com . thanks in advance :)
Would this work with a variable light resistor instead of the photo resistor. (They might even be he same thing, I'm new to this type of thing).
&nbsp;hey there thanx for this awesome tut but when i try to run the sketch in arduino its says &quot;error: redefinition of 'void setup()'<br /> <br /> and wont run<br /> <br /> please help ?<br /> <br /> thanx<br />
<p>If you just copy and paste the code has there, it won't work.<br /> <br /> void setup() {<br /> pinMode(4, OUTPUT);<br /> pinMode(13, OUTPUT);<br /> }<br /> <br /> void loop(){<br /> digitalWrite(4, HIGH);<br /> if(analogRead(0) &lt; 750){<br /> digitalWrite(13, HIGH);<br /> } else{<br /> digitalWrite(13, LOW);<br /> }<br /> }<br /> <br /> void setup() {<br /> pinMode(4, OUTPUT);<br /> Serial.begin(9600);<br /> }<br /> <br /> void loop(){<br /> digitalWrite(4, HIGH);<br /> Serial.println(analogRead(0));<br /> }<br /> <br /> Those two seperate sections of code need to be combined, as thse are both programs in their own right. From memory it should be something similar to this:<br /> <br /> void setup() {<br /> pinMode(4, OUTPUT);<br /> pinMode(13, OUTPUT);<br /> Serial.begin(9600);<br /> }</p> <p>void loop(){<br /> digitalWrite(4, HIGH);<br /> if(analogRead(0) &lt; 750){<br /> digitalWrite(13, HIGH);<br /> } else{<br /> digitalWrite(13, LOW);<br /> Serial.println(analogRead(0));<br /> }<br /> }<br /> <br /> Please not though that each of those segments of code were designed for a seperate task; one to simply trigger an LED when the beam is broken, the other to send data from the LDR to the computer so that Processing may be used. The combined code does both of these tasks, although you pobably don't need the serial transfer section if you had an error like that that you couldn't fix. Most of the people who will want to try this will be content with the first segment of code; that is, just turn on an LED or similar device when the beam is broken. The second piece of code is for more advanced users who wish to create a monitoring program in Processing (probably not you).<br /> <br /> Hope this helped.<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -Archive</p>
Hi, this sounds great and perhaps just what I'm looking for. I'm doing a project at university using Arduino and Processing and want to use a camera triggered by motion to produce an effect like the one shown below (by Magritte).<br>What I want to achieve is to have a computer screen using the mirror function in Processing and camera that is triggered by a person entering the space. Ideally the camera should track the person so that they can never see their own face in the mirror but that might be a bit ambitious for my skils / knowledge level at present.<br><br>Thanks in anticipation,<br><br>Frank
hey you should check out the website http://projectsentrygun.rudolphlabs.com/ <br>from the motion and tracking thing. I bet you could modify his code for what your wanting to do.
Hi! This is a <strong>wicked LASER project</strong>. Actually you can make something very useful this circuit. You can make a LASER counter and use it for counting people or objects on a conveyor! And you don't even require an Arduino for it. There is a step by step guide on how to make a <strong>LASER trip wire counter </strong>in this site:<br> <br> <strong><a href="http://gallactronics.blogspot.in/2011/11/laser-people-counter.html" rel="nofollow">http://gallactronics.blogspot.in/2011/11/laser-people-counter.html</a></strong><br> <br> Thanks
Can someone add in the ability for it to tweet when the alarm gets tripped? That would make it sick!<br>
it can be modified to be kind of self calibrating. Just a software thing xD. Turn on the laser, read the value, turn off the laser and read the value again, choose a threshold somewhere in between the two values, turn the laser back on and start the main loop
Another common technique is to do this continuously - deliberately strobe the laser (possibly so fast that PoV makes it look continuous) and alarm when you can no longer &quot;see&quot; your strobing. Then day/night variations, lights on/off, and even people waving torches around won't affect it.
I love the idea, I'm breaking out the old laser pointer now! :)
More importantly, people waving a<em> laser</em> around won't affect it. You can't simply hold a laser pointer on the LDR as you walk through the beam.<br> <br> You're onto a very smart idea to make it frequency dependent. Then there would be a good reason to use the Arduino. (The project as it is can be done with a transistor, trimpot, couple of resistors, LDR and LED)
Interesting idea. 10x :D
What kind of Arduino should I get for this?
Where is the video?
I think this is a great idea, and I have just the right application for it. Problem is, I am having trouble finding a photo resistor like the one in your video. I have some photo resistors I got from Adafruit, but they are tiny, and I am afraid I will have difficulty with allignment. Could you recommend where I could get a larger one, like you have?
I personally think that an Arduino is overkill, one proably could do that with an LDR. Even the idea with a oscilator should be possible to implement without an arduino.<br>I do think that's a great instructable though. <br>
I disagree... The Arduino allows you to do hundreds of different things JUST with this concept.
Hey, where could I get the Arduino thing? Could i find one on eBay?
I built a football trainer years ago that used IR emitters modulated at something like 35KHZ aimed at tuned receivers from Sharp at the same freq. There were 8, multiplexed in an array. Both emitters and receivers were placed in 2&quot; tubes and placed 6' apart from each other, forming a 6' X 6' opening. The brain was a Motorola HC705J1A MCU that fed a main MCU HC705C8 over one I/O line. It worked very well in bright sun light. The fun part was the power usage was very low as only one IR led was ever ON at any given moment. I ran some tests and was able to get a distance of 20' separation outdoors using nothng more than run-of-the-mill IR LEDs. The trick was using those tubes.
If possible add a weak lens as a beam expander, so the laser spot just covers the active area of the photo resistor. That will give much greater sesistivity, and will propbably ease even remove the need for calibration altogether.<br><br>Brian Whatcott
would an arduino NANO 3.0 work?
it looks like your using the uno.I guess ill use the uno to.
This was published in 2008.. the UNO was released 2 years after.. .It doesn't matter which board you use.
Does it matter wich arduino you use?<br>
He He... If someone could rig this so it shot the person with something (nerf gun? Paintball?) when set off, they would be a legend...
Great idea! As an improvement, could you add a second photoresistor that just takes a reading of the ambient light in the room, and use that reading instead of having to calibrate the arduino?
Simple solution may not require additional electronics-<br>Place the sensor at the back end of a black tube to block ambient light.
Oh geez that's genius! I didn't even think of that. Earlier I used a relay to shoot an electric airsoft gun with the Arduino, perhaps I"ll make a tripwire somewhere that shoots you when you cross it?
how could you do that? like:<br/><br/>if(analogRead(0) = analogRead(1)) {<br/>digitalWrite(13, LOW);<br/><br/>it doesnt work though! :S but the principle is close right? lol<br/>
Well first of all, if you're comparing two values you would use '==' not just '='.<br/><br/>And I would turn on the light if they are within a certain percentage of each other, so it would be:<br/><br/>if(analogRead(0) - (.25 * analogRead(1)) &lt; 0) {<br/>digitalWrite(13, LOW);<br/>}<br/><br/>Or at least something like that<br/>
I just completed a modified version of this. I modified the original code to check the value of the photoresitor with the laser on and then off, it averages the values, and then checks if the value of the photoresistor with the laser on is less than that value. If the beam is broken, the arduino triggers the button on a wireless doorbell using an optoisolator, which in turn chimes the door bell.<br />
You think that that would work with a 2N3904? I've been wanting to do that for a while now but have worried about takin apart my airsoft gun, because I have taken apart the electric ones before and have had problems putting them back together with all the uncooporitive springs...
Yeah I don't see why it wouldn't. I'm sticking with a relay though (mainly because I don't have a 2N3904) Maybe you could just pull the trigger with a servo then

About This Instructable




More by Login258:Arduino Laser Tripwire 
Add instructable to: