Introduction: ESP 8266 Standalone WiFI Relay Control [ytUt]

AIM

  • To control a relay switch using esp8266 in standalone mode(without arduino,pic or any other Micro-controller) via Web-UI
  • The ESP broadcasts its own SSID.It does not connect to a router.local IP address of esp is 192.168.4.1

Step 1: Gather Hardware

  1. ESP 8266 (There are a lot of variants available in the market.for this tutorial lets just use the esp-01).If you are curious about the different variants click this link.
  2. 3.3v/5v power supply (depending on your module.My esp 01 uses 3.3v.Its very important that you have and external power source.More on this later),12 v power supply
  3. Any WI-Fi enabled device.
  4. FTDI USB to TTL adapter like this
  5. Bread Board
  6. Some connecting wires
  7. DC-DC Buck converter(optional.To power the module.)
    1. 1N5408 diode(optional)
    2. A multi meter (optional)
  8. Relay Driver(3v in my case) I recommend you to get the one with

    optocouple like this

    1. you can build the relay driver on your own if you wish to with an npn transistor and a relay,the circuit is provided here.but i recommend you get a relay driver

Step 2: Gather Software

  1. Node MCU Flasher - Node_MCU.7z
  2. ESPlorer(The IDE to load Lua script to the module) - ESPlorer.7z

Step 3: Setting Up Power Supply

This step is important.

Some FTDI USB to TTL converters have a 3.3 v power supply build into it.To avoid unnecessary confusions.Don't try to power the module from the power supply of the USB to TTL converter. It Just wont work guys

Methods to power it:

  • Use a 3.7 v battery from your old phone.(an additional 0.4v wont damage your module)
  • Use a DC to DC buck converter like this

Calibrating the Buck Converter

Make connections as shown in the Diagram

  • Connect a 12v power supply to the input via a diode(protection)
  • Switch to DC voltage measurement in you multi meter and connect it to the output of the Buck converter
  • adjust the variable resistance on the buck converter till the multi meter reads 3.3v


Step 4: Flashing Node MCU

  • Make connections as per the diagram
  • Open Up node MCU flasher( file in "Node_MCU.7z" given above)
  • Select COM Port
  • Click Flash

Step 5: Code Lua Script

I just modified the code from the node MCU firmware page at GIT (hats off to the TerryE,the developer)

I've attached the code to the tutorial.

I've used GPIO 2 of the esp as output

Step 6: Uploading the Lua Script.

Make connections as per the digram(REMOVE GPIO 0 FROM GROUND)

  1. Open Esplorer from "ESPlorer.7z" (provided above) you need to install java for Esplorer
  2. Select Com port from drop down menu 9600 braudrate(may vary change it till you get proper message)
  3. click open
  4. now open"init.lua"(provided above) and copy all the contents and paste it into the editor window of esplorer
  5. save it as "init.lua"
  6. click save button(now the upload to esp should begin)
    1. if it does not click "save to esp at the bottom

7.Click Reset button in ESPlorer IDE

Step 7: Driving the Relay

I know that most users who are capable of using an esp can figure this part out on their own.anyhow I'll give a quick idea just in case(you may not need it i know) using the relay driver is pretty straight forward

  • connect GND to GND
  • connect 12v(may vary depending on the module) to VCC
  • connect GPIO 2 to IN

For those who want to build the relay driver on their own.I've made a circuit.its pretty straight forward and most of you can design a better circuit than the one i've made.i've provided it anyhow.The circuit is not tested.do tell me if it works..

Step 8: Connecting to the Esp

After wiring the circuit as shown in step 7.Turn on the module(via a battery,the buck converter or any other power source)

If everything goes according to plan you should see the SSID broadcasted by the ESP on when you refresh your wifi on any WiFI enabled device(be it a smartphone,tablet,laptop etc...)

Password is 12345678 (Edit init.lua to change password and ssid)

Connect to it and you should see the webpage.

IP address is 192.168.4.1

Step 9: Conclusion

  • Hope you guys understood my first instructable .In case of any doubt don't hesitate to PM me.
  • I'll tend to your questions the best way i can

Chao :)

Comments

author
domoledlightd made it!(author)2017-05-13

Thank you very much for your tutorial

I want to pilote 10 independant relay is it possible with your system

author
YadhuS made it!(author)2017-05-15

Not with this module. I think it would be best if you could give Node Mcu development board a try.

https://www.amazon.com/HiLetgo-Version-NodeMCU-Internet-Development/dp/B010O1G1ES/ref=sr_1_1?ie=UTF8&qid=1494850759&sr=8-1&keywords=nodemcu

author
RANJITH+GANDRA made it!(author)2016-06-02

hi,
send me the link to download the ESPlorer

author
Akshay+Jha made it!(author)2016-04-09

Great Instructable keep it up & thanks for keeping it simple and to the point

author
godfish made it!(author)2016-04-06

You make it look easy, thank you for this I'm trying this for a backyard light. I'll follow up if I can get it working.

author
tttapa made it!(author)2016-04-05

Nice Instructable!
However, I'd like to point out that the 3.7V of a Li-ion cell is the nominal voltage (the halfway point when discharging at a constant current). When fully charged, most Li-ions are 4.2V or even up to 4.35V. This is 30% more than the rated 3.3V, and might damage/destroy the module.

author
wold630 made it!(author)2016-04-05

Thanks for sharing and welcome!