Keval PankhaniyaJainam shahViraj rawal
Published © GPL3+

Personal Home Assistant

It is the I2C protocol based Home Automation System. Which can be controlled by voice, Android Phone and even from your laptop.

AdvancedFull instructions providedOver 2 days3,362
Personal Home Assistant

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
Atmel ATMega328
×1
Linear Regulator (7805)
Linear Regulator (7805)
×1
Jumper wires (generic)
Jumper wires (generic)
×20
Resistor 10k ohm
Resistor 10k ohm
×5
Resistor 1k ohm
Resistor 1k ohm
×5
Capacitor 22 pF
Capacitor 22 pF
×6
16 MHz Crystal
16 MHz Crystal
×3
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×3
LED (generic)
LED (generic)
×6
Capacitor 10 µF
Capacitor 10 µF
×6
Capacitor 470 µF
Capacitor 470 µF
×3
Terminal Blocks
×1
9V to Barrel Jack Connector
9V to Barrel Jack Connector
×1
SparkFun DC Female Jack
×1
Raspberry Pi 2 Model B
Raspberry Pi 2 Model B
×1
Relay (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
webiopi
Visual Studio 2015
Microsoft Visual Studio 2015
Microsoft Windows Speech Recognition Macros

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
PCB Milling Machine

Story

Read more

Schematics

ATmega328 based slaves

This is a schematic file. Which is supported in eagle or other PCB designing softwares.

ATmega 328 based PCB board

This is PCB board, which may be supported in Eagle or other PCB designing software.

Code

Master Code

C/C++
This is master arduino code.
int state;
#include <Wire.h>
#include <Password.h> 
#include <Keypad.h>

Password password = Password( "1234" );

const byte ROWS = 4; // Four rows
const byte COLS = 4; // columns
// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 2, 3, 4, 5 };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 6, 7, 8, 9 };


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


void setup() {
 Serial.begin(9600);
 delay(200);
 pinMode(13, OUTPUT);  
 keypad.addEventListener(keypadEvent);
 Wire.begin(); // join i2c bus (address optional for master)
}


void loop() 
{

keypad.getKey();
state = Serial.read();
switch(state)
{
  
  // Drawing room controlling, device id 1
  
  case '1':                   //Drawing Room Fan On
  Wire.beginTransmission(1);
  Wire.write("1");
  Wire.endTransmission();
  delay(500);
  break;

  case '2':                  //Drawing room Light on
  Wire.beginTransmission(1);
  Wire.write("2");
  Wire.endTransmission();
  delay(500);
  break;

  case '3':                  //Drawing room Curtain open
  Wire.beginTransmission(1);
  Wire.write("3");
  Wire.endTransmission();
  delay(500);
  break;
  
  case '4':                  //Drawing room Fan off
  Wire.beginTransmission(1);
  Wire.write("4");
  Wire.endTransmission();
  delay(500);
  break;

  case '5':                  // Drwaing room light off
  Wire.beginTransmission(1);
  Wire.write("5");
  Wire.endTransmission();
  delay(500);
  break;

  case '6':                  //Drawing room curtain off
  Wire.beginTransmission(1);
  Wire.write("6");
  Wire.endTransmission();
  delay(500);
  break;

  // Bed room controlling , device id 2
  
  case '7':                   //Bed Room Fan On
  Wire.beginTransmission(2);
  Wire.write("1");
  Wire.endTransmission();
  delay(500);
  break;

  case '8':                  //Bed room Light on
  Wire.beginTransmission(2);
  Wire.write("2");
  Wire.endTransmission();
  delay(500);
  break;

  case '9':                  //Bed room Curtain open
  Wire.beginTransmission(2);
  Wire.write("3");
  Wire.endTransmission();
  delay(500);
  break;
  
  case 'A':                  //Bed room Fan off
  Wire.beginTransmission(2);
  Wire.write("4");
  Wire.endTransmission();
  delay(500);
  break;

  case 'B':                  // Bed room light off
  Wire.beginTransmission(2);
  Wire.write("5");
  Wire.endTransmission();
  delay(500);
  break;

  case 'C':                  //Bed room curtain off
  Wire.beginTransmission(2);
  Wire.write("6");
  Wire.endTransmission();
  delay(500);
  break;


  // Kitchen controlling
  
  case 'D':                   //Kitchen Fan On
  Wire.beginTransmission(3);
  Wire.write("1");
  Wire.endTransmission();
  delay(500);
  break;

  case 'E':                  //KitchenLight on
  Wire.beginTransmission(3);
  Wire.write("2");
  Wire.endTransmission();
  delay(500);
  break;

  case 'F':                  //Kitchen Curtain open
  Wire.beginTransmission(3);
  Wire.write("3");
  Wire.endTransmission();
  delay(500);
  break;
  
  case 'G':                  //Kitchen Fan off
  Wire.beginTransmission(3);
  Wire.write("4");
  Wire.endTransmission();
  delay(500);
  break;

  case 'H':                  // Kitchen light off
  Wire.beginTransmission(3);
  Wire.write("5");
  Wire.endTransmission();
  delay(500);
  break;

  case 'I':                  //Kitchen curtain off
  Wire.beginTransmission(3);
  Wire.write("6");
  Wire.endTransmission();
  delay(500);
  break;

  
}
}

void keypadEvent(KeypadEvent eKey){
  switch (keypad.getState()){
  case PRESSED:
  
  Serial.print("Enter:");
  Serial.println(eKey);
  delay(10);
  
 
  
  switch (eKey){
    case '*': checkPassword(); delay(1); break;
    
    case '#': password.reset(); delay(1); break;
    
     default: password.append(eKey); delay(1);
}
}
}

void checkPassword(){
  
if (password.evaluate()){  //if password is right open
    
    Serial.println("Accepted");
    delay(10);
    //Add code to run if it works
    digitalWrite(13, LOW);//turn on
    
    
}else{
    Serial.println("Denied"); //if passwords wrong keep locked
  delay(10);
    //add code to run if it did not work
    digitalWrite(13, HIGH); //turn on
    
}
}

Second slave code

C/C++
We are using total three slaves. ut I am just uploading only first slave's code, because other slaves have just same code except NODE_ADDRESS.
#include <Wire.h>

#define NODE_ADDRESS 2  // For 1st slave, it is 1 and for third slave it is 3 
#define PAYLOAD_SIZE 2 

byte nodePayload[PAYLOAD_SIZE];
int t;
void setup()
{

  Serial.begin(9600);
  Serial.println("System made by K.V.J");
  Serial.print("Node address: ");
  Serial.println(NODE_ADDRESS);
  Serial.print("Payload size: ");
  Serial.println(PAYLOAD_SIZE);
  Serial.println("***********************");
  pinMode(2,OUTPUT);
  pinMode(3,OUTPUT);
  pinMode(4,OUTPUT);
  Wire.begin(NODE_ADDRESS);  
  Wire.onReceive(receiveEvent); 
}

void loop()
{
  delay(100);
}


void receiveEvent(int howMany)
{
  t = Wire.read();    
  Serial.println(t);

  if (t == 49)
  {
    digitalWrite(2, HIGH);
  }

  else if (t == 50)
  {
    digitalWrite(3, HIGH);
  }



  else if (t == 51)
  {
    digitalWrite(4, HIGH);
  }


  else if (t == 52)
  {
    digitalWrite(2, LOW);
  }

  else if (t == 53)
  {
    digitalWrite(3, LOW);
  }



  else if (t == 54)
  {
    digitalWrite(4, LOW);
  }




}

Credits

Keval Pankhaniya

Keval Pankhaniya

1 project • 5 followers
cout << "Electronics Enthusiastic" <<endl;
Contact
Jainam shah

Jainam shah

1 project • 1 follower
Contact
Viraj rawal

Viraj rawal

1 project • 1 follower
I am working at Hitachi -Hirel power Electronics Pvt. Ltd as Research and Development Engineer since june 2016
Contact

Comments