MyRoboPathOpen Robotics Lab
Arduino Uno #31 of 35
Est. 0.75 Hours
Budget: $3 - $5
Beginner

KY-008 Red Laser Module & Optical Tripwire Alarm

Project a focused 650nm red laser beam onto an LDR photoresistor to build a high-speed optical security tripwire.

Build a spy-movie laser tripwire right on your workbench! Drive the KY-008 650nm red laser diode emitter from Arduino Uno D7, aim its crisp beam directly onto a paired LDR receiver on A0, auto-calibrate beam-locked vs. broken thresholds, and latch an audible security alarm when anything crosses the line.

Arduino Uno R3KY-008 Laser DiodeLDR ReceiverOptical TripwireLatched Alarm
KY-008 Red Laser Module & Optical Tripwire Alarm Blueprint
KY-008 Red Laser Module & Optical Tripwire AlarmCAD Blueprint

Key Learning Objectives & Robotics Concepts

By building and programming this project, you will master the following core engineering skills:

1Practice laser lab safety rules for 650nm semiconductor laser diodes.
2Align an optical emitter-receiver pair and shade the LDR in a short dark tube to reject room light.
3Auto-calibrate "beam locked" ADC at arming so the tripwire adapts to any room lighting.
4Implement a latched security alarm state that persists until an authorized Reset click.

Power Architecture & Voltage Staging

5V / 3.3V Regulated Power

The KY-008 module integrates an onboard SMD current-limiting resistor allowing safe 5V operation at ~28mA from Arduino D7 (or 5V rail). The LDR voltage divider draws <1mA. EYE SAFETY: Class II/IIIa 5mW 650nm laser—NEVER aim at eyes, faces, pets, or glossy mirrors! Keep beam strictly horizontal at tabletop height.

KY-008 Red Laser Module & Optical Tripwire Alarm Power Architecture Schematic
Figure: Regulated Arduino Uno supply rails, current budget, and component protection.Power Schematic

Bill of Materials (BOM) & Hardware Components

Bill of Materials for KY-008 Red Laser Module & Optical Tripwire Alarm
ComponentSpecifications & AlternativeQtyApprox Cost
Arduino Uno R3ATmega328P @ 16MHz1$8.00
KY-008 650nm Red Laser Module5V, <5mW focused red laser diode1$1.20
LDR Photoresistor Module (or Bare LDR+10kΩ)Optical beam target receiver1$1.20
Piezo Buzzer, Red LED + 220Ω, Reset ButtonLatched alarm output & disarm control1$1.10

Electrical & System Architecture

Connect KY-008 Signal (S) to D7 and (-) to GND. Across the gap, connect LDR receiver AO to A0 (5V/GND powered). Wire Piezo Buzzer to D8, Alarm LED (+220Ω) to D9, and Reset Button to D2 (INPUT_PULLUP).

Figure: Complete Arduino Uno R3 pin-to-pin wiring schematic for KY-008 Red Laser Module & Optical Tripwire Alarm.
Figure: Complete Arduino Uno R3 pin-to-pin wiring schematic for KY-008 Red Laser Module & Optical Tripwire Alarm.Wiring Schematic

Autonomous Behavior & Finite State Machine (FSM)

Deterministic Arduino loop handling KY-008 650nm Red Laser + LDR Receiver acquisition, filtering, and real-time output updates.

Figure: Firmware execution flow and state transitions for KY-008 Red Laser Module & Optical Tripwire Alarm.
Figure: Firmware execution flow and state transitions for KY-008 Red Laser Module & Optical Tripwire Alarm.Control Algorithm

Step-by-Step Physical Assembly & Wiring Tutorial

Follow each of the 5 sequential milestone stages with technical photos, wiring checks, and pre-flight tests.

1

Observe Laser Safety & Inspect KY-008 Pins

Duration: 5 Mins

Confirm KY-008 pinout (S = signal/5V, middle = NC/5V, - = GND) and establish safe horizontal beam line.

KY-008 Red Laser Module & Optical Tripwire Alarm hardware layout diagram
Stage 1: KY-008 650nm Red Laser + LDR Receiver hardware inspection & pinout overview.Stage 1 Diagram
Step Action Checklist:
  • Check KY-008 silkscreen: S connects to D7 (or 5V), "-" connects to GND (middle pin is unused on most boards).
  • Mount the laser and LDR 20–40cm apart facing directly at each other at identical height.
  • Slip a 2cm piece of black paper or straw over the LDR to block stray overhead ceiling lamps!
Engineering & Tuning Tip: Shading the LDR with a tiny paper shroud increases tripwire reliability by 10× in bright rooms!
2

Wire Laser (D7), LDR (A0), Alarm (D8/D9) & Reset (D2)

Duration: 10 Mins

Complete both emitter and receiver circuits cleanly.

KY-008 Red Laser Module & Optical Tripwire Alarm breadboard wiring check diagram
Stage 2: Breadboard layout & Arduino Uno pin-to-pin wiring audit.Stage 2 Diagram
Step Action Checklist:
  • Connect KY-008 S → D7 and (-) → GND.
  • Connect LDR Module VCC → 5V, GND → GND, AO → A0.
  • Wire Buzzer to D8, Red LED (+220Ω) to D9, and Reset Switch between D2 and GND.
Engineering & Tuning Tip: Using D7 to power the laser lets firmware switch the beam OFF when disarmed or modulate it for anti-spoofing!
3

Align Red Laser Dot Directly onto LDR Face

Duration: 5 Mins

Power up the laser and carefully aim the bright red dot squarely onto the LDR's wavy sensor grid.

KY-008 Red Laser Module & Optical Tripwire Alarm power rail protection diagram
Stage 3: Supply rail check (USB 5.0V Regulated Rail (≈30mA laser diode)) and circuit protection verification.Stage 3 Diagram
Step Action Checklist:
  • Upload the diagnostic sketch to turn D7 HIGH and stream live A0.
  • Adjust laser angle until the red dot centers cleanly on the LDR sensing surface.
  • Verify a huge ADC contrast (≥200 counts jump) when you slip a finger across the beam.
Engineering & Tuning Tip: Use a dab of modeling clay or breadboard tape to lock the laser angle steady so desk bumps don't misalign it.
4

Upload Auto-Calibrating Latched Tripwire Firmware

Duration: 10 Mins

Flash the security system that locks onto the aligned beam at boot and latches the alarm on breach.

KY-008 Red Laser Module & Optical Tripwire Alarm serial telemetry verification diagram
Stage 4: Firmware upload & 115200 baud Serial Monitor verification.Stage 4 Diagram
Step Action Checklist:
  • Ensure the red dot is aimed squarely on the LDR, then upload the production sketch.
  • Wait 1 second for Serial to print "BEAM LOCKED & ARMED".
  • Pass your hand across the beam—confirm the alarm latches ON even after you pull your hand away!
Engineering & Tuning Tip: Notice INVERT_LDR handles standard LM393 LDR modules (lower ADC = brighter light) automatically!
5

Test Disarm Button & Fast-Swipe Detection

Duration: 5 Mins

Press D2 to clear the alarm, then test rapid finger swipes across the beam.

KY-008 Red Laser Module & Optical Tripwire Alarm live operational logic diagram
Stage 5: Live operational logic flow & calibration verification.Stage 5 Diagram
Step Action Checklist:
  • Press Reset (D2) with beam clear → siren stops and system re-arms cleanly.
  • Swipe a pencil swiftly across the laser beam—verify instant sub-5ms breach capture.
  • Power off the laser whenever stepping away from the bench.
Engineering & Tuning Tip: You can bounce one laser off two small mirrors to create a zigzag laser corridor across an entire doorway!

Subsystem Benchtop Verification Scripts

Test each hardware subsystem independently before deploying the full autonomous firmware.

1Bench Diagnostic: KY-008 650nm Red Laser + LDR Receiver Hardware Check

Subsystem Diagnostic

Minimal standalone sketch to verify pin wiring and signal response for KY-008 650nm Red Laser + LDR Receiver before running the full project firmware.

Arduino IDE Diagnostic ScriptC++ / Arduino
// Diagnostic: Laser Alignment & Contrast Check
void setup() { pinMode(7, OUTPUT); digitalWrite(7, HIGH); Serial.begin(115200); }
void loop() { Serial.print("LDR A0 (Laser ON): "); Serial.println(analogRead(A0)); delay(150); }
Expected Output: Shows sharp contrast (e.g., ~90 with laser hitting LDR vs ~650 when beam blocked).

Complete Production Firmware

Full working C++ source code with pin mappings, non-blocking timers, and FSM avoidance routines.

arduino_uno_ky008_laser_tripwire_security.ino
arduino_uno_ky008_laser_tripwire_security.inoArduino C++
/**
 * Project 31: KY-008 Red Laser Optical Tripwire Security System
 * Board: Arduino Uno R3 | Pins: D7(Laser), A0(LDR), D8(Buzzer), D9(LED), D2(Reset)
 */
const uint8_t LASER_PIN  = 7;
const uint8_t LDR_AO     = A0;
const uint8_t BUZZER_PIN = 8;
const uint8_t ALARM_LED  = 9;
const uint8_t RESET_BTN  = 2;

const bool INVERT_LDR = true; // Standard LDR module: lower ADC = brighter laser hit
const int BREAK_DELTA = 140;

int beamLockedAdc = 100;
bool alarmLatched = false;

void armSystem() {
  digitalWrite(LASER_PIN, HIGH);
  noTone(BUZZER_PIN);
  digitalWrite(ALARM_LED, LOW);
  delay(250);
  long sum = 0;
  for (int i = 0; i < 8; i++) { sum += analogRead(LDR_AO); delay(10); }
  beamLockedAdc = sum / 8;
  alarmLatched = false;
  Serial.print(F("BEAM LOCKED & ARMED | Reference ADC="));
  Serial.println(beamLockedAdc);
}

void setup() {
  Serial.begin(115200);
  pinMode(LASER_PIN, OUTPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(ALARM_LED, OUTPUT);
  pinMode(RESET_BTN, INPUT_PULLUP);
  armSystem();
}

void loop() {
  if (digitalRead(RESET_BTN) == LOW) {
    Serial.println(F("[RESET] Re-arming laser tripwire..."));
    armSystem();
    delay(300);
  }

  int cur = analogRead(LDR_AO);
  bool beamBroken = INVERT_LDR
    ? (cur > beamLockedAdc + BREAK_DELTA)
    : (cur < beamLockedAdc - BREAK_DELTA);

  if (beamBroken && !alarmLatched) {
    alarmLatched = true;
    Serial.print(F("[BREACH!] Laser beam interrupted! ADC="));
    Serial.println(cur);
  }

  if (alarmLatched) {
    digitalWrite(ALARM_LED, HIGH);
    tone(BUZZER_PIN, 2200, 120);
    delay(150);
    digitalWrite(ALARM_LED, LOW);
    delay(100);
  }
}

Firmware Architecture Explanation:

  • Auto-captures the exact aligned laser intensity (beamLockedAdc) during armSystem().
  • Latches alarmLatched = true on any instantaneous beam break so quick sprints cannot escape detection.
  • Pressing Reset (D2) silences the siren and re-calibrates the armed threshold cleanly.

Operational Verification & Pin State Matrix

1Double-check all 5 Arduino Uno pin connections against the wiring schematic before plugging in USB.
2Upload the Bench Diagnostic sketch first and confirm Serial Monitor at 115200 baud matches: Shows sharp contrast (e.g., ~90 with laser hitting LDR vs ~650 when beam blocked).
3Upload the complete production sketch and verify every condition in the operational truth table below.

Input Signal vs. System Output Truth Table:

Operational truth table for KY-008 Red Laser Module & Optical Tripwire Alarm
Input / StatePin / SignalDetected ConditionExpected Output
Laser Hits LDRA0 ≈ beamLockedBeam IntactArmed Standby (Silent)
Object Blocks BeamΔADC > 140Beam InterruptedLatch Siren + Blink D9 LED
Reset ClickedD2 = LOWAuthorized DisarmSilence & Re-Arm Beam

Engineering Troubleshooting Matrix

Engineering troubleshooting matrix for KY-008 Red Laser Module & Optical Tripwire Alarm
ProblemLikely CauseDiagnostic CheckEngineering Solution
Triggers immediately upon armingLaser drifted off LDR face or desk light flickeringVerify red laser dot sits squarely on LDR centerSecure laser firmly, shroud LDR in dark paper tube, and press Reset.
Blocking beam does not trip alarmRoom light too bright (contrast < 140) or INVERT_LDR wrongRun alignment diagnostic to compare ON vs blocked ADCAdd dark paper shroud around LDR or flip INVERT_LDR.
Laser beam looks very dimKY-008 wired through extra resistor or loose groundCheck D7 → S directly (module already has onboard resistor)Connect D7 directly to S and (-) to GND.

Engineering Challenges & Upgrades

Take your build to the next level with these progressive engineering upgrades:

Level 1Keypad PIN Disarm

Require entering 4-digit PIN on Project 25 Keypad to silence the tripwire.

Level 2High-Speed Lap Finish Gate

Measure miniature race car lap times to the millisecond using micros() on beam break.

Level 3Modulated Anti-Spoof Laser

Pulse the laser at 20Hz and verify the LDR sees the exact matching pulse so flashlights cannot fool it!