Introduction: Laser Perimeter Security Mechanism WITH ARDUINO! (Beginners/Intermediate)
(Main Image fromhttp://gente.ig.com.br/2012-07-03/tom-cruise-50-an...)
(Image taken at Jacobs Institute for Design and Innovation at UC Berkeley, College of Engineering)
Ever seen an action movies where the heroes ingeniously breech through laser obstacle detector? The mechanism is often called the "Laser Obstacle Detector" or "Laser Perimeter. These detectors shoot lasers across the room or a hall-way. They ring the alarm whenever an invader touches one of those laser blades.
But how does it work? In this Instructable, I will use an Arduino and some of its sensors and equipments to demonstrate one of the simplest ways to build a Laser Perimeter. This Laser Perimeter will turn on the LED light bulb and ring the alarm (buzzer) whenever the laser is breached.
Minimal prior experience in Arduino is recommended, as simple one as blinking an LED on Arduino, but a complete beginner can follow along this Instructable as well, given time.
Required Equipments (Total approx. $20 ~ 40)
1. One Arduino Board (Arduino Nano or Arduino Uno Recommended)
2. One Arduino BreadBoard
3. 20 (or less) Arduino Wires
4. 1 Arduino Photo-resistor (aka. Photocell or Photodiode)
5. 1 Arduino Buzzer
6. 1 Arduino LED Lightbulb
7. 3 or more Arudino Resistors
8. Laser Pointer (Quality doesn't matter) and it's batteries
9. (Optional) Soldering tools
If you're using a Windows OS, you'll need to download the Arduino USB driver. Check out the guidelines here:
https://www.arduino.cc/en/Guide/Windows
First and foremost, I'd like to thank Jacobs Institute for Design and Innovation (at UC Berkeley) for offering a wonderful workspace.
Step 1: Arduino Setup
Arduino Setup
The first step is to set up your Arduino and get ready for the project! Very Simple. Take out your Main Arduino board, a Breadboard, and Open the Arduino Software IDE on your computer.
If you don't have the Arduino IDE, access this link : https://www.arduino.cc/en/Main/Software
and go to "Download the Arduino IDE"
Download all the essentials the package tells you to download.
When you execute the software, you should see a screen similar to the image above.
Step 2: Connecting the Photo-Resistor
Connect your Arduino board and Photo-Resistor as seen on the Arduino Schematic image above.
Remember, on the breadbord:
- the edge part with '+' row and '-' row has horizontal connection
- the middle part with alphabets and numbers has vertical connection
DO NOT CONNECT THE PINS WHILE YOUR ARDUINO BOARD IS POWERED!
STEPS:
1. Connect the 5V on the Arduino board with '+' on the Breadboard
2. Connect the GND pin on the Arduino board with '-' on the Breadboard
3. Plug in the photo-resistor on the middle part of the breadboard
- Photo-resistor has two connection pins! Be aware of their positions. I will refer to them as left end and right end
4. Connect the '+' on the Breadboard to the right end of the Photo-resistor
5. Connect the '-' on the Breadboard to the left end of the Photo-resistor, via resistor
6. Connect the left end of the Photo-resistor to Arduino Board pin A0 (On the Analog In section)
Step 3: Test Your Photo-Resistor
Let's get back to your Arduino IDE to check out how the Photo-resistor works!
In Arduino IDE, go to:
File -> Examples -> 01. Basics -> AnalogReadSerial
The IDE should look like the image above. If you can't find the code, copy and paste the code I've posted below.
1. Connect your Arduino to your computer
2. Click the Upload button (looks like an arrow, located on top left)
3. Click the Serial monitor
4. Now, if you see numbers scrolling on the screen, place your finger on the Photo-resistor and realize how the number changes. Then, remove your finger and confirm that the number goes back up.
If you've completed this step, you're good to go!
If you're having errors, check out the following:
1. Tools -> Board : " ~ " : check if the ~ part is the board you're using!
2. Tools -> Port: select the usb port you're using. It's normally the last port on the list.
3. Try downloading the Arduino Driver again.
4. Try pressing the reset button on the Arduino right after you press Upload button
5. Check the circuit
CODE:
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
delay(1);
}
Step 4: Connect Your LED
In this step, you'll learn to conduct an operation based on the Photo-Resistor's input. Follow the steps:
1. Connect Arduino Board's Pin13 with an LED. Please consult the image above
- For LEDs, there are two pins. The longer pin is called 'Anode', which should be connected with the power (+) source. (In this case, pin 13) The shorter pin is called 'Cathode', which should be connected with the Ground (-) with resistance.
2. Open your Arduino IDE
3. In the "void setup() {" method, type in the following:
- pinMode(13, OUTPUT);
4. In the "void loop() {" method, type in the following:
int thresholdValue = 300; //change this whenever necessary
if (sensorValue < thresholdValue){
digitalWrite(13,HIGH);
} else {
digitalWrite(13,LOW);
}
5. Plug in your Arduino and Update the code. (The entire code will be posted below)
6. Open the Serial Monitor and realize that the LED blinks whenever the Laser is not shot at the Photo-Resistor
Explanation:
Realize that I've set the thresholdValue as 300. In my room, the average room brightness is sensed as about 200~300 in the sensorValue. When I shot my laser on the Photo-Resistor, that number went up to 800. (The maximum value of the Photo-Resistor is 1023)
Thus, the code we uploaded will read :
"If the brightness detected is as low as the room's brightness, turn on the LED. If brighter than the room's brightness, turn off the LED"
If you're interested in making this process more convenient and universal, try ->
File -> Example -> 03. Analog -> Calibration
CODE:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(7,OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() { // read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);
delay(1);
// delay in between reads for stability
int thresholdValue = 300; //change this whenever necessary
if (sensorValue < thresholdValue){
digitalWrite(13,HIGH);
} else {
digitalWrite(13,LOW);
}
}
Step 5: Connect Your Buzzer
This step will add an alarm to the Laser Perimeter.
1. Connect your buzzer (or piezo) to your Arduino Pin 8
- It's usually marked on the buzzer which side is +. If not, the longer pin should be connected to plus. Plug it to pin 8. The other pin should be connected to the ground (-) on the board. No resistor is needed here.
- The buzzer not be as big as the size shown in the image
2. Open your Arduino IDE and open:
File -> Examples -> 02. Digital -> toneMelody
3. Delete everything in the 'toneMelody' tab and copy-paste the code posted here below. (I made the melody to be the beginning of Beethoven's 5th Symphony, 1st movement.)
4. Upload the code, open your Serial Monitor, and realize that the buzzer plays whenever the laser is not shot at the Photo-Resistor
CODE:
#include "pitches.h"
// notes in the melody: int melody[] = { NOTE_G4, NOTE_G4, NOTE_G4, NOTE_DS4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_D4 };
// note durations: 4 = quarter note, 8 = eighth note, etc.: int noteDurations[] = { 6, 6, 6, 1, 5, 5, 5, 1 };
void setup() {
Serial.begin(9600);
pinMode(7, OUTPUT);
}
void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
int thresholdValue = 300; // you may change the threshold
if(sensorValue < thresholdValue){
digitalWrite(13,HIGH);
for (int thisNote = 0; thisNote < 8; thisNote++) {
int noteDuration = 1000 / noteDurations[thisNote];
tone(8, melody[thisNote], noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
noTone(8);
}
} else {
digitalWrite(13,LOW);
}
delay(10);
// delay in between reads for stability
}
Step 6: (Optional) Arduino Nano + Mini Breadboard
Mini-version
You can also make a Mini version of this Miniature with a small Arduino board and a small breadboard.
Arduino Nano's pins aren't placed when unpack them. Engineers normally solder the pins into the board. The image above is part of the soldering process for my Arduino Nano. (Third hand, Bronze Sponge, Solderer, Soldering Lead from CITRIS Invention Lab, UC Berkeley)
The circuit connections are the same, except that Arduino Nano has only up to 12 pins for Digital. Which means, you have to plug your LED pin to a pin other than 13, and change the number '13's on your code to the pin number you chose.
Here's an informative guideline for Arduino Nano board: https://www.arduino.cc/en/Guide/ArduinoNano
Also, remember that Mini Breadboards don' have the (+) and (-) sections along the sides. That is, Mini breadboards only have vertical connection. My tip is to connect the 5V and GND pins on the very edge lines, and connect other pins to it just like you did for the big breadboard.
Step 7: Test It Out!
Place your laser, place your board, fix their positions, and power them up!
Please watch my video above to see how your project should work like.
Congratulations! You're done!
I could upload another Instructable about how to alert your SmartPhone whenever the Laser Perimeter's alarm goes off! If you would like that, please comment below.
Also, if you have any questions or need additional information, please comment below.
Vince J. Han
UC Berkeley M.E.T.