You’ve probably seen a movie where a valuable item is protected by a grid of laser beams. The beams look cool and seem pretty hightech, but the principles behind them are actually very simple.

See also: How to build a plant monitor with Arduino

How it works

When the laser pen shines on the photoresistor, the green LED will light up to signify that the circuit is ready. When the laser beam is broken, the LED turns off and the buzzer sounds.

echo do_shortcode('[inread_parallax slot="DFP-EW-InRead2-Mobile" width="300"]'); ?

echo do_shortcode('[inread_parallax slot="DFP-EW-InRead2-Mobile" width="300"]'); ?

As we know from Projects 13 (“Weather Station”) and 18 (“Intruder Sensor”), photoresistors produce variable resistance depending on the amount of light falling on their sensor. When the photoresistor does not detect light from the laser, it will drop its resistance and trigger the Arduino to send voltage to the pin controlling the buzzer.

Laser beams that are visible in daylight or even in the dark are very powerful and can be extremely dangerous. In this project we’ll use a low-powered laser pen instead.

NOTE: Laser pens can still be dangerous and should never be directed toward anybody’s eyes!

The laser trip wire build

1. Insert your photoresistor into the breadboard. Connect one leg to the +5V rail using a jumper wire. Connect a 10k-ohm resistor to the other leg, and connect the other side of this resistor to Arduino A0 and GND on the breadboard.

2. Connect the red (positive) wire of the piezo buzzer directly to Arduino pin 11 on the Arduino and the black (GND) wire to GND on the breadboard.

3. Insert the green LED’s long leg into Arduino pin 13 and the short leg into GND.

4. Connect the power rails to the breadboard.

5. Before you upload the code, you need to check the photoresistor’s value in ambient light. Run the following small program with the photoresistor set up as instructed.

6. Open the Serial Monitor in the Arduino IDE. It will show the value being read from the light resistor – in the example, pictured right, it’s 964 – in normal lighting conditions. Take note of your number, which will be different depending on your lighting conditions.

Now shine the laser on the resistor’s cell, and also note this number; my reading is 620. This might seem counterintuitive, as you would expect more light to provide a higher number, but the figure is actually translating the resistance – more light, less resistance.

Your values will differ from those shown here, so make sure to record your two readings.

7. Check that your setup matches that shown right, and then upload the code in “The Sketch” shown further below.

The Sketch

The sketch first sets Arduino pin 11 as an OUTPUT for the piezo buzzer and pin 13 as an OUTPUT for the LED.

The photoresistor is connected to Arduino pin A0. If the analog reading from A0 is more than 850 (meaning that there is less light and the laser beam has been broken), the buzzer will be set to HIGH and turn on and the LED will turn off.

Remember to change the resistance value depending on your calibration on this line:

if (analogRead(0) > 850) {

As noted earlier, when the laser is shining on the resistor it reads about 620, so in the sketch I’ve set the buzzer to sound only if the value is more than 850. This value is between our laser value and our nonlaser value, so we know the laser beam to the resistor has been broken if the value reaches 850.

Parts list for laser trip wire

Arduino board

Breadboard

Jumper wires

Photoresistor

Piezo buzzer

Green LED

10k-ohm resistor

Laser pen

Extracted from the Arduino Project Handbook, written by Mark Geddes and published by No Starch Press. It is described as a beginner-friendly collection of electronics projects using the low-cost Arduino board, and it’s highly recommended by Gadget Master!

See also: How to build a plant monitor with Arduino

See also: Gadget Book: The Arduino Project Handbook

All images: Arduino Project Handbook, © 2016 by Mark Geddes