0% found this document useful (0 votes)
2 views

Smart Home

PROJECT REPORT
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Smart Home

PROJECT REPORT
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

SMART HOME

MASTER ARDUINO PROGRAM

#include <Keypad.h>

#include <LiquidCrystal_I2C.h>

#include <Servo.h>

#include <dht.h> // Include library

#define outPin 12

dht DHT;

const byte ROWS = 4; //four rows

const byte COLS = 4; //four columns

int pos = 0;

Servo myservo;

LiquidCrystal_I2C lcd(0x27,16,2);

char keys[ROWS][COLS] = {

{'1','2','3','A'},

{'4','5','6','B'},

{'7','8','9','C'},

{'*','0','#','D'}

};

byte rowPins[ROWS] = {2, 3, 4, 5}; //connect to the row pinouts of the keypad

byte colPins[COLS] = {6, 7, 8, 9}; //connect to the column pinouts of the keypad
const String password = "1234"; // change your password here

String input_password;

String pass;

int buz = 13;

//Create an object of keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){

Serial.begin(9600);

lcd.init(); // initialize the lcd

lcd.backlight();

pinMode(11, INPUT);

pinMode(buz, OUTPUT);

input_password.reserve(32);

myservo.attach(10);

myservo.write(160);

void loop(){

lcd.setCursor(0,0);

lcd.print(" SMART HOME ");

lcd.setCursor(0,1);

lcd.print(" WELCOME ");

if (digitalRead(11) == LOW) {

digitalWrite(buz, HIGH);
delay(200);

digitalWrite(buz, LOW);

lcd.clear();

lcd.setCursor(0,0);

lcd.print(" WELCOME ");

lcd.setCursor(0,0);

lcd.print(" SELECT OPTION ");

char opkey;

while (true){

opkey = keypad.getKey();

Serial.println(opkey);

if (opkey == 'A') {

Serial.println("if block");

break;

else if (opkey == 'B') {

break;

delay(200);

if (opkey == 'A') {

digitalWrite(buz, HIGH);

delay(200);

digitalWrite(buz, LOW);

lcd.clear();

lcd.setCursor(0,0);

lcd.print(" ENTER PIN ");


while (true) {

char key = keypad.getKey();// Read the key

if (key){

Serial.println(key);

if(key == '*') {

digitalWrite(buz, HIGH);

delay(200);

digitalWrite(buz, LOW);

input_password = ""; // reset the input password

pass = "";

lcd.setCursor(0,1);

lcd.print(" ");

else if(key == '#') {

digitalWrite(buz, HIGH);

delay(200);

digitalWrite(buz, LOW);

if(input_password == password) {

lcd.clear();

lcd.setCursor(0,1);

lcd.print(" Access Grand ");

delay(3000);

lcd.setCursor(0,1);

lcd.print(" Door Opening ");

for (pos = 160; pos >= 40; pos -= 5) { // goes from 0 degrees to 180 degrees

// in steps of 1 degree

myservo.write(pos); // tell servo to go to position in variable 'pos'


delay(50); // waits 15 ms for the servo to reach the position

lcd.setCursor(0,1);

lcd.print(" You May Go ");

delay(10000);

lcd.setCursor(0,1);

lcd.print(" Door Closing ");

for (pos = 40; pos <= 160; pos += 5) { // goes from 180 degrees to 0 degrees

myservo.write(pos); // tell servo to go to position in variable 'pos'

delay(50); // waits 15 ms for the servo to reach the position

delay(1000);

lcd.clear();

input_password = ""; // reset the input password

pass = "";

break;

else {

lcd.setCursor(0,1);

lcd.print(" Access Denid ");

digitalWrite(buz, HIGH);

delay(2000);

digitalWrite(buz, LOW);

input_password = ""; // reset the input password

pass = "";

else {
digitalWrite(buz, HIGH);

delay(200);

digitalWrite(buz, LOW);

input_password += key; // append new character to input password string

pass += "*";

lcd.setCursor(6,1);

lcd.print(pass);

delay(100);

if (opkey == 'B'){

digitalWrite(buz, HIGH);

delay(200);

digitalWrite(buz, LOW);

lcd.clear();

lcd.setCursor(0,0);

lcd.print(" Temprature ");

for (int i = 0 ; i < 10 ; i++){

int readData = DHT.read11(outPin);

int t = DHT.temperature; // Read temperature

int h = DHT.humidity;

lcd.setCursor(0,1);

lcd.print(t);

lcd.setCursor(2,1);
lcd.print("C");

lcd.setCursor(5,1);

lcd.print((t*9)/5+32);

lcd.setCursor(8,1);

lcd.print("F");

lcd.setCursor(11,1);

lcd.print(h);

lcd.setCursor(13,1);

lcd.print("% H");

delay(1000);

lcd.clear();

delay(500);

SLAVE ARDUINO PROGRAM

#include <Servo.h>

#include <SoftwareSerial.h>

#include <dht.h> // Include library

#define outPin 4

dht DHT;

SoftwareSerial mySerial(2,3); // Tx & Rx


Servo roomOneServo;

Servo roomTwoServo;

int roomOneIR = 12;

int roomTwoIR = 13;

int roomOneLight = 5;

int roomTwoLight = 6;

int roomHallLight = 8;

int roomHallFan = 7;

int roomOneLightSt = 0;

int roomTwoLightSt = 0;

int roomHallLightSt = 0;

int roomHallFanSt = 0;

int buz = 9;

int pos = 0;

void setup() {

Serial.begin(9600);

mySerial.begin(9600);

roomOneServo.attach(10);

roomTwoServo.attach(11);

roomOneServo.write(50);
roomTwoServo.write(180);

pinMode(roomOneIR, INPUT);

pinMode(roomTwoIR, INPUT);

pinMode(roomOneLight, OUTPUT);

pinMode(roomTwoLight, OUTPUT);

pinMode(roomHallLight, OUTPUT);

pinMode(roomHallFan, OUTPUT);

pinMode(buz, OUTPUT);

void loop() {

if (digitalRead(roomOneIR) == LOW) {

digitalWrite(buz, HIGH);

delay(500);

digitalWrite(buz, LOW);

for (pos = 50; pos <= 170; pos += 5) {

roomOneServo.write(pos);

delay(50);

delay(7000);

for (pos = 170; pos >= 50; pos -= 5) {

roomOneServo.write(pos);

delay(50);

}
if (digitalRead(roomTwoIR) == LOW) {

digitalWrite(buz, HIGH);

delay(500);

digitalWrite(buz, LOW);

for (pos = 180; pos >= 80; pos -= 5) {

roomTwoServo.write(pos);

delay(50);

delay(7000);

for (pos = 80; pos <= 180; pos += 5) {

roomTwoServo.write(pos);

delay(50);

if (mySerial.available()) {

char d = mySerial.read();

if (d == 'A') {

digitalWrite(buz, HIGH);

delay(200);

digitalWrite(buz, LOW);

digitalWrite(roomOneLight, HIGH);

mySerial.println("ROOM ONE Light ON");

roomOneLightSt = 1;

else if (d == 'B') {

digitalWrite(buz, HIGH);

delay(200);

digitalWrite(buz, LOW);
digitalWrite(roomOneLight, LOW);

mySerial.println("ROOM ONE Light OFF");

roomOneLightSt = 0;

else if (d == 'C') {

digitalWrite(buz, HIGH);

delay(200);

digitalWrite(buz, LOW);

digitalWrite(roomTwoLight, HIGH);

mySerial.println("ROOM TWO Light ON");

roomTwoLightSt = 1;

else if (d == 'D') {

digitalWrite(buz, HIGH);

delay(200);

digitalWrite(buz, LOW);

digitalWrite(roomTwoLight, LOW);

mySerial.println("ROOM TWO Light OFF");

roomTwoLightSt = 0;

else if (d == 'E') {

digitalWrite(buz, HIGH);

delay(200);

digitalWrite(buz, LOW);

digitalWrite(roomHallLight, HIGH);

mySerial.println("ROOM HALL Light ON");

roomHallLightSt = 1;

else if (d == 'F') {
digitalWrite(buz, HIGH);

delay(200);

digitalWrite(buz, LOW);

digitalWrite(roomHallLight, LOW);

mySerial.println("ROOM HALL Light OFF");

roomHallLightSt = 0;

else if (d == 'G') {

digitalWrite(buz, HIGH);

delay(200);

digitalWrite(buz, LOW);

digitalWrite(roomHallFan, HIGH);

mySerial.println("ROOM HALL FAN ON");

roomHallFanSt = 1;

else if (d == 'H') {

digitalWrite(buz, HIGH);

delay(200);

digitalWrite(buz, LOW);

digitalWrite(roomHallFan, LOW);

mySerial.println("ROOM HALL FAN OFF");

roomHallFanSt = 0;

else if (d == 'I') {

digitalWrite(buz, HIGH);

delay(200);

digitalWrite(buz, LOW);

mySerial.println("ROOM ONE DOOR OPEN");

for (pos = 50; pos <= 170; pos += 5) {


roomOneServo.write(pos);

delay(50);

delay(7000);

mySerial.println("ROOM ONE DOOR CLOSE");

for (pos = 170; pos >= 50; pos -= 5) {

roomOneServo.write(pos);

delay(50);

else if (d == 'J') {

digitalWrite(buz, HIGH);

delay(200);

digitalWrite(buz, LOW);

mySerial.println("ROOM TWO DOOR OPEN");

for (pos = 180; pos >= 80; pos -= 5) {

roomTwoServo.write(pos);

delay(50);

delay(7000);

mySerial.println("ROOM TWO DOOR CLOSE");

for (pos = 80; pos <= 180; pos += 5) {

roomTwoServo.write(pos);

delay(50);

else if (d == 'K') {

digitalWrite(buz, HIGH);

delay(200);
digitalWrite(buz, LOW);

mySerial.println("===================");

mySerial.println("Tempratur");

mySerial.println("===================");

for (int i = 0 ; i < 10 ; i++){

int readData = DHT.read11(outPin);

int t = DHT.temperature; // Read temperature

int h = DHT.humidity;

mySerial.print("Celcius : ");

mySerial.println(t);

mySerial.print("Fahrenheit : ");

mySerial.println((t*9)/5+32);

mySerial.print("Humidity : ");

mySerial.print(h);

mySerial.println("%");

mySerial.println("===================");

delay(1000);

else if (d == 'L') {

digitalWrite(buz, HIGH);

delay(200);

digitalWrite(buz, LOW);

mySerial.println("===================");

mySerial.println("SMART HOME STATUS");

mySerial.println("===================");

if (roomOneLightSt == 1){

mySerial.println("Room 1 Light : ON");


}

else {

mySerial.println("Room 1 Light : OFF");

if (roomTwoLightSt == 1){

mySerial.println("Room 2 Light : ON");

else {

mySerial.println("Room 2 Light : OFF");

if (roomHallLightSt == 1){

mySerial.println("Room Hall Light : ON");

else {

mySerial.println("Room Hall Light : OFF");

if (roomHallLightSt == 1){

mySerial.println("Room Hall Fan : ON");

else {

mySerial.println("Room Hall Fan : OFF");

mySerial.println("Room Tempratur");

int readData = DHT.read11(outPin);

int t = DHT.temperature; // Read temperature

int h = DHT.humidity;

mySerial.print("Celcius : ");

mySerial.println(t);

mySerial.print("Fahrenheit : ");
mySerial.println((t*9)/5+32);

mySerial.print("Humidity : ");

mySerial.print(h);

mySerial.println("%");

mySerial.println("Room 1 Door : Locked");

mySerial.println("Room 2 Door : Locked");

mySerial.println("Water Tank Leavel : 0%");

mySerial.println("===================");

delay(200);

You might also like