Daniel Abode
Created August 10, 2017

Home Dot

Cloud based application of IoT and machine learning to home automation. Esp8266 nodeMCU + relays + sensors:: firebase cloud :: mobile app.

12
Home Dot

Things used in this project

Hardware components

NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
RobotGeek Relay
RobotGeek Relay
×1
TinyShield Ambient Light Sensor
TinyCircuits TinyShield Ambient Light Sensor
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Firebase
Google Firebase

Story

Read more

Schematics

Home Automation

To be use with the mobile app

Code

Home Automation code

Arduino
It has to do with firebase cloud database also
#include <Wire.h>
#include <MAX44009.h>
#include <dht11.h>  
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
MAX44009 light;
#define FIREBASE_HOST "home-automation-project-f1ed1.firebaseio.com"
#define FIREBASE_AUTH "sF4fmvhzuSem8q75XYnjzbmi7W6pktTTGPTNfUAb"
#define WIFI_SSID "dan"
#define WIFI_PASSWORD "Danick007@ROSS"

 dht11 DHT11;
const int Light1 = D4;
const int Socket1 = D6;
const int Socket2 = D7;
const int PIRpin = D8;
const int WifiIndicator = D3;


String HomePath = "HomeData";
String path = HomePath + "/States";

  void setupPins(){
    pinMode(Light1, OUTPUT);
    pinMode(Socket1, OUTPUT);
    pinMode(Socket2, OUTPUT);
    pinMode(PIRpin,INPUT);
    pinMode(WifiIndicator,OUTPUT);
    }

    void setupWifi(){
      WiFi.begin(WIFI_SSID,WIFI_PASSWORD);
      Serial.println("Hey I 'm connecting...");
      while(WiFi.status()!= WL_CONNECTED ){
        Serial.println(".");
        delay(500);
        }
        Serial.println();
        Serial.println("I am connected and my IP address is ");
        Serial.println(WiFi.localIP()); 
    }

      void setupFirebase()
      {
        Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
        if(Firebase.failed()){
          Serial.print("setting/number failed:");
          Serial.println(Firebase.error());
          return;
          } 
      }


void setup() {
  // put your setup code here, to run once:
light.begin();
Serial.begin(9600);
setupPins();
setupWifi();
setupFirebase();
DHT11.attach(D5);
Serial.println("DHT11 TEST PROGRAM ");  
Serial.print("LIBRARY VERSION: ");  
Serial.println(DHT11LIB_VERSION);
}

  void Switching()
  {
    
    FirebaseObject object = Firebase.get(path);
  if(Firebase.failed()){
    Serial.print("Failed to access path");
    return;
    }
  
   String LightState = object.getString("LightState");
   String Socket1State = object.getString("Socket1State");
   String Socket2State = object.getString("Socket2State");
  Serial.println(LightState);
  Serial.println(Socket1State);
  Serial.println(Socket2State);
  delay(1000);
  if(LightState == "true"){
  digitalWrite(Light1,HIGH);
  Firebase.setInt("HomeData/States/LightStateConfirm",1);
  }
  else{
  digitalWrite(Light1,LOW);
  Firebase.setInt("HomeData/States/LightStateConfirm",0);
  }
   if(Socket1State == "true"){
  digitalWrite(Socket1,HIGH);
  Firebase.setInt("HomeData/States/Socket1StateConfirm",1);
   }
  else{
  digitalWrite(Socket1,LOW);
  Firebase.setInt("HomeData/States/Socket1StateConfirm",0);
  }
   if(Socket2State == "true"){
  digitalWrite(Socket2,HIGH);
Firebase.setInt("HomeData/States/Socket2StateConfirm",1);
   }
  else{
  digitalWrite(Socket2,LOW);
  Firebase.setInt("HomeData/States/Socket2StateConfirm",0);
  }
  }

    float LightReading()
    {
      float x = light.get_lux();
      return x;
    }

void loop() {
  // put your main code here, to run repeatedly:
Switching();
float lightLevel = LightReading();
int tempValue = 0;
int humValue = 0;
Serial.println("\n"); 
int chk = DHT11.read();  
  switch (chk)  
  {  
   case 0:  
   Serial.print("Humidity (%): "); 
   humValue = (DHT11.humidity);
   tempValue = (DHT11.temperature);  
   break;  
   case -1: Serial.println("Checksum error"); break;  
   case -2: Serial.println("Time out error"); break;  
   default: Serial.println("Unknown error"); break;  
  }  

Firebase.setFloat("HomeData/States/Light Intensity", lightLevel);
Firebase.setInt("HomeData/States/Temperature Value",tempValue);
Firebase.setInt("HomeData/States/Humidity Value", humValue);
Serial.print("Light Level : ");
Serial.println(lightLevel);
Serial.print("Temperature value: ");
Serial.println(tempValue);
Serial.print("Humidity value: ");
Serial.println(humValue);
Switching();
delay(1000);
}

Home Automation

Arduino
#include <Wire.h>
#include <MAX44009.h>
#include <dht11.h>  
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
MAX44009 light;
#define FIREBASE_HOST "home-automation-project-f1ed1.firebaseio.com"
#define FIREBASE_AUTH "sF4fmvhzuSem8q75XYnjzbmi7W6pktTTGPTNfUAb"
#define WIFI_SSID "dan"
#define WIFI_PASSWORD "Danick007@ROSS"

 dht11 DHT11;
const int Light1 = D4;
const int Socket1 = D6;
const int Socket2 = D7;
const int PIRpin = D8;
const int WifiIndicator = D3;


String HomePath = "HomeData";
String path = HomePath + "/States";

  void setupPins(){
    pinMode(Light1, OUTPUT);
    pinMode(Socket1, OUTPUT);
    pinMode(Socket2, OUTPUT);
    pinMode(PIRpin,INPUT);
    pinMode(WifiIndicator,OUTPUT);
    }

    void setupWifi(){
      WiFi.begin(WIFI_SSID,WIFI_PASSWORD);
      Serial.println("Hey I 'm connecting...");
      while(WiFi.status()!= WL_CONNECTED ){
        Serial.println(".");
        delay(500);
        }
        Serial.println();
        Serial.println("I am connected and my IP address is ");
        Serial.println(WiFi.localIP()); 
    }

      void setupFirebase()
      {
        Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
        if(Firebase.failed()){
          Serial.print("setting/number failed:");
          Serial.println(Firebase.error());
          return;
          } 
      }


void setup() {
  // put your setup code here, to run once:
light.begin();
Serial.begin(9600);
setupPins();
setupWifi();
setupFirebase();
DHT11.attach(D5);
Serial.println("DHT11 TEST PROGRAM ");  
Serial.print("LIBRARY VERSION: ");  
Serial.println(DHT11LIB_VERSION);
}

  void Switching()
  {
    
    FirebaseObject object = Firebase.get(path);
  if(Firebase.failed()){
    Serial.print("Failed to access path");
    return;
    }
  
   String LightState = object.getString("LightState");
   String Socket1State = object.getString("Socket1State");
   String Socket2State = object.getString("Socket2State");
  Serial.println(LightState);
  Serial.println(Socket1State);
  Serial.println(Socket2State);
  delay(1000);
  if(LightState == "true"){
  digitalWrite(Light1,HIGH);
  Firebase.setInt("HomeData/States/LightStateConfirm",1);
  }
  else{
  digitalWrite(Light1,LOW);
  Firebase.setInt("HomeData/States/LightStateConfirm",0);
  }
   if(Socket1State == "true"){
  digitalWrite(Socket1,HIGH);
  Firebase.setInt("HomeData/States/Socket1StateConfirm",1);
   }
  else{
  digitalWrite(Socket1,LOW);
  Firebase.setInt("HomeData/States/Socket1StateConfirm",0);
  }
   if(Socket2State == "true"){
  digitalWrite(Socket2,HIGH);
Firebase.setInt("HomeData/States/Socket2StateConfirm",1);
   }
  else{
  digitalWrite(Socket2,LOW);
  Firebase.setInt("HomeData/States/Socket2StateConfirm",0);
  }
  }

    float LightReading()
    {
      float x = light.get_lux();
      return x;
    }

void loop() {
  // put your main code here, to run repeatedly:
Switching();
float lightLevel = LightReading();
int tempValue = 0;
int humValue = 0;
Serial.println("\n"); 
int chk = DHT11.read();  
  switch (chk)  
  {  
   case 0:  
   Serial.print("Humidity (%): "); 
   humValue = (DHT11.humidity);
   tempValue = (DHT11.temperature);  
   break;  
   case -1: Serial.println("Checksum error"); break;  
   case -2: Serial.println("Time out error"); break;  
   default: Serial.println("Unknown error"); break;  
  }  

Firebase.setFloat("HomeData/States/Light Intensity", lightLevel);
Firebase.setInt("HomeData/States/Temperature Value",tempValue);
Firebase.setInt("HomeData/States/Humidity Value", humValue);
Serial.print("Light Level : ");
Serial.println(lightLevel);
Serial.print("Temperature value: ");
Serial.println(tempValue);
Serial.print("Humidity value: ");
Serial.println(humValue);
Switching();
delay(1000);
}

Credits

Daniel Abode

Daniel Abode

0 projects • 0 followers

Comments