-
Notifications
You must be signed in to change notification settings - Fork 0
/
Culminating2022.ino
78 lines (66 loc) · 2.01 KB
/
Culminating2022.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//January 31st 2022
#include <IRremote.h> //include infared remote library
#include <LiquidCrystal_I2C.h> //include lcd sceen library
#include <Wire.h>
//defining pins for inputs
int trigPin = 13;
int echoPin = 12;
long duration;
int distance;
int buzzer = 3;
int IR_RECEIVE_PIN = 2;
IRrecv ir_receiver(IR_RECEIVE_PIN);
LiquidCrystal_I2C lcd (0x27,20,4); //set dimensions for lcd screen
void setup()
{
//defining outputs
lcd.init();
lcd.backlight();
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
pinMode(11, OUTPUT);
IrReceiver.begin(IR_RECEIVE_PIN);
pinMode(buzzer, OUTPUT);
}
void loop()
{
//loop for ultrasonic sensor to scan surroundings for distance
digitalWrite(trigPin ,LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(2);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
//create 'distance' interger
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034/2;
Serial.println(distance); //print serial data from sensor
if (distance < 150) //if sensor detects something less than 150 millimeters away
{
digitalWrite(11, HIGH); //turn LED on
lcd.setCursor(0,0);
lcd.print("security breach");
digitalWrite(buzzer, HIGH); //turn buzzer on
}
if (distance > 150) //if sensor detects somethign but is greater than 150 millimeters away
{
digitalWrite(11, LOW); //turn LED off
lcd.setCursor(0,0);
lcd.println("armed ");
noTone(buzzer); //turn buzzer off
}
if(IrReceiver.decode()) //if the infared receiver detects a signal from the remote
{
digitalWrite(11,LOW); //turn LED off
noTone(buzzer); //turn buzzer off
lcd.setCursor(0,0);
lcd.print("disarmed ");
delay(5000);
lcd.setCursor(0,0);
lcd.print("armed ");
lcd.setCursor(5,0);
lcd.print(" ");
IrReceiver.resume(); //continue loop
}
}