LASER Tripwire Alarm with Arduino
Hello, and welcome to another tutorial sponsored by Seeed Studio, the other one was a Speech recognition module, many thanks for them, today we have a Light Sensor module, that you can get here: Buy module here from Seeed Studio.
Seeed is the IoT hardware enabler providing services over 10 years that empower makers to realize their projects and products. Seeed offers a wide array of hardware platforms and sensor modules ready to be integrated with existing IoT platforms and one-stop PCB manufacturing and Prototype PCB Assembly. Seeed Studio provides a wide selection of electronic parts including Arduino, Raspberry Pi and many different development board platforms. Especially the Grove Sytsem help engineers and makers to avoid jumper wires problems. Seeed Studio has developed more than 280 Grove modules covering a wide range of applications that can fulfill a variety of needs.
Check the module wiki here.
Hardware and parts
In addition to the light sensor, we’re adding these following parts for our project:
Wiring
The module is very easy to interface with the Arduino board, the module has a 4-pins grove connector, GND, 5V, and an analog output, the other pin is not connected, and as you thought, the output signal changes depending on the light detected.
Code
This is the easiest code to test the module, we just read the analog value and display it on the Serial Monitor.
1 2 3 4 5 6 7 8 9 10 11 |
#define Rec 0 void setup() { Serial.begin(9600); } void loop() { Serial.println(analogRead(Rec)); } |
Test
Sensor exposed to light:
Sensor covered
And the value changes depending on the lighting
Tripwire Alarm v1
This project is based on the module, LASER module, a Buzzer, and a push button, the idea is very simple, the LASER is constantly projecting light to the module sensor, when a person or something passes through the light beam, the sensor will not detect the light anymore (When the light stops, the LDR will increase resistance, which means less current will pass, and we’ll get a voltage drop).
Example: At indoor light the sensor will give a value of around “750” when using the “analogRead” function while using Arduino it’s around “3.66V” (1023 for 5V), but when you cover the sensor it will show a value around “10-15” that stands for “40mV”. So it’s better to cover or put the sensor in a case where only the LASER beams can reach.
Once the LASER beams are cut, the alarm will go off and will not stop until the push button is pressed even though the module detects the LASER again.
Wiring
You can power the laser as I do or just wire it with 5v to be constantly powered on.
Code
You can download the code here, or check below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
/* This code is for a LASER Tripwire Alarm based on a light sensor, LASER module and a push button * The LASER is constantly sending beams to the sensor, when someone passes the light is not detected * and the alarm goes off, and will not stop until you press the button * Refer to http://www.surtrtech.com for more details */ #define Rec 0 //Light sensor output #define Laser 2 //Laser module #define Button 3 //Push button input bool detection; void setup() { pinMode(Laser, OUTPUT); digitalWrite(Laser, HIGH); //Turning on the laser delay(2000); } void loop() { short Detect = analogRead(Rec); //Constanly reading the module value bool Button_state = digitalRead(Button); //And the button value (1-0) if(Detect < 500) //The Max value is 760, if someone passes it goes below that (every value lower than 700 can do the work) detection = true; //The detection is triggered if(detection==true) { tone(13,2000); //Alarm sequence will go on as long as the detection is true delay(50); //This alarm has two sounds 2kHz nd 1Khz delayed by 50ms tone(13,1000); delay(50); } if(Button_state == HIGH) //If the button is pressed the buzzer is turned off and the detection too { detection = false; noTone(13); } } |
Tripwire Alarm v2
The v2 is pretty much like the v1 just instead of stopping the alarm with a simple push button, now it requires a passcode entered by the keypad to stop it, otherwise it won’t.
if you’re not familiar with keypad, check this tutorial.
The passcode is stored in an array, I chose 4 digits code, you can make it longer or shorter, just modify the array size, and add or remove values.
1 |
short code[4]={'1','3','6','6'}; |
To turn the alarm off, you should press ‘*’ on the keypad, then enter the numbers 1,3,6,6, the code will fix the buzzer in a single frequency (disturbing) sound until you enter 4 digits, if they are correct the alarm will stop, otherwise it will go off again.
1 2 3 4 5 6 7 8 9 10 |
void Getpass(){ tone(13,2000); for(short i=0 ; i<4 ; i++) { char keypressed = myKeypad.waitForKey(); if (keypressed==code[i]) a++; } } |
Every time you enter a correct digit “a” value increases, if it’s == 4, the code is considered correct, otherwise the number will never be equal to 4.
1 2 3 4 5 |
if(a==4){ noTone(13); a=0; detection=false; } |
Wiring
I used a 4×4 keypad matrix, you can use a 4×3 as we’re not using the last column.
Code
You can download the second code here, or check below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
/* This code is for a LASER Tripwire Alarm based on a light sensor, LASER module and keypad * The LASER is constantly sending beams to the sensor, when someone passes the light is not detected * and the alarm goes off, and will not stop until you press '*' and enter the correct code * Refer to http://www.surtrtech.com for more details */ #include <Keypad.h> #define Rec 0 #define Laser 2 #define Button 3 bool detection; short a=0; short code[4]={'1','3','6','6'}; //pass code stored in a array you can make it longer or shorter //by changing '4' and add/remove values const byte numRows= 4; //Rows and columns of the keypad const byte numCols= 4; char keymap[numRows][numCols]= //Keypad map { {'1', '2', '3', 'A'}, {'4', '5', '6', 'B'}, {'7', '8', '9', 'C'}, {'*', '0', '#', 'D'} }; byte rowPins[numRows] = {11,10,9,8}; //Keypad 8 pins byte colPins[numCols]= {7,6,5,4}; Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols); void setup() { pinMode(Laser, OUTPUT); digitalWrite(Laser, HIGH); delay(2000); } void loop() { short Detect = analogRead(Rec); //Constantly reading the sensor value, to detect if someone passes if(Detect < 500) detection = true; if(detection==true) { //Alarm sequence and constantly waiting for '*' to be pressed tone(13,1000); delay(50); tone(13,200); delay(50); char keypressed = myKeypad.getKey(); if (keypressed == '*') //if '*' is pressed go to Getpass function Getpass(); } if(a==4){ //if a==4 means the code is correct, the alarm is off noTone(13); a=0; //setting the a to 0, otherwise the alarm will turn off automatically detection=false; } } void Getpass(){ //Getting passcode function tone(13,2000); //Constant frequency sound while entring the code for(short i=0 ; i<4 ; i++) { char keypressed = myKeypad.waitForKey(); if (keypressed==code[i]) //If the sequence is correct the a increases (4) means all values are right a++; } } |
Tests
This short video shows tests for both versions (It’s loud!!)
Categories
Yassine View All
Automation and Electrical Engineer, Electronics amateur trying to share my little projects.
4 thoughts on “LASER Tripwire Alarm with Arduino” Leave a comment ›