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

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

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 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

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 :)

Be the First to Share


    • CNC Contest

      CNC Contest
    • Make it Move

      Make it Move
    • Teacher Contest

      Teacher Contest

    16 Discussions


    1 year ago

    Not working..this code makes nodemcu rebooting continuously.

    1 reply

    Reply 1 year ago

    same here, reboots with nothing attached. cant control it and have to re-flash it .


    1 year ago

    that relaydriver wont work with the esp2866-01

    the esp wont boot correctly. cause it pulls the GPIO2 low.

    4 replies

    Reply 1 year ago

    thats why we use optocouplers.

    you can add a pnp transistor if you want.

    just wanne remove frustration :)


    Reply 1 year ago

    i allready have a circuit that doesn't work for what you say... i cant modify the circuit... it has a bc548... some quick fix? a pulldown resistor will work??


    Reply 1 year ago

    You first use a pnp resistor and a pullup resistor. This means that your status of the pin has to be always high. Unless you want to Toggle then you Digitalwrite(2,LOW);
    And your pnp resistor Toggles the nnp transistor which Toggles the Relay.
    I still would suggest optocoplers or solid state relays.


    Reply 1 year ago

    ok! thanks for your reply!! i will go with the optocopler in the next board, definitely!


    1 year ago

    In the esplorer it gets stuck on ' communication with mcu "


    1 year ago

    In the Relay driver... shouldn't the the pin with the resistor go to the base of the npn...the last pin and not the middle one?


    2 years ago

    Thank you very much for your tutorial

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

    1 reply

    Reply 2 years ago

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


    3 years ago

    send me the link to download the ESPlorer

    Akshay Jha

    3 years ago

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


    3 years ago

    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.


    3 years ago

    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.


    3 years ago

    Thanks for sharing and welcome!