-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSOURCE CODE
135 lines (133 loc) · 2.98 KB
/
SOURCE CODE
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
IoT Based Home Automation
*/
//libraries for LCD Display
#include <LiquidCrystal.h>
// Define LCD display pins
LiquidCrystal lcd(12,11,10,9,8,7);
const int Device1 = 6; // Relay pin 1 (IN1)
const int Device2 = 5; // Relay pin 2 (IN2)
const int Device3 = 4; // Relay pin 3 (IN3)
const int Device4 = 3; // Relay pin 4 (IN4)
void setup()
{
Serial.begin(9600); //Sets the baud for serial data transmission
// Set Relay pins as OUTPUT
pinMode(Device1, OUTPUT);
pinMode(Device2, OUTPUT);
pinMode(Device3, OUTPUT);
pinMode(Device4, OUTPUT);
// Print massage on LCD Display
lcd.begin(16, 2); // LCD no. of columns and rows: 16*2
lcd.setCursor(0,0); // Sets the cursor at 0th column and 0th row when LCD
ON
lcd.print(" IoT Based ");
lcd.setCursor(0,1);
lcd.print("Home Automation");
delay(2000);
// To Print message All devices are OFF when system is ON
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" D1 D2 D3 D4 ");
lcd.setCursor(0,1);
lcd.print(" OFF OFF OFF OFF");
}
void loop()
{
lcd.setCursor(0,0);
lcd.print(" D1 D2 D3 D4 ");
// Read data from Bluetooth Module
if (Serial.available() > 0)
{
char Val = Serial.read();
// Print Bluetooth Module data on serial monitor
Serial.print("VAL: ");
Serial.println(Val);
// When Bluetooth Module data "1" then Relay1 ON
if (Val == '1')
{
digitalWrite(Device1,LOW);
lcd.setCursor(1,1);
lcd.print("ON ");
delay(200);
}
// When Bluetooth Module data "A" then Relay1 OFF
else if (Val=='A')
{
digitalWrite(Device1,HIGH);
lcd.setCursor(1,1);
lcd.print("OFF");
delay(200);
}
// When Bluetooth Module data "2" then Relay2 ON
else if (Val=='2')
{
digitalWrite(Device2,LOW);
lcd.setCursor(5,1);
lcd.print("ON ");
delay(200);
}
// When Bluetooth Module data "B" then Relay2 OFF
else if (Val=='B')
{
digitalWrite(Device2,HIGH);
lcd.setCursor(5,1);
lcd.print("OFF");
delay(200);
}
// When Bluetooth Module data "3" then Relay3 ON
else if (Val=='3')
{
digitalWrite(Device3,LOW);
lcd.setCursor(9,1);
lcd.print("ON ");
delay(200);
}
// When Bluetooth Module data "C" then Relay3 OFF
else if (Val=='C')
{
digitalWrite(Device3,HIGH);
lcd.setCursor(9,1);
lcd.print("OFF");
delay(200);
}
// When Bluetooth Module data "4" then Relay4 ON
else if (Val=='4')
{
digitalWrite(Device4,LOW);
lcd.setCursor(13,1);
lcd.print("ON ");
delay(200);
}
// When Bluetooth Module data "D" then Relay4 OFF
else if (Val=='D')
{
digitalWrite(Device4,HIGH);
lcd.setCursor(13,1);
lcd.print("OFF");
delay(200);
}
// When Bluetooth Module data "9" then All Relay ON
else if (Val=='9')
{
digitalWrite(Device1, LOW);
digitalWrite(Device2, LOW);
digitalWrite(Device3, LOW);
digitalWrite(Device4, LOW);
lcd.setCursor(0,1);
lcd.print(" ON ON ON ON ");
delay(200);
}
// When Bluetooth Module data "I" then All Relay OFF
else if (Val=='I')
{
digitalWrite(Device1, HIGH);
digitalWrite(Device2, HIGH);
digitalWrite(Device3, HIGH);
digitalWrite(Device4, HIGH);
lcd.setCursor(0,1);
lcd.print(" OFF OFF OFF OFF");
delay(200);
}
}
}