This should have just been a matter of interfacing the two modules and editing some sample code but there were a few complications.

The ESP8266 is strictly 3.3V, requires the use of AT+ commands by default and needs to be wired in a particular way.

The Relay Module is 5V only and will not work properly with 3.3V logic, this module is also active low.

The solution to the voltage level issues were to standardise on a 5V supply (USB) and to use a paid of transistors (any NPN type, I used BC547) to inverse the logic and to provide ~5V or ~0V to the relay module. A buck converter was used to provide 3.3V for the ESP8266.

Since GPIO0 needs to be pulled high at boot for the chip to operate normally my current workaround is to use a jumper and diodes to manually pull both GPIO0 and GPIO2 high at boot time then I remove the jumper to allow normal operation. I may revisit this in future depending on the final application.

Here are a few more photos of the assembled unit:

Since I was planning on powering this project over USB I wanted to know the current draw when both relays are activated, in this case it was ~200mA which is well short of the 500mA which is the limit for basic USB ports. It should also be noted that the ESP8266 can draw 300mA under heavy load however it has quite a light load in this project and using a buck converter instead of a linear regulator helps eliminates waste.

Here is the (Lua) code which has been adapted from Rui Santos’ code to make the web page reflect the current status of each relay on loading and to automatically reload the page periodically.