You are on page 1of 4

Lab Report 04

Objective:

Make a circuit composed of infra-red sensor or ultra-sonic sensor for the presence of any intruder
in the area of concern. (Use of proximity)

Theory:

Components Required
 Breadboard
 Ultrasonic Sensor
 Buzzer
 Jumper Wires
Breadboard: Platform for prototyping and connecting various components.
Ultrasonic Sensor: Detects distance by emitting ultrasonic waves and measuring the
time taken for the waves to bounce back.
Buzzer: An audible indicator that activates when the sensor detects proximity.
Jumper Wires: Used for connections in the circuit.

Purpose:

The goal is to design a circuit using an ultrasonic sensor that can detect any intrusion or
presence of an object within a specific proximity range. When an object enters this range,
the sensor detects it and activates a buzzer as an alert mechanism.

Procedure:
 Initializes the ultrasonic sensor's trigger and echo pins along with the buzzer pin.
 Sends ultrasonic pulses and measures the time taken for the echo to return, calculating the
distance of an object.
 If an object is within a specified range (in this case, within 100 cm), it triggers the buzzer
to activate.
 Ensure the ultrasonic sensor is wired correctly to the designated pins (Trig pin to pin 9,
Echo pin to pin 10), and the buzzer is connected to pin 7 on the Arduino.

1|Page
 Upload this code to the Arduino and observe how the buzzer activates when an object is
detected within the defined proximity range of the ultrasonic sensor. Adjust the distance
threshold in the code to fit your specific proximity requirements.

Arduino Code:
#define trigPin 2
#define echoPin 3
#define LEDlampRed 4
#define LEDlampYellow 5
#define LEDlampGreen 6
#define soundbuzzer 7
int sound = 500
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(LEDlampRed, OUTPUT);
pinMode(LEDlampYellow, OUTPUT);
pinMode(LEDlampGreen, OUTPUT);
pinMode(soundbuzzer, OUTPUT);
}
void loop() {
long durationindigit, distanceincm;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
durationindigit = pulseIn(echoPin, HIGH);
distanceincm = (durationindigit/5) / 29.1;
2|Page
if (distanceincm < 50) {
digitalWrite(LEDlampGreen, HIGH);
}
else {
digitalWrite(LEDlampGreen, LOW);
}

if (distance < 20) {


digitalWrite(LEDlampYellow, HIGH);
}
else {
digitalWrite(LEDlampYellow,LOW);
}
if (distance < 5) {
digitalWrite(LEDlampRed, HIGH);
sound = 1000;
}
else {
digitalWrite(LEDlampRed,LOW);
}

if (distanceincm > 5 || distanceinsm <= 0){


Serial.println("Outside the permissible range of distances");
noTone(soundbuzzer);
}
else {
Serial.print(distance);

3|Page
Serial.println(" cm");
tone(buzzer, sound);
}

delay(300);
}

Result:

Conclusion:
Upon successful setup and testing:
 When an object enters the proximity range of the ultrasonic sensor, the buzzer will
activate, emitting an audible alert as an indication of intruder presence.
 The circuit will accurately detect objects within the predefined range and trigger the
buzzer accordingly.
This experiment showcases the use of ultrasonic sensors as proximity detectors in security
systems, demonstrating their ability to detect intruders or objects within a specific range and
activate an alert mechanism, represented here by the buzzer.

4|Page

You might also like