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

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 Check – Digital 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.

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.

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.

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

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 an Arduino board with code and  circuit Connection

Motion detection with alarm alert and LED Indication Circuit Diagram
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 

Also Check – Connecting Two MPU6050 Sensors to Arduino with code | Controlling Two MPU6050 3-axis Accelerometer and Gyro Sensors to Arduino with Code

Digital Distance Measuring Device using Ultrasonic sensor and Arduino Board with code

Connecting Multiple Moisture sensor to Arduino Board with Code | Soil moisture sensor with Arduino with code

Testing Multiple PIR Motion Sensors Using Arduino with Code

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

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
  }
}

Any Questions related to this topic please feel free to ask me on my other social media accounts.

Instagram

Facebook

YouTube

Thank You!

Happy Learning!

Scroll to Top