Lab Assignment 4 of iot
Lab Assignment 4 of iot
SESSION- January-May(2024)
Lab assignment 4 of IOT
Submitted to Submitted by
Dr. Devesh Kumar Lal Sahil Karkhur
0901CD211046
Develop an intrusion detection system through motion
sensors.
.
Components Needed:
Arduino board (e.g., Arduino Uno)
PIR motion sensor module
Buzzer or LED for alarm indication
Breadboard
Jumper wires
Circuit Connection:
Connect the VCC pin of the PIR sensor to the 5V pin of the Arduino.
Connect the GND pin of the PIR sensor to the GND pin of the Arduino.
Connect the OUT pin of the PIR sensor to a digital pin (e.g., pin 2) of the Arduino.
Connect the positive terminal of the buzzer or LED to a digital pin (e.g., pin 3) of the Arduino.
Connect the negative terminal of the buzzer or LED to the GND pin of the Arduino.
// Define the pins
const int pirPin = 2; // PIR sensor output pin
const int alarmPin = 3; // Buzzer or LED pin
void setup() {
pinMode(pirPin, INPUT);
pinMode(alarmPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
.
int pirState = digitalRead(pirPin); // Read PIR sensor
state
if (pirState == HIGH) {
// Motion detected
Serial.println("Intrusion detected!");
digitalWrite(alarmPin, HIGH); // Turn on the alarm
delay(1000); // Delay for 1 second
digitalWrite(alarmPin, LOW); // Turn off the alarm
}
Explanation:
In the setup() function, we set the PIR sensor pin as an input and the alarm pin as an output.
In the loop() function, we continuously monitor the state of the PIR sensor using digitalRead(pirPin).
If motion is detected (i.e., the PIR sensor output is HIGH), we print a message to the serial monitor
and trigger the alarm by setting the alarm pin HIGH for a brief period.
We include a small delay after triggering the alarm to prevent rapid consecutive triggers due to
continuous motion detection.
Deployment:
When motion is detected by the PIR sensor, the buzzer or LED will be activated briefly, indicating an
intrusion.
You can adjust the sensitivity and detection range of the motion sensor if needed.
Monitor the serial output for intrusion detection messages.