// Vivint BeyondLock System
// Author: Fredy Antonio Almeyda Alania
// Student Code: u20201b033
// Description: IoT project for access control and environment monitoring.
// Partial Exam 2
// Date: June 14, 2024
#include "DoorControl.h"
#include "MotionSensor.h"
#include "DHTSensor.h"
#include "LCDDisplay.h"
#include "LEDControl.h"
// Pin definitions
#define POT_PIN A0
#define LED_PIN1 2
#define LED_PIN2 6
#define PIR_PIN 4
#define DHT_PIN 7
#define SERVO_PIN 9
// Class instances
MotionSensor motionSensor(PIR_PIN);
DHTSensor dhtSensor(DHT_PIN, DHT11);
LCDDisplay lcdDisplay(0x27, 20, 4);
DoorControl doorControl(SERVO_PIN);
LEDControl led1(LED_PIN1); // LED for the door
LEDControl led2(LED_PIN2); // LED for the PIR sensor
void setup() {
// Serial console initialization
Serial.begin(9600);
Serial.println("Vivint BeyondLock System Initialized");
Serial.println("Developed by: Fredy Antonio Almeyda Alania");
Serial.println("Student Code: u20201b033");
// LCD display initialization
lcdDisplay.init();
}
void loop() {
// Read potentiometer value to simulate distance
int potValue = analogRead(POT_PIN);
double distance = map(potValue, 0, 1023, 0, 400); // Map 0-1023 to 0-400 cm
Serial.print("Measured distance: ");
Serial.println(distance);
// Door control based on measured distance
if (distance < 200) {
led1.turnOn();
Serial.println("Opening the door");
doorControl.openDoor();
} else {
led1.turnOff();
Serial.println("Closing the door");
doorControl.closeDoor();
}
// Motion detection with PIR sensor
if (motionSensor.detectMotion()) {
led2.turnOn();
Serial.println("Motion detected! Turning on the light");
} else {
led2.turnOff();
Serial.println("No motion detected! Turning off the light");
}
// Temperature and humidity measurement with DHT sensor
float temperature = dhtSensor.getTemperature();
float humidity = dhtSensor.getHumidity();
Serial.print("Temperature: ");
Serial.println(temperature);
Serial.print("Humidity: ");
Serial.println(humidity);
lcdDisplay.update(temperature, humidity);
delay(1000); // Delay for stability
}