Introduction: Let Your Home to Be Smart Enough to Take Its Own Care.......Build Yours Today..
The Overall Smart Home Project Contains the following functionality:
SMART DOOR
1. 16x2 Lcd display.
2. Button panel to enter password.
3. Image notification through email on security breech.
4. Password to auto turn 'OFF' lights inside the house.
5. OTP (one time password) for guest.
6. Motor operated automatic door.
SMART SWITCHES
1. Touch switches to switch 'ON' and 'OFF' lights and fans of the room.
2. Bluetooth connectivity for android app.
SMART WINDOW
1. Smart window can be operated through android app with servo operated open and close feature.
2. It can sense rain, wind and temperature and shuts the window to maintain better environment inside the house.
REACTIVE TABLE
Glows where the object is kept on the table.
Step 1: Android Application
The Android Application used here can be downloaded fromHere
Step 2: Brief Overview of the Connections and Working of the Project.
Step 3: Smart Door
The smart lock project contains a 16x2 Lcd display, Arduino Uno micro-controller board, Matrix switch panel, a SIM900 GSM module, Raspberry pi 3 board and Basler Dart camera.
Note: Connectivity between controllers are done to make efficient system and reduce the number of micro-controllers as more number of pins were needed in lock and very less number of I/O pins were needed in window/cutrain system.
Features of the project :
1. Smart password locking system.
2. One time password for guests.
3. Email notification on security breech.
4. Turn 'OFF' lights inside the house using password.
The Code:-
#include <br>#include #include LiquidCrystal lcd(12, 11, 4, 5, 6, 7); // LCD connected on pins 12, 11, 4, 5, 6, 7 SoftwareSerial mySerial(9, 10); // pin 6 as RX and Pin 10 as TX int countwrong=0; // counter for counting the number of times the password was wrong char otp [4]= {' ',' ',' ',' '}; // variable to store otp char pass [4]; // variable to store entered password char password [4]= {'1','2','3','4'}; // stored password char light [4]= {'4','4','4','4'}; // stored password for lights OFF const byte ROWS = 4; //four rows of keypad const byte COLS = 3; //three columns of keypad char keys[ROWS][COLS] = { {'1','2','3'}, {'4','5','6'}, {'7','8','9'}, {'#','0','*'} }; byte rowPins[ROWS] = {A0, A1, 8, A5}; //connect to the row pinouts of the keypad byte colPins[COLS] = {A2, A3, A4}; //connect to the column pinouts of the keypad Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );void setup() {mySerial.begin(9600); // Setting the baud rate of GSM Module Serial.begin(9600); // Setting the baud rate of ardunio to window controller lcd.begin(16, 2); lcd.clear(); delay(100); pinMode ( 13, OUTPUT); // Status LED pinMode ( 2, OUTPUT); // pin for raspberry pi to send email. }void loop() {lcd.setCursor(0, 1); lcd.print(" "); lcd.setCursor(0, 0); lcd.print(" Shanque's Home "); //Prints message on the screen delay(50);if ( countwrong == 4){ // checks if the password was wrong for more than 4 times digitalWrite (2, HIGH); digitalWrite (13, HIGH); delay(500); digitalWrite (2, LOW); digitalWrite (13, LOW); delay(500); digitalWrite (13, HIGH); delay(500); digitalWrite (13, LOW); // blinks led and set the pin 2 high for raspberry pi countwrong=0; } // if (mySerial.available()>0) // For GSM module { char ch = mySerial.read(); if ( ch == '#') // check for # and then store the password accordinly { for (int i=0;i<4;i++) { otp[i] = mySerial.read(); // Store OTP }digitalWrite(13, HIGH); // sets status led 'ON' when OTP received lcd.setCursor(0, 0); lcd.print(" otp received "); delay(100); SendMessage(); // Sends message to the phone on OTP received } } char key = keypad.getKey(); // keypad input if (key != NO_KEY){ lcd.setCursor(0, 0); lcd.print(" Enter Password "); for (int i =0;i<4;i++) { key = keypad.getKey(); while (key == NO_KEY) { key = keypad.getKey(); } pass[i]=key; lcd.setCursor(i, 1); lcd.print('*'); delay(200); } int count = 0; // local counters for password check int count2 = 0; int count3 = 0; for (int i =0;i<4;i++) { if ( pass[i] == password[i]) // check for password equal to stored password count++; if ( pass[i] == otp[i]) // check for password equal to stored otp count2++; if ( pass[i] == light [i]) // check for password equal to stored password for lights count3++; } if(count == 4) { lcd.setCursor(0, 0); lcd.print(" door open "); Serial.write('Y'); // sends Y to window controller to open gates delay(500); countwrong=0; } else if (count3 == 4) { lcd.setCursor(0, 0); lcd.print(" Lights OFF "); Serial.write('Z'); // sends Z to switch board controller to switch off lights delay(500); countwrong=0; // sets counter to zero } else if (count2 == 4) // if password is equal to otp, opens gates and deletes OTP { lcd.setCursor(0, 0); otp [0] = ' '; otp [1] = ' '; otp [2] = ' '; otp [3] = ' '; lcd.print(" door open "); delay(500); digitalWrite (13, LOW); Serial.write('Y'); // sends Y to window controller to open gates lcd.setCursor(0, 0); lcd.print(" otp used "); delay(500); SendMessage1(); // sends the message that guests arrived countwrong=0; } else { lcd.setCursor(0, 0); lcd.print(" wrong password "); countwrong++; // raise the password by one if the password was wrong delay(500); } } } void SendMessage() // send message when otp is received { mySerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode delay(1000); // Delay of 1000 milli seconds or 1 second mySerial.println("AT+CMGS=\"+91xxxxxxxxxx\"\r"); // Replace x with mobile number delay(1000); mySerial.println("OTP Received");// The SMS text you want to send delay(100); mySerial.println((char)26);// ASCII code of CTRL+Z delay(1000); } void SendMessage1() // send message when otp is used. { mySerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode delay(1000); // Delay of 1000 milli seconds or 1 second mySerial.println("AT+CMGS=\"+91xxxxxxxxxx\"\r"); // Replace x with mobile number delay(1000); mySerial.println("Guest arrived");// The SMS text you want to send delay(100); mySerial.println((char)26);// ASCII code of CTRL+Z delay(1000);
1. Smart password locking system :
The lock contains a matrix keypad which is used to input password which thereby is compared with the stored password and unlocks the door if the password is correct. If the PASSWORD is incorrect, then it increases the counter which is used to note the number of incorrect attempts. For the keypad board to work, a keypad library is needed to be installed in the arduino IDE which can be downloaded here The input from the keypad is stored in the character array of size 4, i.e. the password used here is of four digits only. Whenever the password is correct, the lock controller send a message to window/curtain controller which in turn operates the geared DC motor using L 293 ( the motor driver ).
2. One time password for guests:
This features allows guests to enter inside the house when you are not present to attend them or late for some reasons, thereby reducing extra efforts. To initiate OTP, we need to send a four digit password from our mobile phone to the number in the GSM module. The OTP begins with '#', example : #4444, #1234, #5665 etc. When the Lock controller receives the password, It sends a message to the registered number "OTP received" and also switches 'ON' the LED connected to Pin 13 of the controller. When the quest use the OTP provided, It gets deleted and also switches 'OFF' the LED connected to Pin 13 of the controller and sends the message to the registered mobile number "Guest Arrived".
3. Image notification through email on security breech :
For this feature, I have used Raspberry pi 3 board with Basler Dart Camera and wifi connection for internet. Installation:
1. Setting Up Your Raspberry Pi With Raspbian : First you need to install Raspbian on your micro sd card that you will be using in your Raspberry Pi. You can download the latest image of Raspbian from Raspberry Pi website at: http://www.raspberrypi.org/downloads/ You will need to use an image writing tool to install the image on your SD card. You can find the steps to do that at: http://www.raspberrypi.org/downloads/
2. Install OpenCV and Required Libraries : There are lots of methods to do this. But I would prefer using the simplest method that is available in OpenCV website at http://www.raspberrypi.org/downloads/
3. Installation of Basler Dart Camera application Pylon : Download pylon 5.0.11 Camera Software Suite Linux ARM 32 bit hardfloat from Here , unzip and follow the iunstructions mentioned in text file inside.
4. Python Code : Use the attached Python code after editing the following lines gmail_user = "xxxx@gmail.com" #Sender email address Enter your email address in the above line using which the Photo captured will be sent gmail_pwd = "xxxx" #Sender email password Enter the password of the sender email address. to = "xxxx@gmail.com" #Receiver email address Enter the email address to which the email with the picture captured will be sent...
import RPi.GPIO as GPIO<br> import time import numpy as np import pypylon.pylon as pyimport cv2 from datetime import datetime import os import smtplib from email.MIMEMultipart import MIMEMultipart from email.MIMEBase import MIMEBase from email.MIMEText import MIMEText from email import Encoders gmail_user ="xxxx@gmail.com" #Sender email address gmail_pwd = "xxxx" #Sender email password to = "xxxx@gmail.com" #Receiver email address subject = "Security Breach" text = "Somebody is trying wrong passwords at the door. See the attached picture. "sensor = 4GPIO.setmode(GPIO.BCM) GPIO.setup(sensor, GPIO.IN, GPIO.PUD_DOWN)previous_state = False current_state = Falseicam = py.InstantCamera(py.TlFactory.GetInstance().CreateFirstDevice()) icam.PixelFormat = "RGB8" while True: previous_state = current_state current_state = GPIO.input(sensor)if current_state != previous_state: new_state = "HIGH" if current_state else "LOW" print("GPIO pin %s is %s" % (sensor, new_state)) if current_state: icam.Open() img = icam.GrabOne(4000) img = img.Array print "Saving Photo" picname = datetime.now().strftime("%y-%m-%d-%H-%M") picname = picname+'.jpg' cv2.imwrite(picname, img) print "Sending email" attach = picname msg = MIMEMultipart()msg['From'] = gmail_user msg['To'] = to msg['Subject'] = subjectmsg.attach(MIMEText(text))part = MIMEBase('application', 'octet-stream') part.set_payload(open(attach, 'rb').read()) Encoders.encode_base64(part) part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(attach)) msg.attach(part)mailServer = smtplib.SMTP("smtp.gmail.com", 587) mailServer.ehlo() mailServer.starttls() mailServer.ehlo() mailServer.login(gmail_user, gmail_pwd) mailServer.sendmail(gmail_user, to, msg.as_string()) # Should be mailServer.quit(), but that crashes... mailServer.close() print "Email Sent" os.remove(picname)
5. Final Setup : Now connect the Basler Dart camera and pin from arduino to the Raspberry Pi. Connect the output from arduino to GPIO pin 4 and also connect ground from arduino to ground of raspberry pi. Now you run the python code with sudo to check the setup. Whenever somebody enters password wrong more than 5 times, an image is captured and email is set the to email address you entered as the receivers email address.
6. Raspberry Pi Auto Login and Auto Start and Run the Python Code : To auto run the python code at start up just by powering up the raspberry pi use the following steps.
Auto Login:
In Terminal:
sudo nano /etc/inittab
Scroll down to:
1:2345:respawn:/sbin/getty 115200 tty1
and change to
#1:2345:respawn:/sbin/getty 115200 tty1
Under that line add:
1:2345:respawn:/bin/login -f pi tty1 /dev/tty1 2>&1
Ctrl+X to exit, Y to save followed by enter twice
Auto run the python code
sudo nano /etc/rc.local
Scroll to the bottom and add the following above exit 0:
sudo python /directory/pythonfile.py
Press Ctrl+X to exit, Y to save followed by Enter twice.
If you face any issues in the steps, look at http://elinux.org/RPi_Debian_Auto_Login Now reboot the system and you will see that the python code has started.
4. Turn 'OFF' lights inside the house using password :
This feature allows you to switch 'OFF' the lights inside the house when you forgot to switch them 'OFF' so, you don't need to go inside the house to switch them 'OFF'. Thereby reducing extra efforts. This is how it works : When the password entered by you matches the password for the lights, say '4444' here, the controller sends a signal to Window/Curtain controller, which in turn sends the signal to switch board controller and switches all the lights 'OFF'.
Step 4: Smart Switches
Smart switches contains 6 switches which can be operated through touch.
Slide up on the red indicator to switch 'ON' and Slide down on it to switch 'OFF'.
The casing used above is of the normal switch board casing with all the indicators installed.
The internal components of each indicator is replaced with two IR detectors, one IR transmitter and one LED as shown in the image above.
The back of the switch panel is shown in image with LM538 (op-amp) connected one for each switch .
The outputs of the op-amps are given as inputs to Arduino Uno micro-controller board used in the system.
The Code:-
#include <br> SoftwareSerial mySerial(9, 10); // Pin 9 as RX and Pin 10 as TXvoid setup() { mySerial.begin(9600); // Setting the baud rate of GSM Module Serial.begin(9600); // Setting the baud rate of Serial Monitor (Arduino) pinMode ( 2, INPUT); pinMode ( 3, INPUT); pinMode ( 4, INPUT); pinMode ( 5, INPUT); pinMode ( 6, INPUT); pinMode ( 7, INPUT); pinMode ( 8, INPUT); pinMode ( 11, INPUT); //Input mode for 4 IR switches pinMode ( A0, OUTPUT); pinMode ( A1, OUTPUT); pinMode ( A2, OUTPUT); pinMode ( A3, OUTPUT); pinMode ( A4, OUTPUT); pinMode ( A5, OUTPUT); // Output for 6 relays and LEDs } void loop() { if ( digitalRead(2)==HIGH) { digitalWrite(A0, HIGH); // Switch 1 'ON' state } if ( digitalRead(3)==HIGH) { digitalWrite(A0, LOW); // Switch 1 'OFF' state } if ( digitalRead(4)==HIGH) { digitalWrite(A1, HIGH); //Switch 2 'ON' state } if ( digitalRead(5)==HIGH) { digitalWrite(A1, LOW); //Switch 2 'OFF' state } if ( digitalRead(6)==HIGH) { digitalWrite(A2, HIGH); //Switch 3 'ON' state } if ( digitalRead(7)==HIGH) { digitalWrite(A2, LOW); //Switch 3 'OFF' state } if ( digitalRead(8)==HIGH) { digitalWrite(A3, HIGH); //Switch 4 'ON' state } if ( digitalRead(11)==HIGH) { digitalWrite(A3, LOW); //Switch 4 'OFF' state } if (Serial.available()>0){ char ch = Serial.read(); // Input from bluetooth module if(ch=='A') { digitalWrite(A0, HIGH); // switch 'ON' switch 1 } if(ch=='a') { digitalWrite(A0, LOW); // switch 'OFF' switch 1 } if(ch=='B') { digitalWrite(A1, HIGH); // switch 'ON' switch 2 } if(ch=='b') { digitalWrite(A1, LOW); // switch 'OFF' switch 2 } if(ch=='C') { digitalWrite(A2, HIGH); // switch 'ON' switch 3 } if(ch=='c') { digitalWrite(A2, LOW); // switch 'OFF' switch 3 } if(ch=='D') { digitalWrite(A3, HIGH); // switch 'ON' switch 4 } if(ch=='d') { digitalWrite(A3, LOW); // switch 'OFF' switch 4 } if(ch=='E') { digitalWrite(A4, HIGH); // switch 'ON' switch 5 } if(ch=='e') { digitalWrite(A4, LOW); // switch 'OFF' switch 5 } if(ch=='F') { digitalWrite(A5, HIGH); // switch 'ON' switch 6 } if(ch=='f') { digitalWrite(A5, LOW); // switch 'OFF' switch 6 } if(ch=='G') { mySerial.write('G'); // send a signal to window/curtain controller to open Window } if(ch=='g') { mySerial.write('g'); // send a signal to window/curtain controller to close Window } if(ch=='H') { mySerial.write('H'); // send a signal to window/curtain controller to open curtain } if(ch =='h') { mySerial.write('h'); // send a signal to window/curtain controller to close curtain } } if (mySerial.available()>0) { if(mySerial.read()=='Z') // receive a signal from door controller through window/curtain controller to switch 'OFF' all the lights { digitalWrite(A0, LOW); digitalWrite(A1, LOW); digitalWrite(A2, LOW); digitalWrite(A3, LOW); digitalWrite(A4, LOW); digitalWrite(A5, LOW); // switch all the switches 'OFF' } }}
Step 5: Smart Window
This project is related to smart window which can be controlled by mobile phone using android mobile app.
The window is also Smart enough to detect Rain and fast moving air.
Below is the code for arduino to control smart window.
#include #include #include Servo servo1; Servo servo2;// create servo objects to control a servo // twelve servo objects can be created on most boards boolean WindowStatus = 0; // status of window i.e open = 1 and close = 0 boolean DoorStatus = 0; // status of door i.e open = 1 and close = 0 int pos = 0; // variable to store the servo position SoftwareSerial mySerial(9, 10); void setup() { mySerial.begin(9600); // Setting the baud rate of DOOR controller Serial.begin(9600); // Setting the baud rate of Switch board controller servo1.attach(5); // attaches the servo on pin 5 to the servo object servo2.attach(6); // attaches the servo on pin 6 to the servo object pinMode(13, INPUT_PULLUP); // switch to open/close window WindowStatus=EEPROM.read(0); pinMode(A0, INPUT_PULLUP); pinMode(2, INPUT_PULLUP); pinMode(3, INPUT_PULLUP); pinMode(4, INPUT_PULLUP); pinMode(11, OUTPUT); pinMode(12, OUTPUT); } void loop() { if( digitalRead(13)==0 && WindowStatus == 0 ){ for(pos = 150; pos >= 65; pos -= 1) // goes from 150 degrees to 65 degrees { // in steps of 1 degree servo2.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } for(pos = 60; pos <= 155; pos += 1) // goes from 60 degrees to 155 degrees { // in steps of 1 degree servo1.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } WindowStatus = 1; EEPROM.write(0, WindowStatus); }if( digitalRead(13)==0 && WindowStatus == 1 ){ for(pos = 155; pos >= 60; pos -= 1) // goes from 155 degrees to 60 degrees { // in steps of 1 degree servo1.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } for(pos = 65; pos <= 150; pos += 1) // goes from 60 degrees to 150 degrees { // in steps of 1 degree servo2.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } WindowStatus = 0; EEPROM.write(0, WindowStatus); }// Open close window using bluetooth app if (Serial.available()>0) { char ch = Serial.read(); // Input from bluetooth module if( ch == 'G' && WindowStatus == 0 ){ for(pos = 150; pos >= 65; pos -= 1) // goes from 150 degrees to 65 degrees { // in steps of 1 degree servo2.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } for(pos = 60; pos <= 155; pos += 1) // goes from 60 degrees to 155 degrees { // in steps of 1 degree servo1.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } WindowStatus = 1; EEPROM.write(0, WindowStatus); }if( ch == 'g' && WindowStatus == 1 ){ for(pos = 155; pos >= 60; pos -= 1) // goes from 155 degrees to 60 degrees { // in steps of 1 degree servo1.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } for(pos = 65; pos <= 150; pos += 1) // goes from 60 degrees to 150 degrees { // in steps of 1 degree servo2.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } WindowStatus = 0; EEPROM.write(0, WindowStatus); } }if( analogRead(A0) < 600 && WindowStatus == 1 ){ // Rain Sensor for(pos = 155; pos >= 60; pos -= 1) // goes from 155 degrees to 60 degrees { // in steps of 1 degree servo1.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } for(pos = 65; pos <= 150; pos += 1) // goes from 60 degrees to 150 degrees { // in steps of 1 degree servo2.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } WindowStatus = 0; EEPROM.write(0, WindowStatus); }if( analogRead(A1) > 150 && WindowStatus == 1 ){ // Wind Sensor for(pos = 155; pos >= 60; pos -= 1) // goes from 155 degrees to 60 degrees { // in steps of 1 degree servo1.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } for(pos = 65; pos <= 150; pos += 1) // goes from 60 degrees to 150 degrees { // in steps of 1 degree servo2.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } WindowStatus = 0; EEPROM.write(0, WindowStatus); }if (mySerial.available()>0) { char ch = mySerial.read(); if ( ch == 'Z') Serial.write('Z'); // Switch OFF lights if ( ch == 'Y'){ // Close Door if( DoorStatus==1){ while(digitalRead(3)==HIGH){ digitalWrite(11, LOW); digitalWrite(12, HIGH); } digitalWrite(11, LOW); digitalWrite(12, LOW); DoorStatus=0; }} }if(digitalRead(4)==LOW && DoorStatus==0){ // Open Door while(digitalRead(2)==HIGH){ digitalWrite(11, HIGH); digitalWrite(12, LOW); } digitalWrite(11, LOW); digitalWrite(12, LOW); DoorStatus=1; } if(digitalRead(4)==LOW && DoorStatus==1){ // Close Door while(digitalRead(3)==HIGH){ digitalWrite(11, LOW); digitalWrite(12, HIGH); } digitalWrite(11, LOW); digitalWrite(12, LOW); DoorStatus=0; } }
Step 6: Reactive Table
Reactive table is a table containing led matrix at its surface.When ever any object is placed on the top of it, it glows thereby making the table interactive.
The video contains two pixels of the table which glows when something comes infront of it.
1. The pixels can be created in a pair of two as the IC LM358 used is a dual op-amp which can be used as a comparator.
2. Each pair of pixels needs 2 Infrared detectors, 1 Infrared transmitter, 1 LM358, 5 resistors (10k*2, 100ohm*2 ,1 330ohm) and a variable resistor(10k).
3. The circuit diagram for the pixel is given above.
The number of pixels can be made according to the size of the table used and connect in parallel with each other.
Participated in the
Microcontroller Contest