Vidit ShahUtkarsh Tiwari
Published © GPL3+

Buzzer Alarm System With Help Of Arduino

This project will guide you to set up an alarm system using a motion detector.

BeginnerProtip1 hour120,218
Buzzer Alarm System With Help Of Arduino

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Buzzer
Buzzer
×1
Adjustable IR Pyroelectric Infrared PIR Motion Sensor Detector Module HC-SR501
×1
LED (generic)
LED (generic)
×1
Resistor 330 ohm
Resistor 330 ohm
×1
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×1
Resistor 1k ohm
Resistor 1k ohm
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
MALE TO MALE and MALE TO FEMALE
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematic for the project

Code

Code for project

Arduino
// Declaring Pins
const int buzzerPin = 5;
const int ledPin = 6;
const int motionPin = 7;
const int buttonPin = 12;

// Setting Buzzer mode to False
boolean buzzer_mode = false;

// For LED
int ledState = LOW;
long previousMillis = 0; 
long interval = 100;  // Interval at which LED blinks

void setup()
{
  //The Following are our output
  pinMode(ledPin,OUTPUT);
  pinMode(buzzerPin,OUTPUT);

  //Button is our Input
  pinMode(buttonPin, INPUT);
  
  // Wait before starting the alarm
  delay(5000);
}

void loop()
{
  // To chech whether the motion is detected or not
  if (digitalRead(motionPin)) {
    buzzer_mode = true; 
  }

  // If alarm mode is on,blink our LED
  if (buzzer_mode){
    unsigned long currentMillis = millis();
    if(currentMillis - previousMillis > interval) {
      previousMillis = currentMillis;   
      if (ledState == LOW)
        ledState = HIGH;
      else
        ledState = LOW;
    // Switch the LED
    digitalWrite(ledPin, ledState);
    }
    tone(buzzerPin,1000);
  }

  // If alarm is off
  if (buzzer_mode == false) {
  
    // No tone & LED off
    noTone(buzzerPin);  
    digitalWrite(ledPin, LOW);
  }

  // If our button is pressed Switch off ringing and Setup
  int button_state = digitalRead(buttonPin);
  if (button_state) {buzzer_mode = false;}
}

Credits

Vidit Shah

Vidit Shah

10 projects • 39 followers
Programmer
Utkarsh Tiwari

Utkarsh Tiwari

10 projects • 40 followers
Trying to FIND myself! :P Interested in DIY's and coding!

Comments