4 Simple Steps to Make Your Home Come to Life for Under $10
Control your home like never before using DIY home automation
6 min read
Photo by Florian Schmidinger on Unsplash
This is part one of a two-part series. In this part, I will tell you how you can control any device using your smartphone or voice commands from either Google Assistant or Alexa. The next part will be about how to use gestures to control any of your home appliances using Computer Vision and Raspberry Pi.
Here’s the link to my funny programming YouTube video
Why would you want to automate?
Much more efficient
Ability to control any device from anywhere in the world
Insanely useful for lazy chaps like me
Things you will need
ESP8266-Node MCU (Microcontroller) ($2 in aliexpress)
Breadboard power supply or any other 5V source ($0.71 in aliexpress)
Relay board — 2 channel, 4 channel, 8 channel according to your needs ($1 in aliexpress)
Jumper Wires — Female to Female (under $1 in aliexpress)
I will explain the use of each of these items below:
Taking a Look at the Required Components
The Relay board uses electromagnets to make and break the circuits. This one here has 4 channels, but you can easily buy up to 16 channels. The number of channels relates to the number of devices that you can connect at once. This relay can handle up to 10A 250V AC. There are 4 input pins (IN 1–4) to control 4 relays. You can use Node-MCU to power the board, but it is a good idea to isolate the board from the micro-controller, to do that connect voltage pin from Node-MCU to VCC and separate 5V power supply to JD-VCC and GND.
This is where the breadboard power supply comes in.
Breadboard power supply
Breadboard power supply
The breadboard power supply can output 5V or 3.3V or both. There are 2 output pins and 2 jumper pins to set the configuration. It requires 6.5V–12V to function. If you are using both the pins, use the 12V input to deal with voltage drops. You can also power it using USB. There is a switch to turn on and off the device.
ESP8266 Node MCU (Microcontroller)
There is a lot I can talk about when it comes to Node MCU, but I will stick to the details related to this project.
There are 16 GPIO pins in Node MCU, which can receive and send signals. Node MCU can communicate with other APIs and devices using WiFi. Node MCU required 3.3 V to power up and it can be done so using Micro-USB or Vin and GND pins. You can use pins from D1 to D8 to send signals to the relay board. We can use Arduino IDE to program Node MCU and use Blynk to send commands using our phone. We can then connect Blynk to IFTTT to connect it to Google Assistant.
Now, let’s hook them all up!
Connecting the Pieces
Step 1 — Programming Node MCU
First, we need to program Node MCU. We need to connect it to Blynk, an IoT platform, which can send commands from smartphone to Node MCU.
Make sure you have Arduino IDE installed. Now we need to add our Node MCU board to the Arduino board manager. To do this, go to Arduino > Preferences and paste this -
in “Additional Boards Manager URL’s”, and press ok. Now go to boards manager, search “esp8266”, and install it.
Now click on Tools > boards > ESP8266 boards > Node MCU 1.0 (ESP-12E Module). Paste the above code in Arduino IDE, put your authentication code here.
char auth = “PUT YOUR AUTHENTICATION CODE HERE”;
To find the authentication code, use the following instructions-
Open Blynk app and create your account. Create a new project and select Node MCU as the device, choose the connection type as WiFi then click on create. This will send the auth token to your mail. For more details follow this- Getting Started In order to use Blynk app you would need: Hardware that works with Blynk. Check the full list of supported hardware…help.blynk.cc
Finally, put your WiFi SSID here-
char ssid = “YOUR WIFI”;
and your WiFi password here-
char pass = “WIFI PASSWORD”;
That’s all you need to do to control Node MCU.
Step 2 — Wiring everything
The above schematic shows the wiring of each component. D1-D4 pins in Node MCU are plugged in relay board from In1to In4. 3.3V pin of Node MCU goes to VCC in the relay board. Take 2 wires and put both in 5V configuration of breadboard power supply, connect negative to GND, and positive to JD-VCC of the relay board, respectively. To power Node MCU you can either use micro-USB or use the second output of breadboard in 3.3 V configuration. Connect the positive wire to Vin and negative to GND in NodeMCU, respectively. To power breadboard power supply use a 12V DC adapter. Connect the wires of the appliance to the relay as shown above.
Step 3 — Connecting to Blynk
This will be the last step if you just want to control your devices using your phone and you don’t care about voice recognition.
In the Blynk app drag 4 buttons on the main window and change the pin mode in each of the buttons to a digital pin from 1 to 4, For D1 to D4 on Node MCU. If you are using other GPIO pins than choose those pins.
This is it! Now you can control devices using your phone.
Step 4 — Voice Activation
Photo by BENCE BOROS on Unsplash
To use voice recognition, we need to use IFTTT. IFTTT bridges the gap between Blynk and Google Assistant. You can even use Alexa.
Create your IFTTT account and click on My Applets > create applets. There will be a big button saying “If This Then That”
Select “This” button and then select Google assistant and click on connect. Now to create a voice command, click on “say a simple phrase”, fill in the text box according to your needs.
Now click on “That” and choose webhooks and click on connect. This will allow us to communicate with Blynk. On the URL option type the below URL, keep in mind to put your Blynk auth key there—
Change the D1 to your pin of Node MCU to the corresponding pin above. Ex if you are using D1 of Node MCU, type D5 in the URL, if you are using D2 of Node MCU type D4. Use the image above to find the correct value. This is because Blynk thinks that it is connecting to the Arduino UNO board and the above image is the conversion of Node MCU to Arduino UNO pins.
Change the ‘Method’ option to PUT, ‘Content Type’ as application/JSON, and in the ‘Body’ type
[“0”] //This means turn on
Similarly, create another applet to turn off the device and instead of putting:
[“0”] type [“1”]
Now you can do the same for the other 3 appliances.
That's it!!! Now you have more control over your house, you can control anything you want from anywhere in the world for less than $10. I hope that you found this article useful. If you encounter any errors or problems, let me know via any social platform or by responding here!
Did you find this article valuable?
Support Shubh Patni by becoming a sponsor. Any amount is appreciated!