Motion detection with alarm alert using Arduino board with code and circuit Connection

 

Motion detection with alarm alert using Arduino board with code and  circuit Connection

Motion detection with alarm alert using Arduino board with code and  circuit Connection

Material Required


  1. Arduino board (Uno, Nano, or Mega)
  2. Passive Infrared PIR Motion Sensor
  3. Buzzer
  4. Jumper wires
  5. 5v Power supply with USB cable 


Steps to connect PIR motion Sensor and Buzzer to Arduino Board


  1. Connect the VCC pin of the PIR motion Sensor to the 5V pin of the Arduino board.
  2. Connect the GND pin of the PIR motion Sensor to the GND pin of the Arduino board.
  3. Connect the OUT pin of the PIR motion Sensor to any digital input pin of the Arduino board here in circuit connected as pin 3.
  4. Connect the positive (+) pin of the buzzer to any digital output pin of the Arduino board here in circuit connected as pin 4.
  5. Connect the negative (-) pin of the buzzer to the GND pin of the Arduino board.


Also CheckDigital Distance Measuring Device using Ultrasonic sensor and Arduino Board with code

Code Explanation

1) The code define two integer variables to store the input and output pin numbers of the PIR motion sensor and the buzzer.

1
2
int pirPin = 2;
int buzzerPin = 3;

2) In the setup() function we used to initialize the input and output pins of the Arduino board for the sensor and buzzer.

The PIR Pin is set as an input pin to read the digital signal from the PIR motion sensor, while the buzzerPin is set as an output pin to send the digital signal to the buzzer.

1
2
3
4
void setup() {
  pinMode(pirPin, INPUT);
  pinMode(buzzerPin, OUTPUT);
}


Inside this loop() function, the digitalRead() function is used to read the current value of the PIR motion sensor Pin input. Here there are two cases, If the value is HIGH, it means that motion has been detected by the PIR motion sensor.

1st case, the digitalWrite() function is used to send a HIGH signal to the buzzerPin output, which turns on the buzzer. Then, there is a delay() of 500 milliseconds which is 0.5 seconds to control the duration of the buzzer beep. 

2nd case the digitalWrite() function is called again to send a LOW signal to the buzzerPin output, which turns off the buzzer.
This process is repeated indefinitely in the loop() function as long as the Arduino board is powered on.


1
2
3
4
5
6
7
8
void loop() {
  int pirValue = digitalRead(pirPin);
  if (pirValue == HIGH) {
    digitalWrite(buzzerPin, HIGH);
    delay(500);
    digitalWrite(buzzerPin, LOW);
  }
}



Open the Arduino IDE on your computer, create a new sketch and Upload the below code on Arduion board .

Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
int pirPin = 2;  // PIR motion sensor input pin
int buzzerPin = 3;  // Buzzer output pin

void setup() {
  pinMode(pirPin, INPUT);  // Set PIR motion sensor pin as input
  pinMode(buzzerPin, OUTPUT);  // Set buzzer pin as output
}

void loop() {
  int pirValue = digitalRead(pirPin);  // Read PIR motion sensor value

  if (pirValue == HIGH) {  // If motion is detected
    digitalWrite(buzzerPin, HIGH);  // Turn on buzzer
    delay(500);  // Wait for 0.5 seconds
    digitalWrite(buzzerPin, LOW);  // Turn off buzzer
  }
}


Motion detection with alarm alert and LED Indication using Arduino board with code and  circuit Connection

Motion detection with alarm alert and LED Indication Circuit Diagram


Material Required


  1. Arduino board (Uno, Nano, or Mega)
  2. Passive Infrared PIR Motion Sensor
  3. Buzzer
  4. Jumper wires
  5. Led
  6. 220 ohms resistor
  7. 5v Power supply with USB cable 


Steps to Connect PIR motion sensor, buzzer and Led with Arduino Board


  1. Connect the VCC pin of the PIR Motion sensor to the 5V pin of the Arduino board.
  2. Connect the GND pin of the PIR Motion sensor to the GND pin of the Arduino board.
  3. Connect the OUT pin of the PIR Motion sensor to any digital input pin of the Arduino board here I used pin 3.
  4. Connect the positive (+) pin of the buzzer to any digital output pin of the Arduino board here I used pin 4.
  5. Connect the negative (-) pin of the buzzer to the GND pin of the Arduino board.
  6. Connect the anode (+) pin of the LED to any digital output pin of the Arduino board here I used pin 13 in series with the 220-ohm resistor.
  7. Connect the cathode (-) pin of the LED to the GND pin of the Arduino board.


Code


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
int pirPin = 2;  // PIR motion sensor input pin
int buzzerPin = 3;  // Buzzer output pin
int ledPin = 4;  // LED output pin

void setup() {
  pinMode(pirPin, INPUT);  // Set PIR motion sensor pin as input
  pinMode(buzzerPin, OUTPUT);  // Set buzzer pin as output
  pinMode(ledPin, OUTPUT);  // Set LED pin as output
}

void loop() {
  int pirValue = digitalRead(pirPin);  // Read PIR motion sensor value

  if (pirValue == HIGH) {  // If motion is detected
    digitalWrite(buzzerPin, HIGH);  // Turn on buzzer
    digitalWrite(ledPin, HIGH);  // Turn on LED
    delay(500);  // Wait for 0.5 seconds
    digitalWrite(buzzerPin, LOW);  // Turn off buzzer
    digitalWrite(ledPin, LOW);  // Turn off LED
  }
}


Thank You!
Have A Great Day!