Fall ResetAmazon USFall reset deals: check better picks before checkoutAmazon US: today's deals, useful picks and quick comparisons.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanFall ResetAmazon USWork and home upgrades are worth comparing todayAmazon US: today's deals, useful picks and quick comparisons.See Picks×
Skip to content
Blog

Home Security System Using Laser and LDR: Arduino Circuit, Code and Limitations

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

A laser-and-LDR alarm is a useful Arduino project: aim a low-power laser at a photoresistor, and trigger a buzzer when something interrupts the beam. It can demonstrate basic sensing and provide a local warning in a controlled indoor setup, but a single-beam prototype is not a dependable standalone home-security system.

How a laser-and-LDR alarm works

The laser is a light source, not the detector. Its beam falls on a light-dependent resistor (LDR), whose resistance changes with the amount of light it receives. A resistor divider converts that change into a voltage, which the Arduino reads at an analog input. The program compares the reading with a calibrated threshold and activates an alarm output when the reading indicates that the beam has been interrupted.

Signal path: laser module → LDR voltage divider → Arduino analog input → buzzer and/or LED.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

With the divider shown below, the LDR is connected to 5 V and the fixed resistor to ground. In that arrangement, blocking the beam will generally lower the analog reading. Reverse the comparison in the code if your circuit or module behaves differently; verify the actual readings rather than assuming their direction. Beginner project examples demonstrate the same general beam-break approach, but their threshold values are circuit-specific (Arduino Project Hub; Schematik).

#1 Best Overall
Acxico 1Set Sound/Light Alarm Motion Senser Security Infrared Laser Alarm Switch DIY Kits Black
  • Mainly for laser toys, various level meter, instrument and other ground
  • Ohm's law: U = I * R; Transmit power: 150mW; Standard size: Φ6 * 10.5; Spot mode: point-like spot, continuous output; Laser wavelength: 650nm; Optical power: <5mW; Supply voltage: 3VDC; Working current: <25mA; Spot size: 15 meters at the spot for φ10mm ~ φ15mm
  • Tips: This laser is a low-power laser, and a small flashlight laser tube, as part of the safety laser.But laser harmful to the eyes, please do not aim at eyes.Note: AA batteries are NOT included. contain 2pcs 2AA Battery holder.
  • Package Included:1Set Sound / Light Alarm Motion Senser Security Infrared Laser Alarm Switch DIY Kits(If there are any problems with the product, please send us pictures.Tell us more details about this problem.)
  • Thank you so much for your purchasing from our store.Any question ,please feel free to contact us.

Parts for a basic indoor prototype

  • Arduino Uno or compatible board
  • Low-power, properly labeled laser module
  • LDR/photoresistor and a fixed resistor; 10 kΩ is a common starting value, not a universal requirement
  • Piezo buzzer suitable for direct pin drive, or a transistor/MOSFET driver for a higher-current alarm
  • Optional LED and current-limiting resistor
  • Optional reset pushbutton
  • Breadboard, jumper wires, stable USB or regulated power, and rigid mounts
  • Optional opaque tube or hood to shield the LDR from side light

Published demonstrations commonly combine an Arduino, light sensor, resistor, laser, and audible or visual output (Arduino Project Hub; REES52 project example).

Wiring

For a discrete LDR divider, connect the parts as follows:

5 V ---- LDR ----+---- Arduino A0
                 |
               10 kΩ
                 |
                GND

Connect a low-current piezo buzzer between digital pin 9 and ground only if its current draw is within the board pin’s safe limits. Otherwise, drive it through a transistor or MOSFET, with a suitable supply and common ground. An inductive load such as a relay or motor also needs a flyback diode across the load. For an LED, use a current-limiting resistor between digital pin 7 and the LED. Connect an optional reset button between digital pin 2 and ground; the sketch below enables the Arduino’s internal pull-up resistor.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

LDR modules can have different pin labels and onboard circuits, so follow the module’s documentation rather than assuming it is wired like a bare photoresistor.

Rank #2
WiFi Door Alarm System, 8-Piece DIY Wireless Alarm Kit with Door Sensors
  • WIFI Network: WIFI connection, Only works on 2.4GHz WiFi network, does NOT support 5GHz WiFi networks.
  • SMART ALARM SYSTEM for Home: tolviviov Alarm Security System is an affordable solution for your apartment security. You have full control over the door alarms for home security through your smartphone and get instant notifications of alarms alert in your house or apartment.
  • CUSTOMIZATION: You can add extra door and window sensors, motion detectors, wireless doorbell, and water detectors to different rooms in your home security systems;It supports expansion of up to 20 sensors and 5 remote controls/keypads, which can be added to the WiFi alarm station.
  • DIY INSTALLATION: Easily set up tolviviov Wireless Home Security System in minutes without tools. The wireless connection devices does not damage the wall. The alarm station should ALWAYS CONNECT to AC adapter. The backup battery works for 8 hours, only as an emergency battery.
  • VOICE CONTROL: Your tolviviov Home Alarm System can be easily controlled by Away, Disarm, and Home modes with your voice. Works with Alexa and Google Assistant.

Arduino sketch: calibrated threshold, brief confirmation and latched alarm

First use the Serial Monitor to measure your own sensor’s readings. The example below assumes the blocked reading is lower than the beam-present reading, as it usually is with the divider above. Replace the placeholder threshold after calibration. It requires a continuous beam-loss condition for 100 ms, reducing brief glitches, and keeps the alarm on until the reset button is pressed.

const int LDR_PIN = A0;
const int BUZZER_PIN = 9;
const int LED_PIN = 7;
const int RESET_PIN = 2;

// Replace after measuring your own beam-present and blocked readings.
const int TRIP_THRESHOLD = 400;
const unsigned long CONFIRM_MS = 100;

bool alarmLatched = false;
bool checkingBeamBreak = false;
unsigned long beamBreakStarted = 0;

void setup() {
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(LED_PIN, OUTPUT);
  pinMode(RESET_PIN, INPUT_PULLUP);
  Serial.begin(9600);
}

void loop() {
  int lightValue = analogRead(LDR_PIN);
  Serial.println(lightValue);

  // Button is active LOW. Reset is deliberate; it does not re-arm automatically.
  if (digitalRead(RESET_PIN) == LOW) {
    alarmLatched = false;
    checkingBeamBreak = false;
  }

  // For this divider, a low reading indicates that the beam may be blocked.
  // Reverse '<' to '>' if your measured circuit has the opposite polarity.
  bool beamLooksBlocked = (lightValue < TRIP_THRESHOLD);

  if (!alarmLatched) {
    if (beamLooksBlocked) {
      if (!checkingBeamBreak) {
        checkingBeamBreak = true;
        beamBreakStarted = millis();
      } else if (millis() - beamBreakStarted >= CONFIRM_MS) {
        alarmLatched = true;
      }
    } else {
      checkingBeamBreak = false;
    }
  }

  if (alarmLatched) {
    tone(BUZZER_PIN, 2000);
    digitalWrite(LED_PIN, HIGH);
  } else {
    noTone(BUZZER_PIN);
    digitalWrite(LED_PIN, LOW);
  }

  delay(20);
}

The threshold shown is only a placeholder. For a different divider polarity, change the comparison; for a different alarm behavior, change the confirmation interval. The code does not provide a separate arming mode, power supervision, tamper detection, or remote reporting.

Calibrate the sensor instead of copying a number

  1. Mount the laser and aim it at the center of the LDR. Keep the arrangement safe and stable.
  2. Fit an opaque tube or hood around the sensor to reduce room light reaching it from the sides.
  3. Upload a sketch that prints analogRead(A0) values to the Serial Monitor at 9600 baud.
  4. With the beam present, record the typical readings for 10–20 seconds under the lighting conditions where the prototype will be used.
  5. Block the beam repeatedly and record the blocked readings. Try partial and complete obstruction.
  6. Choose a threshold in the gap between the two observed ranges. If the ranges overlap substantially, improve shielding or alignment, or use a different sensing method; an arbitrary threshold will not make ambiguous readings reliable.
  7. Test slow, fast and intermittent interruptions, then repeat after changing the laser, resistor, sensor position or room lighting.

Examples online may use values such as 400 or 500, but those values depend on the sensor, resistor, module design, beam strength, distance and ambient light. They are not transferable settings (How2Electronics example; Arduino Project Hub).

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Placement and laser safety

  • Use rigid mounts, and mark the correct alignment so that small bumps are easy to identify.
  • Place the beam across a narrow indoor passage or opening. A single beam covers only one line: someone may go around, above or below it, or enter by another route.
  • Keep the LDR shielded from side light and avoid directing the beam at reflective surfaces that could redirect it.
  • Consider sunlight, headlights, curtains, pets, vibration and normal movement before choosing a location.
  • Provide a deliberate way to arm, disarm and silence the prototype without requiring anyone to approach an unsafe spot.

Laser warning: Never aim a laser at eyes, vehicles, aircraft or reflective surfaces. Use a low-power, properly labeled module, keep the beam away from eye level where practical, and enclose or shield its path where possible. Do not place it where a child or visitor could look directly into the beam.

Rank #3
Ring Alarm 8-Piece Kit (newest model), Home or business security system with optional 24/7 professional monitoring
  • A great fit for 1-2 bedroom homes, this kit includes one base station, one keypad, four contact sensors, one motion detector, and one range extender.
  • Includes an intuitive Keypad that can arm and disarm your Alarm and Contact Sensors that detect when doors or windows open.
  • Choose the Ring Alarm Kit that fits your needs and detect even more with additional Alarm Sensors and accessories (sold separately) at any time.
  • Receive mobile notifications when your system is triggered and monitor all your Ring devices all through the Ring app.
  • More peace of mind. Subscribe to a compatible Ring Protect Plan (sold separately) to Arm your Alarm from anywhere, keep your system online if the Wi-Fi goes down, and more. Plus, get 24/7 Professional Monitoring for emergency police, fire and medical response, and more.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What can go wrong?

Failure mode Why it matters Practical response
Changing ambient light Sunlight, room lights and reflections can shift an LDR’s reading. A typical LDR does not inherently identify the intended laser. Shield the sensor, calibrate in expected conditions, and use filtering or hysteresis. A photodiode with an optical filter or a modulated beam can improve selectivity, but needs suitable signal conditioning.
Misalignment Movement, vibration or heat can move the beam off the sensor and create an apparent interruption. Use rigid mounts and treat gradual or sustained signal loss as a possible sensor fault, not automatically as proof of entry.
Laser or controller power loss A laser going dark may look like a beam break. If the Arduino loses power too, the alarm may be silent. For a more demanding design, consider backup power, power monitoring and a distinct fault state. A basic sketch cannot supervise its own power failure.
False triggers from ordinary activity People, pets, insects or objects can interrupt the beam. Choose beam height and placement carefully; use a short confirmation interval or combine it with another sensor.
Deliberate bypass A person may avoid the beam, cover the sensor, redirect the beam or imitate the light. Do not use a visible single beam as the only detection layer. Combine different sensor types where appropriate.
Alarm clears when the beam returns A brief interruption may be missed if the alarm stops as soon as light returns. Latch the alarm until a deliberate reset or disarm action, as the sketch does.

Is it suitable for home security?

It is suitable for learning analog sensing and demonstrating a beam-break alarm in a controlled indoor setting. With careful alignment it can trigger a local warning when the beam is interrupted. That is different from a complete security system, which must account for coverage, faults, tampering, power loss, user alerts and reliable operation in changing conditions. This prototype does not establish those properties, and a buzzer is only a local indicator, not necessarily a loud or supervised siren.

Choose a laser-and-LDR project when a visible beam and hands-on electronics are the goal, the area is narrow and indoors, and occasional adjustment is acceptable. Do not rely on it as primary protection for a home, unattended outdoor area, or situation requiring monitored alarms, dependable notifications, code compliance or life-safety performance. Notifications over Wi-Fi or cellular can improve awareness but add network, account, power and service dependencies; they do not by themselves make the detector secure.

Which sensor is a better fit?

Need Consider Reason
Detect a door or window opening Magnetic reed contact Does not depend on an aligned optical path.
Detect movement in a room PIR motion sensor Covers an area rather than one narrow beam.
More controlled optical detection Photodiode or phototransistor Can respond faster and be used with more selective optical sensing; it is not always a drop-in LDR replacement.
Outdoor beam detection Commercial photoelectric beam sensor Designed for beam alignment and, depending on the product, outdoor conditions and supervision.
Whole-home protection Layered commercial alarm system Can combine door/window contacts, motion sensing, backup power, tamper reporting and optional monitoring. Check features and availability for your location.

Testing checklist

  • Confirm readings with the beam aligned and fully blocked.
  • Try a partial obstruction and slow, fast and intermittent interruptions.
  • Check operation under expected room lighting and with likely reflections.
  • Verify what happens if the laser is unplugged, the Arduino restarts or power is interrupted.
  • Press reset and confirm the alarm clears only as intended.
  • Check for nuisance triggers from normal movement, pets and vibration.
  • Remember that a successful bench test confirms beam-break behavior only; it does not prove reliable whole-home coverage.

For a classroom project, an Arduino, LDR, laser and buzzer make an accessible demonstration. For actual property protection, use a purpose-built, appropriately installed alarm and treat any DIY beam sensor as supplementary rather than as the sole safeguard.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.