Introduction: ESP 8266 Standalone WiFI Relay Control [ytUt]
- 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
- 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.
- 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
- Any WI-Fi enabled device.
- FTDI USB to TTL adapter like this
- Bread Board
- Some connecting wires
- DC-DC Buck converter(optional.To power the module.)
- 1N5408 diode(optional)
- A multi meter (optional)
optocouple like this
- 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
- Node MCU Flasher - Node_MCU.7z
- 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)
- Open Esplorer from "ESPlorer.7z" (provided above) you need to install java for Esplorer
- Select Com port from drop down menu 9600 braudrate(may vary change it till you get proper message)
- click open
- now open"init.lua"(provided above) and copy all the contents and paste it into the editor window of esplorer
- save it as "init.lua"
- click save button(now the upload to esp should begin)
- 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