/*
-----------------------------------------------------------------------------
PROJECT TITLE : SMART DOOR BELL
DATE : 6/12/2023
THIS PROJECT DEVELOPED BY OUR GROUP
1-ISYRAF IMRAN
2-ZAIM AIMAN
3-ZARIQ HAIKAL
------------------------------------------------------------------------------
*/
//include for the program
#include <Servo.h>
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
Servo myservo;
int pos = 0;
//tft define
#define TFT_DC 9
#define TFT_CS 10
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
int ledPin = 8; // choose the pin for the LED
int inputPin = 2; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0;
int buzzer = 6;
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
pinMode(buzzer, OUTPUT);
myservo.attach(10);
//tft screen display program(setup)
tft.begin();
tft.setCursor(25, 0);
tft.setTextColor(ILI9341_YELLOW);
tft.setTextSize(3);
tft.println("Welcome to");
tft.setCursor(13, 45);
tft.setTextColor(ILI9341_YELLOW);
tft.setTextSize(2);
tft.println("UNIKL MIIT B03 LAB");
tft.setCursor(0, 95);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(3);
tft.println("This is a");
tft.setCursor(0, 122);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(3);
tft.println("door bell");
tft.setCursor(0, 181);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(3);
tft.println("Put hand to use me");
tft.setCursor(0, 250);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(3);
tft.println("-TQ");
tft.setCursor(0, 300);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(1);
tft.println("IZZ.SDH");
}
void loop() {
val = digitalRead(inputPin);
if (val == HIGH) {
digitalWrite(ledPin, LOW);
if (pirState == LOW) {
for (pos = 0; pos <= 180; pos += 1) {
// in steps of 1 degree
myservo.write(pos);
delay(15);
}
pirState = HIGH;
tone(buzzer, 1000);
digitalWrite(ledPin, HIGH);
delay(1000);
noTone(buzzer);
digitalWrite(ledPin, LOW);
delay(1000);
tone(buzzer, 1000);
digitalWrite(ledPin, HIGH);
delay(1000);
noTone(buzzer);
}
} else {
digitalWrite(ledPin, LOW);
if (pirState == HIGH) {
for (pos = 180; pos >= 0; pos -= 1) {
myservo.write(pos);
delay(15);
}
pirState = LOW;
}
}
}