Adventuring with Wi-Fi Using NodeMCU ESP8266

Toggle switch using NodeMCU.

I have created a toggle switch using Arduino Uno. I have even connected it to an AC relay so that it can control a lightbulb.

Now, I want to control such a switch through a wi-fi because, look, wouldn’t it be nice to be able to control those appliances through wifi, even through the internet, remotely with, say, your smart phone?

I tried several ways. The first attempt was to use Arduino Wi-Fi Shield. I got discouraged almost immediately by the price.

Then I tried the ESP8266 series, mostly fur to its (small) size and price. While I struggled hard in making it work, I got hooked almost immediately. In addition to its wi-fi capability, it also has the ability to execute Arduino sketches directly without the need for an Arduino. An ESP8266 unit, in fact, is a microcontroller so that we no longer need an Arduino Unit at all to use ESP8266. It is indeed a wi-fi enabled microcontroller that works with Arduino sketches, at much lower price. How can we not love this thing.

The first try was with ESP8266 ESP-01, the smallest, first version of the series. It took me a long while to make it work, and even when it was finally working, I didn’t quite like it. Why? Because it took so many steps to make it work and even when you finally understand how, you still get so discouraged by the steps. First, we need to upgrade the firmware. We still need to find where the upgraded firmware is (I forgot where it could be found almost immediately after I found it). And then, we need to remember to ground (“pull down”) one of the pins when we upgrade the firmware. And for Mac users with High Sierra, another problem was that we need to use additional driver to work with it. This, of course, has not taken into account the additional libraries that the Arduino IDE uses when programming the ESP8266 (but the upgrade is needed with whichever version of ESP8266. So I guess it is acceptable).

Then I tried the latest version, the ESP8266 ESP12F. I also got discouraged by the need to solder it first onto a board, and the size of the thing after having been soldered on to its board is so awkward that it needs two breadboards to make it work. Finally I found an ESP8266 board that I like. It is the NodeMCU. At first, I bought the one with on board CP2102. It turned out that finding a driver that works with CP2010 is so hard, if not inexistent. Eventually I bought one with on board CH340, which driver is readily available in a number of sites, and it appears to be much easier to use.(The CP2102 and CH340 are the system that links our computer with the ESP8266 through the USB connector. To work with the system, a driver need to be in place on our computer to control the USB connector on the computer).Having unboxed the Node MCU with CH340, the first thing I did was to make sure that it works by uploading the classic blink sketch. It worked beautifully. Then I uploaded the button sketch to control a LED on one pin with a switch connected to another pin. I used my touch switch to pull-up the button pin, and, voila, it turned the LED on and off as expected. Then, I used and tweaked my toggle-switch sketch, and it actually works! See the video above to see it at work. So now I am convinced that the NodeMCU works well as a programmable microcontrontroller. My next experiment, watch this space, is to use the NodeMCU as a wi-fi switch to control an appliance remotely. Excited!

About this entry