Need help to use 16 channel relays with esp8266 Node mcu and blynk app

Thanks for help!

1 Like

With this we only use two pins for communication, and we can get rid of the short pulse that nodemcu produces while booting !! Which activates the relay for a short a time. Correct me if i am wrong.

Please do share it with us.
Thanks in advance…

You can review this while waiting for Pete’s white pages :wink:


Have a look at similar project at


PCF8574 Controller Project for ESP32 and ESP8266

PCF8574 8-channel I2C Digital Input Output Expander, for ESP32/ESP8266 for ESP32/ESP8266, using Blynk

In the sample project, you can use these features:

  1. This example demontrates the use of a Master PCF8574 Controller (ESP32/ESP8266) to control 8 different PCF8574 Controllers running Blynk
    • Each PCF8574 Controller can control 8 different relays, etc…
1 Like

WOW !! That’s interesting… But it doesn’t seem to have a manual control. Is it better to connect the button to the nodemcu or PCF8574 ??

Here i am not able to get my hands on this IO expanders. I ordered online twice and the package was lost. I am able to get the once used with the i2c LCD display. This too uses the same PCF8574 ic . But it doesn’t work. I tried changing the address in the code but it did not work. Also soldered the pads for selecting the address. But works fine with the LCD display…


Did you run I2C scanner? Also with my nodes I have to use the default SDA and SCL pins as redefining the pins I’m the code dnt work.

I think that if you take a close look at the LCD serial backpack board that you have, you’ll see that the pins labelled D0, D1, D2 & D4 aren’t actually connected to anything - they don’t have any PCB traces connected to them and no connections to the pins on the PCF8574

This schematic confirms that:

This means that at most you only have 4 outputs rather than 8. You could daisy-chain multiple ones together of course, up to 8 on one I2C bus, provided you gave each one a unique address.
The default address (with jumpers A0, A1 and A2 disconnected) is 0x27

More info here…


1 Like

Yep, i tried scanning but it did not show any result on the serial monitor. So i dropped the idea of using this LCD i2c module as it is not ment to be used as IO expander.

I will try searching the IO Expander here locally. Let me see if i can find one.

For getting additional 4 outputs using this module is not worth the money…

There is another alternative, which is the CD74HC4067 chip. This is a 16 channel analogue/digital bi-directional multiplexer.

It doesn’t use I2C, and in my opinion is better suited to giving more output pins rather than as a way of providing more input pins, but as its output pins that you need then this might be worth cionsidering.


I always face the problem while selecting pins for input and output on a nodemcu. As you know they all are not safe and some cannot be used too. And some spikes while booting. So i thought an IO Expander would solve this problem. It would be good if we use expander for both input and output. This way we need not worry about the pin selection on the nodemcu.

What do say on this ?

It depends what you want your project to do.

If you want a 16-way relay controller, as you originally said, then either device would be a suitable way of doing this. The I2C approach needs only 2 pins, the CD74HC4067 needs 4 pins. The NodeMCU has only 2 pins that don’t oscillate at boot-up, but in reality I don’t think that you’d have a problem with using either type of multiplexor for your relays when using a NodeMCU.

As far as inputs are concerned, this is where it gets a little more complex, but once again it depends what you want to do.
If you wanted 16 physical push-buttons, one for each relay, and maybe an additional push button that turned all 16 relays on or off then the problem is knowing when one of these buttons has been pressed.

Buttons connected directly to the board can have interrupts attached to them, to trigger a function in your code when the button is pressed. The alternative is to poll the button on a regular basis to see if it’s state has changed. If you only polled a button once every second then it would seem very unresponsive, but polling it more frequently increases the work that has to be done within the code, which can ultimately lead to problems with Blynk when you add more buttons.

I don’t think you can use interrupts with the CD74HC4067, but I might be wrong. If you cant, then it’s a case of polling each of the 16 inputs in sequence to see if a button has been processed. As each of the 16 inputs has to be selected by doing a digital write to one or more of the four controller pins (this may be done in the background, if you use a library, but it still needs to be done) then the process of polling the 16 buttons in turn will have a much higher overhead than polling 16 pins in sequence.
The I2C expander does have an interrupt facility, 8n fact some have two interrupts, one for each bank of 8 pins. I have no idea how these work though. Hopefully when an interrupt is triggered you’ll be able to read the 12C bus and see which pin was pressed, but I won’t know that until mine arrive and I do some experimentation.

With outputs you don’t have this problem. If you want to turn a relay on/off because a set of criteria are met in your code, or because you use a Blynk widget to signal that you want a relay activating or deactivating then it’s simply a case of sending the correct command.



Thank you so much for the detailed reply !! My idea is just to add a push button and a relay to the IO expander. I dont need 16 relays. But 4 inputs and 4 outputs. And i should be able to read the button via i2c. But as you said interrupts cannot be attached on the i2c lines to detect the changes.

But instead we can add the push buttons to the nodemcu and attach the relays to IO expander. So booting oscillations doesn’t flicker the relays !

No, that’s not what I said. The I2C expanders do have an interrupt line (or two in some versions) that can be connected to a pin (or pins) on the NodeMCU. I just don’t know how you then determine which button triggered the interrupt, but I assume that there must be a way, otherwise there’s no point in having it.

I don’t think the other type of multiplexers support interrupts, but I might be wrong.

If you don’t want to control 16 relays as you originally stated then an ESP32 would be the simplest, cheapest and easiest to obtain solution and it has at least 14 pins that are suitable for input or output and another 4 pins that are input only.


1 Like

Yeah ESP32 have more pins considering ESP12E. But i have never worked on ESP32. But i have one. I should start working on it.

The ESP12E is basically the same as a NodeMCU but without all the voltage regulator and USB interfacing circuitry, so won’t help.

This is a great reference for the ESP32 board, but make sure you have a good pinout diagram for your actual board, as not all pins are broken-out on all dev boards:


1 Like

Yeah i am aware of it. As the nodemcu doesn’t fit on these bread board i usually buy he ESP12E chip and solder it to a breakout board. And i have my lab bench power supply to feed ESP.

I will definitely checkout !! Thank you for the link.

Вариант 1. Сдвиговый регистр. Вариант 2. Использовать UART ESP и на отдельном микроконтроллере реализовать расширение. Вариант 3. Использовать ESP32

I’m using MCP23017 expander to have more inputs/outputs for my NodeMCU.
It have 16 I/O ports and i2c. Im using 8 ports as inputs for logic current sensors (for light on/off state) and 8 ports as outputs to control relays via ULN2803 transistor array to turn on/off lights.
If needed, the setup can be extended to more MCP23017 and ULN2803 .
ULN2803 used to reduce part amount on board. No diodes needed for relay switching
Controlling inputs/outputs for MCP23017 is very easy

1 Like

MCP23017 is best use for 16 ch input or output.
For relay for loking for 16 ch relay board gor 5v.
Search on google for board.