In this Arduino electronics tutorial it is illustrated how to make laser based alarm system using Laser diode and LDR(Light Dependent Resistor). This can be useful to make security system for home usage or industrial application. It may also be useful in counting mechanism and control application. Arduino code for laser diode with LDR for alarm system is provided. Schematic wiring diagram of interfacing Arduino with LDR and buzzer, laser driver circuit with video demonstration are provided.
How it works
During normal operation, the laser beam from the laser diode hits the LDR. But when the laser beam is obstructed, LDR detects this because then it's resistance increases. This increase in resistance and hence increased voltage is detected by the Arduino ADC. When the increased voltage becomes higher than some per-defined voltage at normal condition, alarm is sounded using a buzzer by the Arduino. Hence whenever intruder crosses the laser beam line, alarm is sounded.
Interfacing & Schematic wiring drawing of interfacing Arduino, LDR, buzzer and laser driver
Video demonstration of laser based alarm system
Arduino Code for Laser Diode LDR based alarm system
//Program for laserdiode based Alarm using LDR, Arduino, Buzzer
//Source: https://ee-diary.com
const int ldrPin = A3;
const int buzzerPin = 4;
void setup(){
Serial.begin(9600); //set Serial output baud rate
pinMode(buzzerPin, OUTPUT);
//For output format
Serial.println("\nADC value, Voltage(V):");
Serial.println("--------------------------------------------------\n");
}
void loop() {
int ldrValue = analogRead(ldrPin);
float ldrVoltage = (ldrValue/1023.0)*5;
if(ldrValue <= 350){
digitalWrite(buzzerPin, HIGH);
}
else{
digitalWrite(buzzerPin, LOW);
}
Serial.println(String(ldrValue)+","+String(ldrVoltage)+"V");
delay(100); //100ms delayto prevent any duplicates
}
Hi ee-diary,
Thank you very much for the educative valuable information on your posts. I am working on a similar project but using for different application.
I will like to know how to integrate a regression equation to the output of LDR for example, y=(8*10^-5)x^2+0.1873x+46.131.
In this, I was LDR output as the variable (x) in the equation.
Your assistance is highly appreciated.
Thank you
hmm, i don't understand clearly what is the input and what is the output? here laser could be input and LDR detection could be output, is that what you mean?
ee-diary, thanks for your response. LDR is the output and i call it (y) in the equation. The input is the laser and I call it (x). I need that LDR output to be integrated with the equation given above.
in the code, the ldrValue(or ldrVoltage) is y for your equation,there is no laser input(x). you can make your buzzer output as x by feeding it back to the laser input, however, for this you need to disassemble laser electronics.
Thanks for your response bro, I get your point. I need the ldr voltage to be incorporated with this equation:- y=(8*10^-5)x^2+0.1873x+46.131 so that I get a new output value which have been modified by that equation.
That is why I was referring to the ldr voltage as (x) which will give a new output.
I am working on a project using same principles of ldr voltage but that output have to be modified by the equation.
My request is an Arduino code to perform the modification of ldr voltage with the equation.
Your help is highly appreciated