Smart Home - DIY - IoTfied

by Projectsforallr in Circuits > Remote Control

1463 Views, 0 Favorites, 0 Comments

Smart Home - DIY - IoTfied

image.jpg
Home Automation working model

As technology is advancing so houses are also getting smarter. Modern houses are gradually shifting from conventional switches to centralized control system, involving remote controlled switches. Presently, conventional wall switches located in different parts of the house makes it difficult for the user to go near them to operate. Even more it becomes more difficult for the elderly or physically handicapped people to do so. Remote controlled home automation system provides a most modern solution with smart phones.

The objective of this project is to develop a home automation system using NodeMCU board with Internet being remotely controlled by mobile.

Lets start with Live Demo: https://youtu.be/sz1L6wLNSsw

In order to achieve this, a relay module is interfaced to the NodeMCU board at the receiver end while on the transmitter end, a GUI application on the cell phone sends ON/OFF commands to the receiver where loads are connected. By touching the specified location on the GUI, the loads can be turned ON/OFF remotely through this technology.

Equipment Controlled:
Gas Lighting Fan Pump All the above devices can be switch on and off from smart phone app from any where, any time. It can be configured to run locally within home in case internet connectivity not available.

Solder/connect 4 Devices to NodeMCU Driver Board Like Below

schematic.jpg

Upload Code Given

// Download dependency libraries from: https://github.com/esp8266/Arduino

// Open Arduino IDE -> Select NodeMCU board under tools -> Choose connected port -> Compile and Upload below code and open Serial Monitor.

//This example will set up a static IP - in this case 192.168.1.99
//More information - mail us : projectsforall777@gmail.com //Website: www.labsforall.com #include

////////////////////// // WiFi Definitions // //////////////////////

const char WiFiAPPSK[] = "12345678";

int gas = D5;

int light = D6;

const int ANALOG_PIN = A0; // The only analog pin on the Thing

//for nodemcu // Pump const int IN1 = D0; const int IN2 = D1;

// DC Fan const int IN3 = D2; const int IN4 = D3;

WiFiServer server(80);

IPAddress apIP(192, 168, 1, 99); // where xx is the desired IP Address

void setup() { Serial.begin(9600); delay(10); Serial.print(F("Setting static ip to : ")); Serial.println(apIP);

WiFi.mode(WIFI_AP); WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0)); // subnet FF FF FF 00 WiFi.softAP("sunshinelabz", WiFiAPPSK); // Connect to WiFi network Serial.println(); // // Start the server server.begin(); Serial.println("Server started");

pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT);

pinMode(IN3, OUTPUT); pinMode(IN4, OUTPUT);

pinMode(gas, OUTPUT); pinMode(light, OUTPUT);

Fan_Off(); Pump_Off(); Gas_Off(); Light_Off(); }

void Fan_On() { digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW); }

void Fan_Off() { digitalWrite(IN1, LOW); digitalWrite(IN2, LOW); }

void Pump_On() { digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW); }

void Pump_Off() { digitalWrite(IN3, LOW); digitalWrite(IN4, LOW); }

void Gas_On() { digitalWrite(gas, HIGH); }

void Gas_Off() { digitalWrite(gas, LOW); }

void Light_On() { digitalWrite(light, HIGH); }

void Light_Off() { digitalWrite(light, LOW); } void loop() { // Check if a client has connected WiFiClient client = server.available(); if (!client) { return; }

// Read the first line of the request String req = client.readStringUntil('\r'); Serial.println(req); client.flush();

// Match the request int val = -1; // We'll use 'val' to keep track of both the // request type (read/set) and value if set.

Serial.print("Full request: "); Serial.println(req);

Serial.print("Index of /status1=1 is: "); Serial.println(req.indexOf("/status1=1"));

Serial.print("Index of /status1=0 is: "); Serial.println(req.indexOf("/status1=0"));

Serial.print("Index of ?cmd=0 is: "); Serial.println(req.indexOf("?cmd=0"));

if (req.indexOf("/status1=1") == 4) { Serial.println("Fan On"); Fan_On(); } else if (req.indexOf("/status1=0") == 4) { Serial.println("Fan Off"); Fan_Off(); }

else if (req.indexOf("/status2=1") == 4) { Serial.println("Pump On"); Pump_On(); }

else if (req.indexOf("/status2=0") == 4) { Serial.println("Pump Off"); Pump_Off(); }

else if (req.indexOf("/status3=1") == 4) { Serial.println("gas On"); Gas_On(); }

else if (req.indexOf("/status3=0") == 4) { Serial.println("gas off"); Gas_Off(); }

else if (req.indexOf("/status4=1") == 4) { Serial.println("light On"); Light_On(); }

else if (req.indexOf("/status4=0") == 4) { Serial.println("light off"); Light_Off(); }

client.flush();

// Prepare the response. Start with the common header: String s = "HTTP/1.1 200 OK\r\n"; s += "Content-Type: text/html\r\n\r\n"; s += "\r\n \r\n"; // If we're setting the LED, print out a message saying we did if (val >= 0) { s += "LED is now "; s += (val)?"on":"off"; } else if (val == -2) { // If we're reading pins, print out those values: s += "Analog Pin = "; s += String(analogRead(ANALOG_PIN)); s += "
"; // Go to the next line. //s += "Digital Pin 12 = "; //s += String(digitalRead(DIGITAL_PIN)); } else { s += "Invalid Request.
Try /led/1, /led/0, or /read."; } s += "

\n";

// Send the response to the client client.print(s); delay(1); Serial.println("Client disonnected");

// The client will actually be disconnected // when the function returns and 'client' object is destroyed }

Down and Configure Android App Below

Provide Power Supply DC(5 to 6v) to NodeMCU Driver As Well As Rated Power Supply to NodeMCU Board.

Go to Mobile -> Setting -> Wifi -> Connect to Hotspot Name: Sunshinelabz. Password Is Embedded in Code

Open ESP8266 Wifi App. Enter IP: 192,168.1.99. Make Sure It Shows Connected to Above Hot Spot. Port Is 80

Each 4 Device You Want to Control Name Then in App Setting Dash Board. If Names Don't Reflect. Logout and Re-open the Application

Test. Make Sure to Check All Connectivity, No Short Circuits and Water Is Poured in the Container Water Pump Is Placed

Advantages and Limitation

Advantages:

1. No manual intervention needed to control appliances / devices.

2. Effective power utilization.

3. Long lif4 of devices as no physically contact.

Limitation:

1. Initial setup is costlier

2. Need of internet connectivity needed in order to control remotely.



Note: If you want to control devices from any where in world you do port forwarding from your wifi router. This is not covered in this article.