All programs
IoT - Lab Manual (Simplified) · BCS7O3 IoT (Arduino · C++)

Problem Statement Program 3

Develop a program to deploy an Intrusion Detection System using Ultrasonic and Sound Sensors

To develop an Intrusion Detection System using an Arduino Uno, HC-SR04 Ultrasonic Sensor, and Buzzer. The system detects the presence of an object within a specified distance and generates an alarm using the buzzer. This experiment helps in understanding distance measurement, obstacle detection, and security system implementation using Arduino.

Components Required Hardware

Arduino Uno Board – 1
HC-SR04 Ultrasonic Sensor – 1
Buzzer – 1
Breadboard – 1
Jumper Wires – As Required
USB Cable – 1
Arduino IDE Software

Procedure Step by step

Step 1:

Take an Arduino Uno board, HC-SR04 Ultrasonic Sensor, buzzer, breadboard, jumper wires, and USB cable.

Step 2:

Connect the VCC pin of the HC-SR04 sensor to the 5V pin of the Arduino Uno.

Step 3:

Connect the GND pin of the HC-SR04 sensor to the GND pin of the Arduino Uno.

Step 4:

Connect the TRIG pin of the ultrasonic sensor to Digital Pin 2 of the Arduino Uno.

Step 5:

Connect the ECHO pin of the ultrasonic sensor to Digital Pin 3 of the Arduino Uno.

Step 6:

Connect the positive (+) terminal of the buzzer to Digital Pin 10 of the Arduino Uno.

Step 7:

Connect the negative (-) terminal of the buzzer to the GND pin of the Arduino Uno.

Step 8:

Connect the Arduino Uno to the computer using a USB cable.

Step 9:

Open the Arduino IDE.

Step 10:

Select Tools → Board → Arduino Uno.

Step 11:

Select the correct COM Port.

Step 12:

Copy and paste the Arduino program into the Arduino IDE.

Step 13:

Compile and upload the program.

Step 14:

Open the Serial Monitor and set the baud rate to 9600.

Step 15:

Move an object in front of the ultrasonic sensor.

Step 16:

When the object comes within 10 cm, the buzzer sounds and the Serial Monitor displays "Door Open" along with the measured distance.

Step 17:

When no object is detected within 10 cm, the buzzer turns OFF and the Serial Monitor displays "Door Closed".

Circuit Connection Wiring

HC-SR04 VCC → Arduino 5V
HC-SR04 GND → Arduino GND
HC-SR04 TRIG → Arduino Digital Pin 2
HC-SR04 ECHO → Arduino Digital Pin 3
Buzzer Positive (+) → Arduino Digital Pin 10
Buzzer Negative (-) → Arduino GND

Circuit Diagram 1 image

Download the clean, watermark-free circuit diagram — ₹1.00

Arduino Code (C++) Source

program3.cpp
int trigger_pin = 2;
int echo_pin = 3;
int buzzer_pin = 10;

int time;
int distance;

void setup()
{
  Serial.begin(9600);

  pinMode(trigger_pin, OUTPUT);
  pinMode(echo_pin, INPUT);
  pinMode(buzzer_pin, OUTPUT);
}

void loop()
{
  digitalWrite(trigger_pin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigger_pin, LOW);

  time = pulseIn(echo_pin, HIGH);

  distance = (time * 0.034) / 2;

  if (distance <= 10)
  {
    Serial.print("Door Open");
    Serial.print(" Distance=");
    Serial.println(distance);

    digitalWrite(buzzer_pin, HIGH);
  }
  else
  {
    Serial.print("Door Closed");
    Serial.print(" Distance=");
    Serial.println(distance);

    digitalWrite(buzzer_pin, LOW);
  }

  delay(500);
}
Protected content · © VTU Developer · Unauthorised distribution is prohibited