Lab set Program-3
Develop a program to deploy an intrusion detection system using Ultrasonic sensor.
Objective
To design and implement an intrusion detection system using an Arduino board, ultrasonic sensor, buzzer, and LED. The system will detect motion/entry within a restricted distance and trigger an alarm.
Learning Outcomes
-
Understand how to interface an ultrasonic sensor (HC-SR04) with Arduino.
-
Learn to measure distance using sensor readings.
-
Implement a security alarm system using buzzer and LED.
-
Write Arduino code to control actuators (buzzer/LED) based on sensor input.
Components (from Tinkercad palette)
-
Arduino Uno board
-
Ultrasonic Sensor (HC-SR04)
-
Buzzer
-
LED (Red)
-
Resistor (220Ω for LED)
-
Breadboard
-
Jumper wires
Circuit Wiring (exact)
-
Ultrasonic Sensor
-
VCC → Arduino 5V
-
GND → Arduino GND
-
TRIG → Arduino pin 9
-
ECHO → Arduino pin 10
-
-
Buzzer
-
Positive → Arduino pin 7
-
Negative → GND
-
-
LED
-
Anode (+) → 220Ω resistor → Arduino pin 6
-
Cathode (–) → GND
Arduino Sketch
// Lab Program-3: Intrusion Detection System
const int trigPin = 9;
const int echoPin = 10;
const int buzzerPin = 7;
const int ledPin = 6;
long duration;
int distance;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
// Trigger ultrasonic pulse
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Measure distance
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2;
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
// Intrusion condition
if (distance < 20) { // less than 20 cm = intruder
digitalWrite(buzzerPin, HIGH);
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(buzzerPin, LOW);
digitalWrite(ledPin, LOW);
}
delay(200);
}
How it Works
-
The ultrasonic sensor emits sound waves and measures the time taken for the echo to return.
-
The Arduino calculates the distance from the object.
-
If the distance is less than 20 cm, it assumes an intruder is present.
-
The buzzer and LED turn ON as an alarm signal.
-
If no intruder is detected, the buzzer and LED remain OFF.
Common Mistakes & Quick Fixes
-
Wrong TRIG/ECHO wiring: Ensure TRIG → D9 and ECHO → D10.
-
Buzzer not working: Connect polarity correctly, use digital pin.
-
LED dim: Always connect resistor to prevent damage.
-
Serial monitor not showing distance: Check
Serial.begin(9600)and correct COM port.
Viva / Check-Your-Understanding
-
What is the purpose of the TRIG and ECHO pins in ultrasonic sensor?
-
Why do we divide the time by 2 when calculating distance?
-
What is the speed of sound assumed in the calculation?
-
Can this system work in complete darkness? Why?
-
What modifications are needed to extend this system to real-world intrusion detection?
Extensions (Mini-Tasks)
-
Change intrusion distance threshold from 20 cm to 10 cm.
-
Add a green LED to indicate “safe zone” when no intruder.
-
Replace buzzer with a small lamp or DC motor to simulate real-world load.
-
Integrate with a GSM module (real hardware) to send SMS alerts on intrusion.
Lab Record (Suggested Headings)
-
Title
-
Objective
-
Components Required
-
Circuit Diagram
-
Arduino Program
-
Output
Thinkercad Link:
https://www.tinkercad.com/things/eCeNmHQqw0O-labset-prog-3

Comments
Post a Comment