Project tutorial
Arduino Laser Tripwire

Arduino Laser Tripwire © GPL3+

An Arduino Uno project that utilizes a laser to detect when the laser beam has been interrupted.

  • 17,952 views
  • 12 comments
  • 52 respects

Components and supplies

Apps and online services

About this project

Building a Laser Tripwire

Components

We will need the following:

  • Some Jumper Wires
  • 3 x 10k resistors
  • 2 x Photo resistors
  • A button
  • A Buzzer
  • A Laser
  • An Arduino
  • A Breadboard
  • and a mirror

I've also used a separate breadboard for the laser detection circuit. (This helped heaps to position the laser on the photo resistor.)

Make the Laser Detector

I'm going to start with the Laser detection section of the circuit.

Grab two jumper wires at first. I have Red one and a Yellow one. Place the two jumper wires into 2 separate terminal strips. Grab a Photo resistor and connect it to the Red lead and a terminal strip. Put the other photo resistor between a different terminal strip and the red lead. Connect a 10k resistor from the yellow lead to one of the photo resistors and the other 10K resistor between the other photo resistor and the yellow lead. Grab two more leads and connect them to each intersection of the photo resistors and 10k resistors. I used Green and Orange jumper wires.

Connect the Yellow lead to the negative of the bread board and the Red to the positive of the breadboard. Connect the orange to A0 (the photo resistor connected to this will be the laser detector) and the green to A1 (the photo resistor connected to this one will be the ambient light detector).

Let's Do the Buzzer Next

Place the buzzer anywhere on the breadboard. Connect a lead between the negative rail and the negative of the buzzer. Connect the positive end of the buzzer to pin 3 of the Arduino.

Make the Button

Next up, we are going to make the button section

Place the button between 2 terminal strips (make sure that there is contact only when the button is pressed between the 2 strips). Place the last 10k resistor to one end of the button and a negative pin. I've used a jumper wire to connect it to the ground rail. Connect the other end of the button to the positive rail. Then connect the intersection of the button and resistor to pin 4 of the Arduino.

Time for Laser Light!

Lastly let's connect the laser to pin 2 and ground. I've used the pins on the Arduino for both of these. I've used a cheap laser that I've "hacked" by connecting crocodile clips to the spring and the casing with some Velcro holding the button down.

I've written a program to run the Laser Trip Wire.

It continually checks to see whether the button is pressed. If it is pressed we enter the setup mode, if pressed again we enter armed mode.

If we are in setup mode it does the following:

  • It outputs the values to the serial port.
  • When the light on the photo resistor is bright enough pin 13 lights up. This feature allows one to aim the laser.

In the armed mode it does the following:

  • Every 3 seconds it reports via serial communications.
  • It checks if the value from the photo resistor dips due to the laser being broken, when the laser beam is broken the Trip mode is started.

In trip mode the tripwire has been "tripped":

  • It beeps 3 times and the data is sent to the serial port,
  • then returns to the armed mode.

Code

Laser TripwireArduino
// 5 pins trip wire

// Variables
int mode = 1;
int ambiant;
int trip = 1000; // The light value I get when using my laser
int minLight = 900;
int makeBeep = 1; //0 for no beep, 1 for beep!
int atAverage;
long millisCount;

// Output Pins
int laserPin = 2;
int ledPin = 13;
int buzzerPin = 3;
String  modeNames[3] = {"SETTINGS","ARMED","TRIP"};

// Input Pins
int modePin = 4; 
int tripPin = A0;
int ambiantPin = A1;


void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(laserPin, OUTPUT);
  pinMode(buzzerPin, OUTPUT);
  pinMode(modePin, INPUT);
  Serial.begin(9600);
}


void loop() {

  // When the button is pushed
  if (digitalRead(modePin) == 1) {
    trip = analogRead(tripPin);
    mode=mode + 1;
    if (mode >= 2) {
      mode = 0;
    }
    beep(1);
    delay(300);
  }

  
  //does something when the mode changes
  switch (mode) {
    case 0: //calibration mode
      digitalWrite(laserPin,HIGH);
      
      ambiant = analogRead(ambiantPin);
      trip = analogRead(tripPin);
      atAverage = ambiant + ((trip - ambiant)/2);
      stats();
      
      if (trip  >= minLight) {
        digitalWrite(ledPin,HIGH);
      } else {
        digitalWrite(ledPin,LOW);
      }

    break;

    case 1: // Armed mode
      digitalWrite(laserPin,HIGH);
      digitalWrite(ledPin,LOW);
      ambiant = analogRead(ambiantPin);
      atAverage = ambiant + ((trip - ambiant)/2);
      if (analogRead(tripPin) < atAverage) {
        mode = 2;
      }
      if ((millis() - millisCount) >= 3000) {
        millisCount = millis();
        stats();
      }
    break;
    
    case 2: //Trip Mode
      if ((millis() - millisCount) >= 1000) {
        millisCount = millis();
        stats();
        beep(3);
        mode = 1;
      }
    break;
    }

    
  delay(1);                       // wait for a bit
}

//It Beeps
void beep(int qty) {
  int count;
  if (makeBeep == 1) {
    for (count = 1;count<=qty;count++) {
      digitalWrite(buzzerPin, HIGH);
      delay(50);
      digitalWrite(buzzerPin, LOW);
      delay(50);
    }
  }
}

//Writes stats to the Serial Port
void stats() {
  Serial.print("A:");
  Serial.print(ambiant);
  Serial.print(" T:");
  Serial.print(trip);
  Serial.print(" AT:");
  Serial.print(atAverage);
  Serial.print(" MODE:");
  Serial.print(modeNames[mode]);
  Serial.println("");
}

Schematics

Breadboard View
Breadboard View
Laser tripwire beep bb rnul0isroa
Schematic
Schematic view
Laser tripwire beep schem ygwdkxqt0e

Comments

Similar projects you might like

GPS Datalogger, Spatial Analysis, and Azure IoT Hub.

Project tutorial by Shawn Cruise

  • 19,156 views
  • 4 comments
  • 73 respects

Halloween Laser Maze

Project showcase by Sam Horne

  • 7,742 views
  • 6 comments
  • 21 respects

Breadboard to PCB Part 1 - Making the Simon Says Game

Project tutorial by Katie Kristoff and Monica Houston

  • 4,692 views
  • 9 comments
  • 23 respects

Laser Measurements Controlled by Arduino Nano

Project in progress by Ingo Lohs

  • 2,745 views
  • 2 comments
  • 5 respects

Morse Code Communication Using Laser Module (Both)

Project tutorial by SURYATEJA

  • 750 views
  • 0 comments
  • 8 respects

WW2 Tank Laser Tag Sherman & Panther

Project tutorial by Arduino “having11” Guy

  • 16,874 views
  • 1 comment
  • 57 respects
Add projectSign up / Login