Kalyan Prusty
Published © GPL3+

Home Automation Using XBee and Arduino

This project is all about controlling appliances via xBee communication in Proteus (a simulation software).

BeginnerWork in progress1.5 hours8,066
Home Automation Using XBee and Arduino

Things used in this project

Software apps and online services

Arduino IDE
Arduino IDE
proteus
Virtual Serial Port Driver
this driver connectes the ports (COM ports) virtually

Story

Read more

Schematics

Schematics for Home System

Schematics for Control System

Code

Code for Home System

Arduino
#include<LiquidCrystal.h>

LiquidCrystal lcd(A0,A1,A2,A3,A4,A5);

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);

for(int i = 2;i<=7;i++){
  pinMode(i,OUTPUT);
}
pinMode(9,INPUT);
pinMode(10,INPUT);
}

int i,state = 0;
int high9 = 0,high10 = 0;
void loop() {
  // put your main code here, to run repeatedly:
 if(Serial.available()>0){
  
  i  = Serial.parseInt();

  changeState(i);
 }
 if(digitalRead(9)==1 && high9 ==0){
  Serial.print(91);
  high9 = 1;
 }
 else if(digitalRead(9)==0 && high9 == 1){
  Serial.print(90);
  high9 = 0;
 }
 else if(digitalRead(10)==1 && high10 ==0){
  Serial.print(101);
  high10 = 1;
 }
 else if(digitalRead(10)==0 && high10 == 1){
  Serial.print(100);
  high10 = 0;
 }
}
void changeState(int i){
  state = digitalRead(i+2);
    digitalWrite(i+2,!state);
    Serial.print(12);
}

Code for Control System

Arduino
#include <Keypad.h>
#include<LiquidCrystal.h>

LiquidCrystal lcd(A0,A1,A2,A3,A4,A5);
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'#','0','*'}
};
byte rowPins[ROWS] = {2,3,4,5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6,7,8}; //connect to the column pinouts of the keypad

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

void setup(){
  Serial.begin(9600);
  for(int i=2;i<9;i++){
    pinMode(i,OUTPUT);
  }
}

void loop(){
  char key = keypad.getKey();

  if (key != NO_KEY){
    Serial.print(key);
  }
  if(Serial.available()>0){
    int k = Serial.parseInt();
    if(k == 91){
      lcd.setCursor(0,0);
      lcd.print("GAS DETECTED");
    }
    else if(k == 90){
      lcd.setCursor(0,0);
      lcd.print("GAS NOT DETECTED");
    }
    else if(k == 101){
      lcd.setCursor(0,1);
      lcd.print("FLAME DETECTED");
    }
    else if(k == 100){
      lcd.setCursor(0,1);
      lcd.print("FLAME NOT DETECTED");
    }
  }
}

Credits

Kalyan Prusty

Kalyan Prusty

1 project • 14 followers

Comments