SOTM
Published © CC BY-NC

Alert System with Photo Resistor, Buzzer and Laser (Concept)

Ever wondered on how to build a system to alert you of visitors, intruders or when an object is moved.

IntermediateProtip1 hour780
Alert System with Photo Resistor, Buzzer and Laser (Concept)

Things used in this project

Hardware components

Arduino Nano v3 compatible board
×1
Laser Transmitter Module - KY-008
×1
Passive Buzzer Module - KY-006
×1
Photo-resistor Module - KY-018
×1
Breadboard - 830 Tie Points
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematic for Light System

Code

Code for Alert System using Laser, Buzzer and Lightsensor

Arduino
//
// Photo Resistor Module KY-018 and Passive Buzzer Module KY-006 for Arduino
// 20 January 2020 
// Author: dante@serveronthemove.com.au
//
// Hardware:
//   Arduino
//   Photo Resistor Module KY-018
//   Passive Buzzer Module KY-006
//
//   Wiring:
//     KY-018      -> Arduino
//      S          -> A0
//      + (middle) -> VCC 3.3V or 5V
//      - (GND)    -> GND
//
//     KY-006      -> Arduino
//      S          -> D4
//      (middle)   -> NOT USED
//      - (GND)    -> GND
//
// Purpose:
//    Sound alert when photo resistor is no longer getting light.
//    The code supports to modes controlled by "TriggerModeOnce"
//    triggerModeOnce = true;  // will sound alert once light source is lost and will continue to sound even if light source is restorted (Intruder alert). To reset, push reset button
//    triggerModeOnce = false; // will sound alert only when light source is lost. When lught source is restored, sound stops (visitor entered shop)
//

// Hardware config
int photoModule  = A0;    // S Pin of Photo Resistor Module KY-021 on Arduino A0
int buzzerModule = 4;     // S Pin of Passive Buzzer Module KY-006 on Arduino D4

// Software config
boolean triggerModeOnce = true;  // will sound alert once light source is lost and will continue to sound even if light source is restorted (Intruder alert). To reset, push reset button
boolean photoTriggered = false;  // indicator if photoresistor lost light source
int triggerThreshold = 150;      // threshold for alert trigger. Anything beyond this value coming from Photoresistor will trigger alert

// setup PINs
void setup() {
  pinMode(photoModule, INPUT);
  pinMode(buzzerModule, OUTPUT);
  
}

void loop() {

  // sound alert if
  //   1) threshold is exceeded - or -
  //   2) triggerModeOnce is alert and has been triggered before
  if ((analogRead(photoModule) > triggerThreshold) || (photoTriggered && triggerModeOnce)) {
    photoTriggered = true; // mark trigger

    // reset buzzer
    digitalWrite(buzzerModule, HIGH);
    digitalWrite(buzzerModule, LOW);

    // sound alert with PWM
    for (int i = 0; i < 80; i++) {  // make a sound
      digitalWrite(buzzerModule, HIGH); // send high signal to buzzer 
      delay(1); // delay 1ms
      digitalWrite(buzzerModule, LOW); // send low signal to buzzer
      delay(1);
    }

    delay(50);

    for (int j = 0; j < 100; j++) { //make another sound
      digitalWrite(buzzerModule, HIGH);
      delay(2); // delay 2ms
      digitalWrite(buzzerModule, LOW);
      delay(2);
    }
    
    delay(100);

  } else {
    // make sure is down
    digitalWrite(buzzerModule, LOW);
  }
}

Credits

SOTM

SOTM

7 projects • 4 followers

Comments