Build this project at our next weekend-long Arduino workshop!

Laser Tripwire

Laser Tripwire is a simple implementation of a laser-triggered alarm. A light-dependent resistor in a voltage divider circuit is kept low by shining a laser on it. Interrupting that laser beam sends the analog input over a threshold, triggering the alarm and sounding a buzzer until a reset button is pressed.

Hardware

You’ll need the following components:

Wiring

  1. Build this circuit:

    Fritzing for a buzzer, laser diode, LDR, and button
    Fritzing for a buzzer, laser diode, LDR, and button | full size »
    Schematic for a buzzer, laser diode, LDR, and button
    Schematic for a buzzer, laser diode, LDR, and button | full size »

  2. Make sure to aim the laser diode directly at the LDR. Note: Never look into a laser pointer directly!

Software

  1. Copy this code into a new Arduino sketch:

    int laserPin = 3;
    int sensorPin = A0;
    int buttonPin = 12;
    int buzzerPin = 11;
    
    int laserThreshold = 10;
    
    void setup() {
      pinMode(laserPin, OUTPUT);
      pinMode(buttonPin, INPUT_PULLUP);
      Serial.begin(9600);
    }
    
    boolean alarmState = false;
    
    void loop() {
      if (! alarmState) {
        delay(1000);
        digitalWrite(laserPin, HIGH);
        delay(10);
        unsigned long startTime = millis();
        while (millis() - startTime < 1000) {
          int sensorValue = analogRead(sensorPin);
          Serial.println(sensorValue);
          if (sensorValue > laserThreshold) {
            alarmState = true;
            break;
          }
          delay(10);
        }
        digitalWrite(laserPin, LOW);
      } else {
        tone(buzzerPin, 440);
        if (! digitalRead(buttonPin)) {
          alarmState = false;
          noTone(buzzerPin);
        }
        delay(10);
      }
    }
    
  2. Upload the project.

  3. Observe the values in the serial monitor to make sure that your threshold value is just slightly higher than the values you observe when the laser is hitting the LDR. Modify your threshold value if necessary.

Variations

  1. Change the code so that the laser tripwire is always on, instead of blinking on and off every second.

  2. Change the code so that the buzzer plays a melody instead of a steady tone in the alarm state.

  3. Add an LED to the circuit that turns on to indicate the alarm state.