CSC551B_CIA2_Test_Report
CSC551B_CIA2_Test_Report
CIA-2
Reg no: 2240205
Objectives
To create a home security system which includes:
1. A temperature sensor which reads data from the sensor, controls multiple leds,
based on the temperature range and displays the temperature value in a serial
monitor.
2. When motion is detected within a specified range, make the servo rotate, an led
should light up and a buzzer should sound an alert
3. If the ultrasonic sensor detects an object closer than 20cm print an error
message in the serial monitor
Hardware Requirements
For Quesiton 1:
Temperature Sensor: To measure temperature values.
Microcontroller: To process sensor data, control LEDs, and communicate
with the serial monitor.
LEDs: Multiple LEDs for indicating different temperature ranges.
Resistors: To limit current to the LEDs.
Serial Monitor: To display temperature values.
For Question 2:
Motion Sensor: To detect motion within a specified range.
Servo Motor: To rotate based on motion detection.
LED: To indicate motion detection.
Buzzer: To produce an alert sound.
Microcontroller: To control the servo, LED, and buzzer based on motion
sensor input.
For Question 3:
Ultrasonic Sensor: To measure distance to objects.
Microcontroller: To process sensor data and display error messages.
Serial Monitor: To display error messages.
Circuit
Code
#include <Servo.h>
Servo myServo;
int sensorState = 0;
float temperature = 0.0;
void setup() {
pinMode(PIR_PIN, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(LED_PIN_8, OUTPUT);
pinMode(LED_PIN_10, OUTPUT);
pinMode(LED_PIN_13, OUTPUT);
pinMode(LED_PIN_12, OUTPUT);
pinMode(LED_PIN_11, OUTPUT);
pinMode(TRIGGER_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
myServo.attach(9);
myServo.write(0);
Serial.begin(9600);
}
long measureDistance() {
digitalWrite(TRIGGER_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIGGER_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIGGER_PIN, LOW);
long duration = pulseIn(ECHO_PIN, HIGH);
long distance = (duration / 2) / 29.1; // Convert to centimeters
return distance;
}
void loop() {
sensorState = digitalRead(PIR_PIN);
long distance = measureDistance();
temperature = analogRead(TEMP_SENSOR_PIN) * 0.48828125; // Convert the
analog value to temperature in Celsius