0% found this document useful (0 votes)
34 views8 pages

Raspberry. Trip Laser Wire

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views8 pages

Raspberry. Trip Laser Wire

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Projects

A Raspberry Pi laser tripwire


Build a laser tripwire with Python and a Raspberry Pi

Step
1 Introduction

In this resource you will use a laser pointer, a few electronic components, and a Raspberry Pi to make a laser
tripwire. Each time a stealthy intruder breaks the laser beam, the Raspberry Pi will sound the alarm via a buzzer or a
speaker.

By completing this project you will learn how to:

Measure light levels with an LDR


Control a buzzer
Play sounds using the PyGame Python module
Write and call simple lambda functions

This resource covers elements from the following strands of the Raspberry Pi Digital Making Curriculum:

Use basic programming constructs to create simple programs (https://www.raspberrypi.org/curriculum


/programming/creator)
Combine inputs and/or outputs to create projects or solve a problem (https://www.raspberrypi.org/curri
culum/physical-computing/builder)
Step
2 What you will need

Hardware

A Raspberry Pi
A breadboard
A 1µF capacitor
A light-dependent resistor (LDR)
3 female-male jumper leads (for testing)
3 female-female jumper leads
A laser pointer
A drinking straw

Software

All required software is pre-installed on Raspberry Pi OS


Step
3 Detecting a broken beam

Your first step will be to create a simple prototype on a breadboard to detect whether or not a beam of light is
hitting the light-dependent resistor (LDR).

Shielding the LDR

It’s a good idea to shield your LDR to make sure that only light from the laser pointer will trigger your program. You
can do this with a small roll of paper, or even more easily with a section of a drinking straw.

Building and coding your light sensor

Now you’re going to need to do a couple of things:

Set up your circuit using a capacitor and an LDR wired to your Raspberry Pi. There’s an optional section below
which explains how RC timing circuits work. The other section details how to use Python to detect light levels.

Now you’re ready to write a script to detect when the laser beam is broken. You can use methods from the
gpiozero module to do this. One of your options is to use a while True loop containing the
wait_for_dark method. However, a better way might be to use the when_dark method. If you choose this
method, you need to either create a function to print 'INTRUDER', or you could use a lambda function.

If you need a little help, then have a look at the hints below.

Here’s an animation showing how to set up the circuit and write your Python program.
Step
4 Making some noise

There are two ways you can get you program to make some noise rather than just print ‘INTRUDER’. The first is to
use a buzzer that is switched on when the laser beam is broken. The second is to use the PyGame module to play a
sound through some speakers.

Have a look at the sections below that detail how to use buzzers and play sounds with PyGame. Choose the method
your prefer, and then have a go at making some noise when the laser beam is broken. If you want to have a go at
playing sounds through the speakers, then this site (http://soundbible.com/royalty-free-sounds-1.html) has
plenty of di"erent ones to choose from. This one in particular (http://soundbible.com/71-Dog-Growling-And-B
arking.html) might be useful.

Here’s a couple of videos showing you how to use either method:


Step
5 Building your laser tripwire

Once the circuit has been tested, you can wire up the components directly to the Raspberry Pi as shown below.

1. Place one leg of the LDR and the long leg of the capacitor into a female-to-female jumper lead. Then tape it up
to secure the legs.

2. Place the remaining legs into jumper leads, then plug it all back into the Raspberry Pi.

You can place the Raspberry Pi and components in a housing to conceal them if you wish. Here we have used a
plastic box with a hole made in it for the straw:
1. Place your container near a doorway. Then a#x the laser pointer to the wall so the beam is focused down the
straw.

2. Now run the code and test your laser tripwire.

3. If you want to run your code as soon as the Raspberry Pi boots up, then have a look at the instructions below
for automating tasks with Cron.
Step
6 What next?

You could try and include other events that are triggered when the tripwire is broken. How about sending a
tweet (python-sending-a-tweet), or taking a picture (rpi-picamera-take-photo) of the intruder?
You could use a laser component that can be run directly from the Raspberry Pi’s GPIO pins. Here’s an example
of a laser (https://www.rapidonline.com/laserfuchs-70103984-red-class-2-laser-10m-1mw-3-12vdc-25
ma-650nm-wavelength-57-5868) you could buy.

Published by Raspberry Pi Foundation (https://www.raspberrypi.org) under a Creative Commons license


(https://creativecommons.org/licenses/by-sa/4.0/).
View project & license on GitHub (https://github.com/RaspberryPiLearning/laser-tripwire)

You might also like