Advertisement

header ads

Build a simple home automation system in 30 minutes !


Hello geeks. From today onwards techmagister brings you a unique and simple home automation (IOT) tutorial series. If you are a tech guy, you have probably heard these words. Also you have probably heard about some sayings like "use your phone to control your domestic electronic devices", "use our IOT system to make your life easier" etc. Yes IOT is the buzzword in todays' tech world. But what is IOT? what is home automation? Don't worry even if you are hearing these words for the first time. Techmagister is here to teach you from A to Z.

IOT - a simple explanation.

IOT stands for Internet Of Things. Yes, Internet! That means everything connected to each other. Lets take a simple example, Imaging you are on your way to home and you have to turn your Air conditions on before you go home because it is freaking summer,with IOT and home automation you can turn your home A/C on using your mobile device(smart phone) by using an APP together with Internet. That's is , I O T.

30 Mins IOT project to turn on a bulb using your phone via wi-Fi.

Lets do it. Now we are going to build a very basic home automation (IOT) system to control a bulb via Wi-Fi. There are couple of things you have to have for this project. But don't worry ! It wont cost more than $15. You can find these components from your local stores or even in e-bay easily.

Things You Need.


  • ESP 8266 Wi-Fi module 

here I'm using the basic module. But there are many advanced and easy to use modules also. You can buy this components from using following links:




  • FTDI module.

This module is used to connect ESP module to PC for programming. If you have brought an esp developer module (also called NodeMcu) you wont need this component if it has USB connector.



  • Power supply (AC-DC adapter)
  • DC 5V Relay module
  • Bulb Holder
  • AC bulb
  • Wires and a connector board
  • Mobile phone which can create a Wi-Fi hotspot.(Smart phone)
  • PC or Laptop with Internet connection

Configuring ESP 8266 Wi-fi module

ESP 8266 module is one of the most popular module for IOT based projects. It has almost all basic functions and extremely cost effective. You can download the full data sheet for ESP 8266 module from here and basic features of the module can be listed as follows. The ESP8266 is capable of either hosting an application or offloading all Wi-Fi networking functions from another application processor.Source | sparkfun
  • 802.11 b/g/n
  • Wi-Fi Direct (P2P), soft-AP
  • Integrated TCP/IP protocol stack
  • Integrated TR switch, balun, LNA, power amplifier and matching network
  • Integrated PLLs, regulators, DCXO and power management units
  • +19.5dBm output power in 802.11b mode
  • Power down leakage current of <10uA
  • 1MB Flash Memory
  • Integrated low power 32-bit CPU could be used as application processor
  • SDIO 1.1 / 2.0, SPI, UART
  • STBC, 1×1 MIMO, 2×1 MIMO
  • A-MPDU & A-MSDU aggregation & 0.4ms guard interval
  • Wake up and transmit packets in < 2ms
  • Standby power consumption of < 1.0mW (DTIM3)
We can use method call AT commands to configure ESP module. As name implies it is a set of commands starts with "AT". But there are some lags and errors can occur when you use AT commands in large projects. But if you are using "Lua " language to configure your ESP module you can configure even xml codes in the main code because lua is an hybrid language. 
So lets get back to work. In order to start coding your ESP module with lua. You have to flash lua firmware to ESP module. In order to do so you have to have several files with you.

  • NodeMCU flasher
  • Binary Files
  • ESplorar (To upload lua codes to ESP module's chip) - Download All Files

Now go through following steps carefully.
Note: ESP module is operated only in 3.3V. So don't connect it to 5V .

  • Connect your FTDI and ESP module as follows. Then Connect FTDI to your PC



  • Then FTDI drivers will be automatically update. If not, you can make a google search by using FTDI model name you have for driver downloads.

Flash NodeMcu Firmware to ESP module
To flash the firmware. Follow this video guide. You don't have to download the files which are mention in the video. You have all files now.


(You should have java installed in your PC in order to run ESplorar. To download java-Download Java)


  • Take your smartphone and create a Wi-Fi hotspot . You really don't have to use data  here. Just create an hotspot and keep it.
  • Then open ESplorar software and it will auto detect your ESP module with the connected com port. If not, remove the FTDI from the PC and insert again or try restarting your PC.
  • Copy following code and paste it in new lua project.Replace Your Wi-Fi hotspot name and password in relevant fields. Then deploy the code to ESP module.
wifi.setmode(wifi.STATION)
wifi.sta.config("hotspot name","password") //username & password of the hotspot
print(wifi.sta.getip())
led1 = 3
gpio.mode(led1, gpio.OUTPUT)
gpio.mode(led2, gpio.OUTPUT)
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
conn:on("receive", function(client,request)
local buf = "";
local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP");
if(method == nil)then
_, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP");
end
local _GET = {}
if (vars ~= nil)then
for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do
_GET[k] = v
end
end
buf = buf.."<h1> ESP8266 Web Server</h1>";
buf = buf.."<p>GPIO0 <a href=\"?pin=ON1\"><button>ON</button></a>&nbsp;<a href=\"?pin=OFF1\"><button>OFF</button></a></p>";
buf = buf.."<p>GPIO2 <a href=\"?pin=ON2\"><button>ON</button></a>&nbsp;<a href=\"?pin=OFF2\"><button>OFF</button></a></p>";
local _on,_off = "",""
if(_GET.pin == "ON1")then
gpio.write(led1, gpio.HIGH);
elseif(_GET.pin == "OFF1")then
gpio.write(led1, gpio.LOW);
elseif(_GET.pin == "ON2")then
gpio.write(led2, gpio.HIGH);
elseif(_GET.pin == "OFF2")then
gpio.write(led2, gpio.LOW);
end
client:send(buf);
client:close();
collectgarbage();
end)
end)



  • Then check your smartphones Wi-Fi hotspot connection details. It should show ESP module as a connected device.
  • Then connect your relay module with an AC adapter and an AC bulb holder as follows. Then connect ESP GPIO pin to relay's signal trigger pin and give 5VDC to DC IN and ground the GND pin as follows.

  • GPIO1 ----> Signal trigger port


  1. Then connect The relay to AC current using AC adapter. (Caution : High Voltage)

Note: In here normally GPIO send only a 3.3 V signal as it operates in 3.3V. So you have to convert that signal into a 5V signal.In that case you need arduino board or level shifting Circuit module to convert 3.3V to 5V. The easiest method is connect an arduino to a PC and put following code. or you can try THIS METHOD .
Use THIS CODE for arduino. Note:If you are using arduino to make GPIO value to 5V, you have to make connection as follows:

  • GPIO1>>>Arduino analog input(eg: A0)
  • Arduino digital pin 13>>>Relay Signal Pin

after configuring all lets test the system,


  • Open your phone's web browser and type the IP address of the ESP and hit go.(you can find the ip of the esp using your smartphone's hotspot wizard)
  • It should direct to a web page as follows.



  • You can press ON and OFF buttons from the web page to Control your Bulb.

Hooray! 🙋
Now you have completed your very first IOT based home automation project. You can extend this project by using advanced ESP module which has more than 2 GPIO pins. Also you can connect sensors and check their status via mobile too.
So we will meet you again with another IOT tutorial. Please leave a comment below if any Help needed. Please like our FB PAGE to get in touch with techmagister. peace !



Post a Comment

1 Comments

  1. Obviously, once you choose to spend money for these gadgets, make a point to purchase a decent security camera, as well. https://www.homesecuritybuddy.com/parking-lot-security-cameras/

    ReplyDelete