ESP8266 ESP-01 LED Wire Switch

Introduction: ESP8266 ESP-01 LED Wire Switch

This project originated when my girlfriend and me installed multiple LED fairy light wires in the room for a nice christmas feeling. Each time we went to bed we had to run around the room and shut every single wire off. The other day, we had to turn all of them on again.

Since I had some ESP8266 ESP-01 modules lying around, I decided to assemble and program a quick prototype.

After the successful implementation of the prototype with a junk LED wire, I decided to take on my first PCB design and ordered a few boards.

This instructable leads you through the schematic, the first prototype and the PCB and gives you the code to program the ESP module with a few clicks.

TL;DR: This is an easy way to implement a Wi-Fi controlled switch with the ESP8266 ESP-01.



  • ESP8266 ESP-01 module
  • AMS-1117 3.3V regulator
  • IRLB8721 MOSFET (final PCB) or 2N2222 transistor (initial prototype)
  • Male and female header bars


  • Arduino IDE v1.6

For programming

  • OPEN SMART USB to ESP-01 Adapter

For testing

  • LED
  • 220 Ohm resistor
  • Breadboard
  • Jumper cables

For assembly

  • Soldering iron
  • Wires (prototype only; not for PCB)
  • Perf board (prototype only; not for PCB)

Step 1: Schematic

Above is the schematic made with EasyEDA. It can be broken down like this:

We take an input voltage from a USB power cable with 5V and feed it into the VIN pins of the AMS1117 3.3V module.

The VOUT pins of the AMS1117 3.3V module are connected to the collector pin of the IRLB8721 MOSFET and the VIN and CH_PD pins of the ESP8266 ESP-01 module. The CH_PD pin needs to be pulled HIGH for the ESP8266 ESP-01 module to execute the code.

The D2 pin of the ESP8266 ESP-01 module is connected to the GATE pin of the IRLB8721 MOSFET. This controls whether the current may flow through it or not.

The emitter pin of the IRLB8721 MOSFET is connected to the LED wire.

Lastly, all ground pins are connected together.

If you chose the 2N2222 transistor, replace all occurrences of IRLB8721 with 2N2222 respectively and remember the legs have different meanings on both components.

Step 2: Programming

Before we set up a prototype on a breadboard, we should program the ESP8266 ESP-01 module, so we can test the prototype later on.


My code is heavily based on Random Nerd Tutorial's tutorial for the simple HTTP server. I removed the second button though, since we only need to control one pin (D2). Nonetheless, you can just use their code as is and replace your WiFi credentials.

Flash the ESP8266 ESP-01

If you got yourself the OPEN-SMART USB to ESP-01 Adapter you can plug your ESP8266 ESP-01 module into it and set the switch to PROG. Then, plug the whole thing into a free USB port in your computer and fire up the Arduino IDE.

Copy and paste the code from Random Nerd Tutorials, replace your WiFi credentials and upload it to the ESP8266 ESP-01 module.

Then, remove the ESP8266 ESP-01 module from the OPEN-SMART adapter, set the switch to UART and reinsert it.

Test the code

Open the Serial Console in the Arduino IDE and wait until the module is connected to WiFi.

Then, open your browser and navigate to the IP address shown in the Serial Console. Note: You have to be in the same network aka WiFi. Else you won't be able to access the ESP8266 ESP-01!

If everything's working, you see a website with two buttons. Connect a LED with a 220 Ohm resistor to the D2 pin on the ESP8266 ESP-01 module and it should light up and turn off when you click the correct button on the website.

If you experience any difficulties, please follow the full and detailed tutorial linked above.

Step 3: Prototyping

Set up a breadboard with all needed components and wires as shown in the schematic above and test it with the programmed ESP8266 ESP-01 module.

If everything's working, you have two options.

Option A: Solder it to a perf board

Option B: Make a PCB

I opted for option A first and afterwards decided to get my hands dirty with my first PCB project.

In the pictures you see my self-soldered prototype. As always, the connections are a mess and I used some shrink tubes to prevent the overlapping connections from shorting out. Also, I used the 2N2222 transistor instead of the IRLB8721 MOSFET, because I had plenty of them lying around and I knew it wasn't meant to stay.

The soldering took me about an hour and it wasn't fun at all. If you're a pro solderer maybe you enjoy the process, but for me I want something simpler.

Step 4: PCB

I've been afraid of PCBs because I thought I had to design them with the SMD components and I couldn't find readily made ESP or Arduino development modules to insert into the schematic or the PCB layout.

For this project I decided to simply consider the ESP8266-01 and AMS1117 3.3.V modules as the kind of stuff I would need to solder on the board in order to use them: as female header pins.

This made my life much easier and the PCB layout was done in about two hours. You can see the two versions in the pictures.

Version 1 has some minor caveats:

1. The header pins are too narrow. I didn't take into account they had to be 2.54mm apart from each other and just grabbed the first pins from the library.
2. I messed up the label for VIN: VCC and GND labels are swapped.
3. The AMS1117 3.3V module is wider than I thought and spans over the edge of the PCB.

Of course, I noticed those caveats after ordering and testing them in real life. They're not a game breaker, but I created a new version where I improved the above mentioned points. Also, I placed the ESP8266 ESP-01 module in a way that it wouldn't overlap the AMS1117 3.3V module.

You can find the EasyEDA project here:

Step 5: Advancing

So here we are with an easy to assemble PCB. What's next?


It would be great to have a 3D printed case that hides the electronics and makes the build more robust. Ideally it would have an integrated heat sink for the IRLB8721 (although during my test with a 10m long LED wire it never became warmer than room temperature).


Also, I want to add a USB connector for VIN aka the USB cable and a JST connector for VOUT aka the LED wire. Currently, I used male headers on the board and female headers soldered to the LED wire and the (cut off) USB cable to connect it. But this is not a future proof connection and doesn't look and feel very professional.

In conjunction with a case this would tremendously increase the aesthetics of the build and also the overall usage experience (which is crucial if you try to implement a smart home in a shared environment and not only in your own room or lab).

Smart Home integration

Currently, every ESP8266 ESP-01 is a HTTP-Server with a website that controls its state. I'd like to take my first steps towards Smart Home and use NodeRED and MQTT to integrate them into a centralized Home Automation system so I can control all my switches from one UI.

Of course I could simply build a webserver that sends requests to the different ESP8266 ESP-01 modules but again, that isn't an elegant, standardized or extensible solution.

Step 6: Critique

If you made it until here, thanks a lot for reading!

This is my first article here and I hope you could take away something. I didn't dive into the various topics mentioned, because I felt there are many great tutorials on the different topics already. If you need more references or want me to describe some of the steps more detailed, please leave a comment.

If you like what you read, please leave a comment, too and maybe like the article. It would mean a lot :)

Be the First to Share


    • Photography Challenge

      Photography Challenge
    • Anything Goes Contest 2021

      Anything Goes Contest 2021
    • One Board Contest

      One Board Contest