Laser Tripwire Security System Using LDR

Laser Tripwire Security System Using LDR

Main Diagram

Hardware Required

  • PICUNO Microcontroller board
  • 1 × LED
  • 1 × 220Ω resistor
  • 1 × 10kΩ resistor
  • 1 × LDR (Light Dependent Resistor)
  • 1 × Buzzer
  • Breadboard
  • Jumper wires
  • USB cable

Description

This project creates a basic security system using a laser and LDR setup. A laser beam or torch is continuously focused on the LDR. When the beam is interrupted (someone crosses the path), the LDR value changes sharply, triggering a buzzer alarm. And an LED is added to visually indicate the breach.

Circuit Diagram

[Fritzing image to be added here]

Circuit

  • Connect the PICUNO board to the computer using a USB cable.
  • Connect the Anode of the LED to one terminal of a 220Ω resistor.
  • Connect the other terminal of the resistor to GPIO pin 6.
  • Connect the Cathode of the LED to GND.
  • Connect one end of the LDR to 3.3 V
  • Connect the other end of the LDR to Analog Pin A0 through one end of 10kΩ resistor.
  • Connect the other end of the 10kΩ resistor to GND.
  • Connect positive terminal of the buzzer to GPIO 7.
  • Connect negative terminal of the buzzer to GND.

Schematic

One end of the LDR → VCC (3.3V)

Other end of the LDR → Analog pin A0

A 10kΩ resistor from A0 → GND

LED anode → 220-ohm resistor → GPIO 6

LED cathode → GND

Buzzer +ve terminal → GPIO 7

Buzzer -ve terminal → GND

Code - C

int ldrPin = A0;
int buzzerPin = 7;
int ledPin = 6;
int threshold = 500;

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

void loop() {
  int ldrValue = analogRead(ldrPin);
  Serial.print("LDR Value: ");
  Serial.println(ldrValue);

  if (ldrValue < threshold) {
    digitalWrite(buzzerPin, HIGH);
    digitalWrite(ledPin, HIGH);
  } else {
    digitalWrite(buzzerPin, LOW);
    digitalWrite(ledPin, LOW);
  }
  delay(100);
}
analogRead(ldrPin) - Monitors brightness hitting LDR.

threshold - Value below which beam is considered broken.

digitalWrite(buzzerPin, HIGH) - Sounds buzzer on beam break.

Serial.println(...) - Allows value tuning using Serial Monitor.

Code - Micropython

from machine import ADC, Pin
import time

ldr = ADC(0)
buzzer = Pin(7, Pin.OUT)
ledpin = Pin(6, Pin.OUT)

while True:
    value = ldr.read_u16()
    print("LDR:", value)

    if value < 30000:  # Adjust as needed
        buzzer.value(1)
        ledpin.value(1)
    else:
        buzzer.value(0)
        ledpin.value(0)
    time.sleep(0.1)
read_u16() - Reads analog light value.

value < 30000 - Beam broken = low light = sound alarm.

buzzer.value(1) - Triggers alarm.