Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
fanesahadi
Published © GPL3+

Laser Security System at Home - Basic

Simple home security project using laser light and Arduino nano.

BeginnerFull instructions provided4,766
Laser Security System at Home - Basic

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Solderless Breadboard Full Size
Solderless Breadboard Full Size
×1
Laser Diode, 2 Pins
Laser Diode, 2 Pins
×1
LDR, 5 Mohm
LDR, 5 Mohm
×1
Signal Relay, 5 VDC
Signal Relay, 5 VDC
Relay 5 pin
×1
Buzzer
Buzzer
×1
LED (generic)
LED (generic)
Red & Green
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Resistor 330 ohm
Resistor 330 ohm
×2

Story

Read more

Schematics

laser-security-system_schem_RaqHUIZH68.jpg

Code

Source Code

C/C++
int relayPin = 2;
int ldrPin = A2;
int laserPin = 5;
int buzerPin = 8;

void setup(){
  Serial.begin(9600);
  pinMode(relayPin, OUTPUT);
  pinMode(ldrPin, INPUT);
  pinMode(laserPin, OUTPUT);
  pinMode(buzerPin, OUTPUT);
  security_begin();
}

void loop() 
{
  digitalWrite(laserPin, 1);
  int ldrValue = analogRead(ldrPin) / 4;
  Serial.println(ldrValue);
  if(ldrValue < 200)
  {
    security_warning();
    setup();
  }else{
    digitalWrite(relayPin, 0);
  }
}

void security_begin()
{
  for(int i = 0;i < 2; i++)
    {
      analogWrite(buzerPin, 255);
      digitalWrite(laserPin, 1);
      delay(50);
      analogWrite(buzerPin, 0);
      digitalWrite(laserPin, 0);
      delay(50);
    }
}

void security_warning()
{
    digitalWrite(relayPin, 1);
    for(int i = 0;i < 5; i++)
    {
      digitalWrite(relayPin, 1);
      digitalWrite(buzerPin, 1);
      digitalWrite(laserPin, 1);
      delay(500);
      digitalWrite(relayPin, 0);
      digitalWrite(buzerPin, 0);
      digitalWrite(laserPin, 0);
      delay(500);
    }
    digitalWrite(laserPin, 1);
    int ldrValue = analogRead(ldrPin) / 4;
    if(ldrValue < 200) security_warning();
}

Credits

fanesahadi
0 projects • 0 followers

Comments