Arduino Laser Tripwire

236,277

303

88

Introduction: Arduino Laser Tripwire

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:

-Arduino
-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);
Serial.begin(9600);
}

void loop(){
digitalWrite(4, HIGH);
Serial.println(analogRead(0));
}

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...

Share

    Recommendations

    • Metalworking Contest

      Metalworking Contest
    • Fix It! Contest

      Fix It! Contest
    • Tiny Home Contest

      Tiny Home Contest

    88 Discussions

    Thanks for the ideas. Currently working on alarm system for predators around my chicken coop, gonna order the photo resistors and give it a go. Until it arrives, fishing line :P

    I'm thinking of using lasers instead of regular light LEDs for an outdoor hot wheels track timer project.

    I want the lasers to point DOWN, and I don't have room for 2" of tube around the sensor under the finish line. Should I scrap the laser idea and just try to use some existing light/sensor projects out there?

    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?

    5 replies

    dude did you ever figure this out i am looking for almost the exact same thing. Please get back to me on this.

    It should work as is, gust use different inputs in your ardino and add the if()... code for each photo resistor.

    Bad idea...
    Just use if digitalRead(1, HIGH) || digitalRead(2, HIGH) etc.
    (|| means or).
    You can thank me later.

    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 "if" blocks for each light sensor, and then play the appropriate sound within each block.

    dude did you ever figure this out i am looking for almost the exact same thing. Please get back to me on this.

    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 "create" an analogRead between 0-1023...
    I hope this helped someone and good luck with the project.

    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?

    there is!the code you'll have to add depends on what method you want to use to display that count though.


    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. 

    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
       
      }
    }


    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.

    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).