home automation using iot

This is the codings for home automation program
Here we control 4 relays ,water level induction ,thermal and humanity  , motion detection
and it is send to could (adafruit io) and it also receive the codings using python program.
the arduino program is below.......
for reference visit the video.... my automation video(youtube video link)

                             arduino program

#include <dht.h>
#define dht_apin A0
dht DHT;

int data;
int LED=13;
int fan=5;
int motor = 9;
int light, waterup, waterdown, PIR, thermal,humidity;

//output of pir pin2 and light sensor pin6
//waterup output A1 and waterdown A2
//thermal output A0

void setup() { 
  Serial.begin(9600);                               //initialize serial COM at 9600 baudrate
  pinMode(LED, OUTPUT); //totally free pins are 3,4,7,8;
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(motor, OUTPUT);
  pinMode(fan, OUTPUT);
  pinMode(6, INPUT);
  pinMode(2, INPUT);
  pinMode(A0, INPUT);
  pinMode(A1, INPUT);
  pinMode(A2, INPUT);

  Serial.println("hai internet");
  
}
void loop() {
  DHT.read11(dht_apin);
  PIR = digitalRead(2);
  light = digitalRead(6);
  thermal = DHT.temperature;
  humidity = DHT.humidity;
  waterup = analogRead(A1);
  waterdown = analogRead(A2);
if (Serial.available()>0)    //whatever the data that is coming in serially and assigning the value to the variable “data”

data = Serial.read();
if (data == '0')
{
  digitalWrite (LED, LOW);
  Serial.println("RELAY1 is off");
}
else if (data == '1')
{
  digitalWrite (LED, HIGH);
  Serial.println("RELAY1 is on");
}
else if (data == '2')
{
  digitalWrite (12, LOW);
  Serial.println("RELAY2 is off");
}
else if (data == '3')
{
  digitalWrite (12, HIGH);
  Serial.println("RELAY2 is on");
}
else if (data == '4')
{
  digitalWrite (11, LOW);
  Serial.println("RELAY3 is off");
}
else if (data == '5')
{
  digitalWrite (11, HIGH);
  Serial.println("RELAY3 is on");
}
else if (data == '6')
{
  digitalWrite (10, LOW);
  Serial.println("RELAY4 is off");
}
else if (data == '7')
{
  digitalWrite (10, HIGH);
  Serial.println("RELAY4 is on");
}
}
else if(data=='8')
  {
    //Serial.println("all on");
    if(waterdown <= 800)
    {
      digitalWrite(motor,HIGH);
      //Serial.println("motor on");
    }
    else if(waterup >= 900)
    {
      digitalWrite(motor,LOW);
      //Serial.println("motor off");
    }
    if(PIR == 1)
    {
     digitalWrite(fan,HIGH);
     if(light == 1)
     {
       digitalWrite(LED,HIGH);
     }
     else if (light == 0)
     {
      digitalWrite(LED,LOW);
     }
  }
  else if(PIR == 0)
  {
   digitalWrite(LED,LOW);
   digitalWrite(fan,LOW);
  }
 }
 else if(data=='9')
 {
  if(PIR == 0 || PIR == 1 )
  {
   digitalWrite(LED,LOW);
   digitalWrite(fan,LOW);
   digitalWrite(motor,LOW);
  } 
 }
Serial.print(waterup);
Serial.print(" ");
Serial.print(waterdown);
Serial.print(" ");
Serial.print(thermal);
Serial.print(" ");
Serial.println(humidity);
delay(1000);
}
_______________________________________________________________________

and we also run a python program in Laptop  for send and receive comments..
the python program is given below......

                               python program

import serial, time
from Adafruit_IO import *
aio=Client('XXXXXXXXX').... #use your key
ser = serial.Serial('COM7' , 9600) #arduino connecting port
value=ser.readline().decode('ascii')
print(value)
while(1==1):
    value=ser.readline().decode('ascii')
    separate = value.split()
    aio.send('temperature',separate[2])
    aio.send('humidity',separate[3])
    data = aio.receive('Test')
    val=(data.value)
    print(val)
    if(val == '0'):
        ser.write( '0'.encode('utf-8'))
        print('REALY1 is off')
    elif(val == '1'):
        ser.write( '1'.encode('utf-8'))
        print('REALY1 is on')
    elif(val == '2'):
        ser.write( '2'.encode('utf-8'))
        print('REALY2 is off')
    elif(val == '3'):
        ser.write( '3'.encode('utf-8'))
        print('REALY2 is on')
    elif(val == '4'):
        ser.write( '4'.encode('utf-8'))
        print('REALY3 is off')
    elif(val == '5'):
        ser.write( '5'.encode('utf-8'))
        print('REALY3 is on')
    elif(val == '6'):
        ser.write( '6'.encode('utf-8'))
        print('REALY4 is off')
    elif(val == '7'):
        ser.write( '7'.encode('utf-8'))
        print('REALY4 is on')
    elif(val == 'ON'):
        ser.write( '8'.encode('utf-8'))
        print (separate[0])
        print (separate[1])
        print('ALL ACTIVITY is on')
    elif(val == 'OFF'):
        ser.write( '9'.encode('utf-8'))
        print('ALL ACTIVITY is off')
time.sleep(1)    
   ____________________________________________________________________________
run this program in your lap or raspberry pi [python version (3.6.3)]


Comments

Popular posts from this blog

CHATBOT programming tutorial in tamil

programing part for petrol level measuring in tamil

using millis() in ultrasonic sensor program in tamil