#include #include LiquidCrystal lcd(12, 11, 5, 4, 3, 2);//RS, EN, D4, D5, D6, D7 SoftwareSerial bt(10, 9); // TX,RX OF HC05 #define fan 8 #define light 7 #define out1 A1 # define out2 A2 int buzzer = 6; int light_sensor_Pin = 0;// analog 0 for light sensor int password[4] = {1,2,3,4};//correct password int input; int check = 0 ; char command[1];// for light and fan L,l for light and F,f for fan int ilight; // intensity of ight from sensor int correct,wrong;// inputs from the helium board void setup() { Serial.begin(9600); lcd.begin(16, 2); lcd.print("Locking the "); lcd.setCursor(0,1); lcd.print("Doors "); delay(1500); lcd.clear(); lcd.print("Connecting with"); lcd.setCursor(0,1); lcd.print("Appliances"); delay(1000); lcd.clear(); lcd.print("Securing the"); lcd.setCursor(0,1); lcd.print("Mansion...."); delay(1500); Serial.begin(9600); Serial.println("\n Bluetooth Module two-way communication with Phone or PC begins..."); pinMode(light_sensor_Pin, INPUT); pinMode(out2, INPUT); pinMode(out1, INPUT); pinMode(fan, OUTPUT); pinMode(light, OUTPUT); pinMode(buzzer,OUTPUT); digitalWrite(fan, HIGH); digitalWrite(light, LOW); digitalWrite(buzzer, LOW); bt.begin(9600); // delay(1000); bt.println("\nHello Bluetooth Device! /nThis is Home automation system calling via Bluetooth."); bt.println("Send the password for access"); lcd.clear(); lcd.setCursor(0,0); lcd.print("Enter Password"); delay(1000); } void loop() { //-----------------checking the outputs from the helium board--------- correct = digitalRead(out1); wrong = digitalRead(out2); if (wrong = LOW) check = 2; if(correct = LOW) {check = 5;Serial.println("hi");} //if (wrong = HIGH) check = 2; //---------------checking the amount of light in the room----------- ilight = analogRead(light_sensor_Pin); if( ilight >= 450) { lcd.setCursor(0,1); lcd.print("Low Light"); delay(1000); bt.println("/nTheir is not enough light in the room."); } //-----------------if password entered is correct-------------------- if ( check == 5 ) { lcd.clear(); lcd.setCursor(0,0); lcd.print("Access Granted!"); delay(200); { command[0] = bt.read(); } lcd.setCursor(0,1); lcd.print(command[0]); if(command[0] == 'f')digitalWrite(fan,HIGH); if(command[0] == 'l') digitalWrite(light,HIGH); if(command[0] == 'F')digitalWrite(fan,LOW); if(command[0] == 'L') digitalWrite(light,LOW); delay(1000); lcd.clear(); } //---------------if wrong password is entered------------------------ else if ( check == 2 ) {check = 1; lcd.clear(); lcd.setCursor(0,0); lcd.print("Wrong Password"); lcd.setCursor(0,1); lcd.print("Enter Again"); digitalWrite(buzzer,HIGH); delay(500); digitalWrite(buzzer,LOW); if(bt.available()) { if(password[0] == bt.read()-48) //for checking the ascii values we subtract 48 if(password[1]==bt.read()-48) if(password[2]==bt.read()-48) if(password[3]==bt.read()-48) check=5; } else if (check = 1); { if(bt.available()) { if(password[0] == bt.read()-48) //for checking the ascii values we subtract 48 if(password[1]==bt.read()-48) if(password[2]==bt.read()-48) if(password[3]==bt.read()-48) check=5; } } } //-----------------------asking for password for the first time---------- else if (bt.available()) { input = bt.read(); lcd.clear(); if(password[0] == input-48) if(password[1] == bt.read()-48) if(password[2] == bt.read()-48) if(password[3] == bt.read()-48) { check=5; } else {check = 2;} else {check = 2;} else {check = 2;} else {check = 2;} } }