Create a trip-wire alarm that signals when a laser beam is interrupted.

What will I learn?

You will learn how to read analog values from a connected sensor and perform some action based on the value read from the sensor. You also learn about the LDR resistor and laser usage in Arduino projects.

Prerequisites

A Computer with a configured Arduino IDE tested and working. If you don’t know how to get the basic set up working, check out my guide for Getting started (1/5)

Important notes

  • This project contains components that cannot handle 5V, so take care to use resistors (1 KOhm) with the LEDs.
  • Respect minus and plus, otherwise you may damage the components.
  • Start out by figuring out what components can handle 5V and what components can’t. If you connect a component that cant handle 5V you may destroy the component.
  • Several different light resistors exist. Based on their resistor value it could be necessary to add a different resistor than the 10KOhm resistor from between the LDR and GND (see below). The 10KOhm resistor adjusts the sensitivity of the LDR.

What you need

  • Breadboard
  • Dupont wires & jumper wires
  • CP2102
  • Arduino Pro Mini
  • LDR GL5539 50-90K light resistor
  • 1 KOhm resistor
  • 10 KOhm resistor
  • 5mW 5V Laser

Connecting instructions

  • Arduino VCC → Positive laser pin
  • Arduino GND → Negative laser pin
  • Arduino VCC → LDR resistor first pin
  • Arduino A0 → LDR resistor second pin
  • LDR resistor second pin → 10KOhm resistor and then to GND
  • Arduino GND → Negative buzzer pin
  • Arduino D10 → Positive buzzer pin
  • Arduino D9 → Positive pin of Red LED
  • LED negative pin → 1KOhm resistor and then to GND

 

Fritzing

alarm-tripwire_bb

Code

/**
* Tripwire alarm - alarm that signals when a laser beam is interrupted.
*
* Connections:
* - Arduino VCC → Positive laser pin
* - Arduino GND → Negative laser pin
* - Arduino VCC → LDR resistor first pin
* - Arduino A0 → LDR resistor second pin
* - LDR resistor second pin → 10KOhm resistor and then to GND
* - Arduino GND → Negative buzzer pin
* - Arduino D10 → Positive buzzer pin
* - Arduino D9 -> Positive pin of Red LED
* - LED negative pin -> 1KOhm resistor and then to GND
*
* Author: Jakob Maaloe
* https://wackydeveloper.wordpress.com
*/

int lightSensor = A0;

int ledPin = 9;
int buzzerPin = 10;

int value;

void setup() {
Serial.begin(115200); // Sets the baud rate for logging

pinMode(lightSensor, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
}

void loop() {
value = analogRead(lightSensor); // reads the sensor value

Serial.print("Sensor value: ");
Serial.println(value); // prints the light sensor value

if (value < 600) {
Serial.println("James bond got caught!");
digitalWrite(ledPin, HIGH);
digitalWrite(buzzerPin, HIGH);

} else {
digitalWrite(ledPin, LOW);
digitalWrite(buzzerPin, LOW);
}
delay(300); // wait a little while before doing another read
}

Next steps

What happens with the value if you change the 1KOhm resistor connected between the LDR resistor and GND to something higher or lower? When you are done, try the next project, the Plant Monitor.

Advertisements