0% found this document useful (0 votes)
15 views

CSC551B_CIA2_Test_Report

Uploaded by

fractaldiffusion
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

CSC551B_CIA2_Test_Report

Uploaded by

fractaldiffusion
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

CSC551B-INTERNET OF THINGS LAB

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>

// Define constants and variables for the ultrasonic sensor


#define TRIGGER_PIN 7
#define ECHO_PIN 6
#define MAX_DISTANCE 200 // Maximum distance we want to measure (in
centimeters)

// Define pin for the PIR sensor and temperature sensor


#define PIR_PIN 2
#define TEMP_SENSOR_PIN A3

// Define LED pins


#define LED_PIN_8 8
#define LED_PIN_10 10
#define LED_PIN_13 13
#define LED_PIN_12 12
#define LED_PIN_11 11

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

// PIR sensor functionality


if (sensorState == HIGH) {
if (distance >= 50 && distance <= 100) {
digitalWrite(LED_PIN_10, HIGH);
myServo.write(90);
tone(8, 1000);
Serial.println("Motion detected within 30-50 cm!");
}
} else {
digitalWrite(LED_PIN_10, LOW);
noTone(8);
myServo.write(0);
}

// Ultrasonic sensor functionality


if (distance > 0 && distance < 20) {
digitalWrite(LED_PIN_8, HIGH);
Serial.println("Object detected within 20 cm!");
} else {
digitalWrite(LED_PIN_8, LOW);
}

// Temperature sensor functionality


if (temperature < 20) {
digitalWrite(LED_PIN_13, HIGH);
digitalWrite(LED_PIN_12, LOW);
digitalWrite(LED_PIN_11, LOW);
} else if (temperature >= 20 && temperature < 50) {
digitalWrite(LED_PIN_13, LOW);
digitalWrite(LED_PIN_12, HIGH);
digitalWrite(LED_PIN_11, LOW);
} else if (temperature >= 50) {
digitalWrite(LED_PIN_13, LOW);
digitalWrite(LED_PIN_12, LOW);
digitalWrite(LED_PIN_11, HIGH);
}

// Delay to avoid rapid triggering


delay(1000);
}
Output

You might also like