Home Automation Step by Step using Wemos D1 Mini with PCB Design

A few weeks back we published a tutorial “Home Automation using Raspberry Pi” in rootsaid.com which was well received among hobbyists and college students. Then one of our members came up with an Arduino Home Automation system using NodeMCU.

Arduino Home Automation System

Here we will be showing you how to build an Arduino Home Automation System that can control electrical devices like lights, fans, garage doors etc using our mobile phone from anywhere around the world. To build this DIY Home Automation System, All you need is an Wemos D1 Mini Board, some relays and an android phone.

Online PCB Manufacturer – JLCPCB

JLCPCB is one of the best Online PCB manufacturing company from where you can order PCBs online without any hassle. The company works 24 hours a day, 7 days a week nonstop. With their high tech machinery and automated work stream, they can manufacture huge quantities of high-class PCBs within hours.

JLCPCB can develop PCBs of various complexity. They develop Simple and cheap PCBs with Single layer board for hobbyists and enthusiasts as well as complex multi layer board for high standard industrial applications. JLC works with large product manufacturers and may be the PCB of devices you are using such as laptop or mobile phones were made at this factory.

Step 1 – Drawing Schematics using EasyEDA

To draw circuits and design PCBs, we have online PCB designing tools from EasyEDA, provides all the necessary capability for online PCB Design and PCB Printing of Circuit Boards with hundreds of components and multiple layers with thousands of tracks.

I drew a circuit in EasyEDA which included all the components on the breadboard version – the Wemos D1 Mini, Relay, Regulator and LEDs which are connected to the digital pin of the Wemos.

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. 

Voltage Regulator

I also added a 7805, regulator which will helped me to provide an input voltage between 7 volt and 35 volt in the input, so that I can use a 5 volt USB power supply, 9-volt battery or even a 12 volt lithium polymer battery without any issues.

I also added some indicator LEDs that will let me know if something stopped working. You will find the circuit to my EasyEDA below.

PCB Layout

Next, designing the PCB. PCB Layout is actually a significant part of PCB Design, we use PCB Layouts to make PCBs from schematics. I designed a PCB where I could solder all the components together.

For that, first save the schematics and from the top tool list, Click on the convert button and Select “Convert to PCB”. This will open up a window like this. Here, you can place the components inside the boundary and arrange them the way you want. The easy way route all the component is “auto-route” process. For that, Click on the “Route” Tool and Select “Auto Router”.

This will open up an Auto Router Config Page where you can provide details such as clearance, track width, layer information etc. Once you have done that, click on “Run”.

Thats it guys, your layout is now complete. This a dual layer PCB which means the routing is there in both side of the PCB. You can now download the Gerber file and use it to manufacture your PCB from JLCPCB.

Step 2 – Getting the PCB Manufactured from JLCPCB

JLCPCB is a PCB manufacturing company with a full production cycle. Which means they start from “A” and finishes with “Z” of PCB manufacturing process. From raw materials to finished products, everything is done right under the roof.

Go to JLC PCBs website and create a free account. Once you have successfully created an account, Click on “Quote Now” and upload your Gerber File.

Gerber File contains information about your PCB such as PCB layout information, Layer information, spacing information, tracks to name a few.Below the PCB preview, you will see so many options such as PCB Quantity, Texture, Thickness, Color etc. Choose all that are necessary for you.

Once everything is done, click on “Save To Cart”. In the next page, you can choose a shipping and payment option and Check Out Securely. You can either use Paypal or Credit/Debit Card to pay.

Thats it guys. Its Done. The PCB will be manufactured and you will received with in the mentioned time period.

Step 3 – Setting Up the UDP Listener on Wemos D1 Mini

Now all you have to do is setup a listener on the Wemos. 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(D5, OUTPUT);
    pinMode(D6, OUTPUT);
    pinMode(D7, 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(strcmp(packet, "device1on") == 0) 
{    
digitalWrite(D0, HIGH);     
Serial.printf("Device 1 On"); 
} 
else if(strcmp(packet, "device1off") == 0) 
{    
digitalWrite(D0, LOW);     
Serial.printf("Device 1 Off");    
Serial.println(""); }
 else if(strcmp(packet, "device2on") == 0)
     {
        digitalWrite(D5, HIGH); 
        Serial.printf("Device 2 On");
        Serial.println("");
 }
 else if(strcmp(packet, "device2off") == 0)
     {
        digitalWrite(D5, LOW); 
        Serial.printf("Device 2 Off");
        Serial.println("");
 }
 else if(strcmp(packet, "device3on") == 0)
     {
        digitalWrite(D6, HIGH); 
        Serial.printf("Device 3 On");
        Serial.println("");
 }
 else if(strcmp(packet, "device3off") == 0)
     {
        digitalWrite(D6, LOW); 
        Serial.printf("Device 3 Off");
        Serial.println("");
 } 
else if(strcmp(packet, "device4on") == 0) 
{    
digitalWrite(D7, HIGH);     
Serial.printf("Device 4 On");    
Serial.println(""); } 
else if(strcmp(packet, "device4off") == 0) 
{    
digitalWrite(D7, LOW);     
Serial.printf("Device 4 Off");    
Serial.println(""); 
} 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.

Whats Next?

Making an Arduino Robot

How about making cool Robot with this Remote Controller? Check out this Bad Boy – The Robotin6.

It is an Off Road 6 Wheel Drive Crawler which can be remotely controlled using an Arduino remote controller. Here also we will be using the same robot, only thing different here will be the code which we will upload to the robots Arduino. Click Here for Complete Tutorial.

Similar Posts

Leave a Reply

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