Hardware components | ||||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
Software apps and online services | ||||||
| ||||||
|
To improve the idea and decrease the cost of home automation, this project used a platform to manage the home automated devices as service accessed via the cloud using firebase cloud service. It uses the cheap ESP8266 nodemcu interfaces with temperature and humidity sensor, PIR motion sensor, light sensor and relay to monitor the ambient condition of a home and to control the socket and light switches. The cloud also host machine learning algorithm using SVM written in javascript to collect the ambient data, time, date, and human interaction with the switches to learn from human behaviour, so as to help in control of the home load points from the experience.
The project also involves the development of mobile app using MIT app inventor that helps user to control and monitor the load points ubiquitously and also to visualize the ambient condition of the home where ever the user is.
#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);
}
#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);
}
Comments