Arduino Home Automation Cheap DIY Using NodeMCU

| |

A few days back we published an article “Home Automation using Raspberry Pi” in our blog which was well received among hobbyists. Now we have brought up with a Home Automation system using Arduino and NodeMCU.

In this post, we will explained how to build an Arduino Home Automation System that can control electrical appliances such as lights, fans, gates etc suing our mobile phone from anywhere around the world. All you need is a Node MCU board, some relays and an android phone to build our own Home Automation system using Arduino . Lets get started.

Components Required

Click on them to purchase from amazon

The Relay

Relays are switching circuits that can close and break circuits mechanically. That means it can control an electrical circuit by closing and breaking connections in that circuit.

As you can see, there are mainly 5 terminals in a relay. Two for energizing the coil, one Common terminal, a Normally Closed terminal which will be connected to the Common terminal when the coil is not energized and a Normally Open terminal which will be in contact with the Common terminal when the coil is energized.

This is how the relay works. In our case, we will be connecting

  • GPIO pins to One End of Coil
  • Ground to other End of Coil
  • Phase of Main Power Supply to The Common terminal or Pole
  • One Terminal of bulb (Or other electrical Appliance) to Normally Open Terminal
  • And the Other Terminal of Bulb to Neutral Point of Main Power Supply

 

Depending upon the output of arduino board, you can select your relay. Since the Output of Node MCU GPIO pins are 3.3V, you will have to buy a 3.3V Relay. You can purchase the relay board of 4 relays that is compatible with Raspberry Pi from here or click on the image.

NodeMCU

Node MCU is an open source platform that is specifically designed for IOT projects. This tiny little board is based on ESP8266 WiFi module which is specifically designed for working with or woithout micro controllers which uses Lua scripting language.

This module have 10 GPIO, all of which can be used as PWM, IIC, 1-Wire and Analog to Digital Converters all in one board. It also has a PCB antenna etched in the board, which significantly improves the connectivity.

Home Automation system using Arduino

Steps

Step 1 – Download, Install and Setup Arduino IDE

This little board can be easily programmed using the worlds most user friendly Open Source Platform – Arduino. This will be explained in detail below. So, to get started with our Home Automation system using Arduino, first thing to do is download and install Arduino IDE from Here.
Follow the below tutorial and setup Node MCU in your Arduino IDE.

 

NodeMCU – Set up Arduino IDE and Start using WiFi

Step 2 – Connections

We powered Node MCU through USB with 5V.

For this project we will be using 4 IO pins to control the devices. D0, D1, D2 and D3 all goes directly to the 4 relays input.

Best WiFi Routers of 2018

Here is a list of World’s Best WiFi Routers of the year 2018. Make sure you grab one of them for High speed, Long Range, and Stable Internet connection.

http://www.cuteoffers.com/technology/best-wifi-routers-2018/

Step 3 – Setting Up the UDP Listener on Node MCU

Now all you have to do is setup a listener on the NodeMCU. Download the sketch from the link below. Download

Code Explained
const char* ssid = "rootsaid";
const char* password = "testpassword";

This is where you enter the ESSID and Passphrase of your network. Before uploading, make sure that you change values to SSID and Passphrase of your WiFi network.

unsigned int port = 5005;

This is the port, NodeMCU will be listening for incoming UDP Packets

pinMode(D0, OUTPUT);
pinMode(D1, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D3, OUTPUT);

The 4 pins we will connecting to the relay input

 WiFi.begin(ssid, password);
 while (WiFi.status() != WL_CONNECTED)
 {
 delay(500);
 Serial.print(".");
 }
 Serial.println("Connection Successful");
 Udp.begin(port);
 Serial.printf("Listener started at IP %s, at port %d n", WiFi.localIP().toString().c_str(), port);
}

Connect to the WiFi network using predefined ESSID and Passphrase and set up a UDP listener in the predefined port

int packetSize = Udp.parsePacket();
 if (packetSize)
 {
 Serial.printf("Received %d bytes from %s, port %dn", packetSize, Udp.remoteIP().toString().c_str(), Udp.remotePort());
 int len = Udp.read(packet, 255);
 if (len > 0)
 {
 packet[len] = 0;
 }
Serial.printf("UDP packet contents: %sn", packet);

Save the UDP packet contents to the variable ‘packet’ and print its value

 if(packet=="device1on")
 {
 digitalWrite(D0, HIGH); 
 }
 else if(packet=="device1off")
 {
 digitalWrite(D0, LOW); 
 }
 else if(packet=="device2on")
 {
 digitalWrite(D1, HIGH); 
 }
 else if(packet=="device2off")
 {
 digitalWrite(D1, LOW); 
 }
 else if(packet=="device3on")
 {
 digitalWrite(D2, HIGH); 
 }
 else if(packet=="device3off")
 {
 digitalWrite(D2, LOW); 
 }
 else if(packet=="device3on")
 {
 digitalWrite(D3, HIGH); 
 }
 else if(packet=="device3off")
 {
 digitalWrite(D3, LOW); 
 }
 else
 {
 Serial.printf("Invalid"); 
}

Turns the output of the pins to HIGH or LOW depending upon the packets received.

Step 4 – Install RootSaid WiFi Command Center from Google PlayStore

RootSaid WiFi Command Center is a simple light weight android application that can be used to control robots and Raspberry pi and Arduino Home Automation over WiFi. All you have to do is connect your mobile phone to the network, enter the IP address and Port of the server (the NodeMCU of our Home Automation system using Arduino) and control it using the On Off buttons. Click here to know more about this App.

Click Here to Download this app from Playstore.

Step 5

Now all you have to do is start the App, enter the IP address of the Pi and port it is listening to (5005).

Load the IP and Port using the link button and navigate to the Home Automation Tab.

Thats it, your Home Automation system using Arduino is now ready. You can now control devices connected to your Node MCU using this simple app and turn it on and off.[AdSense-B]

Rate the Project

Did you find this page useful? Help us to improve by rating this page.

[RICH_REVIEWS_FORM]
[RICH_REVIEWS_SNIPPET stars_only=”true”]

 

Similar Posts

2 Comments

  1. NudeMCU guy with an iPhone and no android devices says:

    Very cool. Are there any iphone apps similar to the one mentioned in this article?

Leave a Reply

Your email address will not be published. Required fields are marked *