Ralph S Bacon

MicroControllers, Electronics and IOT

ESP8266 WiFi Relay – Part 2

ESP8266 WiFi RelayThe many comments left after my latest video on this device left me in no doubt that to make it useful we need to reprogram the ESP8266.

It was only when I discovered how overly complex it was to get this device going that I resorted to the rather “faffy” solution in my video (just to prove it would all work!). No more faffing this time, though.

So how easy is it to reprogram this ESP8266 and still get it to do what we want, exactly, Ralph, I hear you ask? As it turns out, pretty easy, certainly something a beginner can do with a bit of guidance.

I’m reprogramming the ESP8266-01 so that the (currently unused, yes, really) GPIO-0 and GPIO-02 pins will be used in the usual way to drive the onboard J3Y transistor that then opens or closes the relay. Even more fortunate is that there are a couple of unused pads on this board which we can use, almost as though the manufacturers expected me to do all this!

So, expect a follow-up video in a few weeks that describes the steps required. That gives you enough time to purchase one (or more, they are really cheap, see the video) and at the same time make sure you have an FTDI or CH340G USB-to-Serial converter, as we’ll need this to program the ESP8266. We’ll avoid going down the route followed by some others of using an Arduino to do this, there’s really no need!

When this project is finally finished I expect to be able to use the manufacturer’s original phone app (for Android) and be able to turn the relay on and off without any further faffing about! Stay tuned!

By the way, as you’re here, if you haven’t subscribed to this blog (or my YouTube channel) I invite you to do both now – that way you keep up to date with my latest Arduino (and similar) µcontroller experiments, and I can gauge how this (new) blog is doing. Constructive comments, suggestions and praise always welcome.

Yellow cube smiley face saying Ja



17 replies

  1. Nice blog! Your blog is very informative. Shopping for wifi Relays ? Here is our pick for the absolute best wifi relays that money can buy which are available in australia.

    Buy shelly wifi relay online


  2. “So, expect a follow-up video in a few weeks that describes the steps required. That gives you enough time to purchase one”.

    So I bought one, and I keep checking your channel, but so far I’ve not seen a description of the modifications required. Presumably you found it easier do what you needed with a Sonoff?


    • No, no, Andy, there was a follow-up video, although I used a different module as well in that video, #110. In order to use this without all the ‘faffing’ we must dispense with the use of the serial bus to drive yet another µController on the relay board. Remove that component just using a hot soldering iron and plenty of solder so all the pins are desoldered at once; it will then almost fall off. Then just follow the modifications in the above video, using GPIO-2 to drive the on-board transistor, which in turn drives the relay. Have a look at the video and see whether it answers your queries – otherwise post back here and I’ll be happy to help.


      • Thanks for your reply, Ralph. I watched the video, but you seem to skip over the actual hardware mods required.


        • Oh dear. My bad. Let’s step through it.

          Firstly, you need the new ESP8266 sketch on my Github (details in the video description).
          Secondly, you need the Android phone app to control the on/off status. (ditto)
          Thirdly, for the original module, remove the on-board µcontroller and then run a 10K resistor from GPIO2 (from where the ESP8266-01 plugs in) to the base of the transistor on the module which I am sure I pointed out in the video.

          I can send you a couple of photos that show this in more detail. (In fact, I’ve just dug out the modules, one modified, one not, so it will be easy for you to see the changes). My email address is on the About tab on my channel (cunningly hidden so that I am not spammed). I await your email!


          • Nice one Ralph. I’m an avid watcher of your YouTube channel, and new blogger. I’ve been playing about with Arduinos for a few years now, and recently thought I might ‘have a go’ at some WiFi (local) stuff, just for fun. What could be easier than operating a single relay via my existing WiFi connection ?
            The answer was “almost anything”. I followed your videos #s 107, 109, 110, which never solved my problems. I have a V4 relay module, which is shown in : https://github.com/IOT-MCU/ESP-01S-Relay-v4.0 but your videos seem not to support that module. Would it be possible to readdress this subject using the latest (and inexpensive) v4 relay module ? Please keep up your fantastic and educational work. PS I purchase almost everything through AliExpress, as I am a kiwi from “down under” (New Zealand).


      • Many thanks to Ralph for his help with this. I finally managed to get it working, although it seems that I may have a hardware problem on the relay module which is upsetting boot-up of the ESP8266.


  3. There are many alternatives to the wifi relay and, as Ralph discovered for us, it doesn’t perform as well as might be hoped right out of the box. However, the module is a neat little unit and it does have an ESP8266 on it. That not only means operation via a smartphone but it is capable of updating the firmware “over the air” (wirelessly – though, it looks easy enough to unplug the ESP from the module), can tell the time via NTP and you have a 32 bit MCU that is much more powerful than the AVR Mega family. So, seeing the module as just a remote controlled relay is missing the point. I suspect that Ralph’s next video on this issue will show us the first steps to how to access that potential.


    • I just love that “doesn’t perform as well as might be hoped”, as in it was an unfinished crappy product! But no more. I’ve rewritten the sketch (simple wi-fi server) and a phone app using MIT App Inventor, NOW it works as I had expected it to, out of the box. As for what I have in store for future videos, I can —– sorry, no spoilers says Benny, it would just be rude. Thanks for posting Michael, always good to hear from you.


  4. Have you had a look at the Sonoff range?
    When loaded with the Tasmota custom firmware they are an awesome solution for lots of different situations.


    • Now, funnily enough, I am awaiting a 4-channel Sonoff from Banggood, for my new workshop. I’ll have to do an “unboxing” or similar and show how well (or not) it all works when it arrives. I’m hoping I don’t have to do anything to it but we shall see. And in the meantime, I had better read up more on the Tasmota software. Those little “in-line” Sonoffs seem clever but I am appalled that there is no Earth wire connection available. Just think how many people will just cut it off?! But my rant can wait. Let’s get the four channel one working first, probably take a couple of weeks to arrive. Thanks for your post, keep reading.


  5. As I needed something very similar, I was really interested in your review of the ESP8266 relay board – but this looks way too much like hard work to me…

    For similar money, I found the Wemos D1 Mini to be a dream to work with, including easy configuration with an open source WiFi Manager library… and rather than having to run a phone app to handle it all, I’m even serving an Angular based web application directly from the 3MB storage on the device too… would thoroughly recommend a look!


    • Interesting comments, Robin, as I’ve used the Wemos D1 before and I agree it’s easy to use. In this case, however, it the fact that the “module” is sold as an ESP8266-01 with (mains) relay that interested me.

      As it happens I’ve written new code for the ESP8266 (a simple web client) and a new phone app too, pretty simple on-off functionality but it works very reliably. I had it running for 24 hours without issue. So it proves we can use this device if we want.

      That all said, I’m also investigating MQTT as a more robust protocol – more on this, I hope, in a future video.

      As an aside, I used to know a Robin Rixon and who looked amazingly like you. I guess Luton is now a dim and distant memory for both of us? How’s life?


      • Life is, as always, keeps getting in the way of all the fun stuff – and fortunately, Luton is now a very distant nightmare! Have you recovered from your ordeal there yet?!

        I completely agree with the “as a module” thinking – that’s why I was looking at it – but realistically, it’s a relay board, with a row of pins that an ESP8266 just plugs into, in much the same way as you can adapt a multi-relay board to plug straight on to a Wemos. But with the Wemos, you have an 80/160MHz CPU and 4MB of memory to play with – and a huge array of libraries.

        The MQTT stuff is also really good fun, I have a Wemos acting as a communication hub for itself and another Arduino Pro Mini – serial comms from the Arduino being converted to JSON and published out to Mosquitto running on a Raspberry Pi – watch out for the maximum payload sizes though, that one tripped me up for a while, you need to adjust the library itself if you want more than about 100 bytes! The software I’ve been working on for my day job makes extensive use of RabbitMQ, a larger scale messaging system, so MQTT came quite easily.

        And lastly, that web application – deploying Android apps is one thing (for the moment), but my phone is already bogged down with too many apps that do one thing only, and drain my battery ever faster – the web app route means I don’t need a dedicated app, I can serve everything from the Wemos directly (3MB file system is enough for most things), there’s no chance of the data and the app no longer marrying up correctly (UI & API are on the same device), refreshing data is simple… and of course, that’s what I do for a living anyway, so why not?!

        Hope all is good with you – it’s been far too long – was absolutely floored to find you on YouTube with such a fantastic collection of really informative, useful videos too… keep up the good work!

        Liked by 1 person

  6. Ralph, I think it is time to change the name of your channel to TENACITY. I did suspect that Benny would be completely dissatisfied with all that “faffing” . Looking forward to your next video on this device. Well, truth be known, I look forward to all your vids, no matter the subject matter.

    Michael Keegan


    • It could be “Tenacity” or perhaps “Extreme Faffing“, Michael, which was another suggestion I made after I received a comment on the video! As it happens I’ve reprogrammed the ESP8266-01 and am now looking at making a new, simpler phone app so that these IoT relays just do what we all, including Benny, expected. At which point I will buy up the entire stock, reflash them, sell them for £1 more than I bought them for and retire a millionaire.

      Meanwhile, back on Planet Earth, keep tuned, and thanks for your continued support.


Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.