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

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.

Pete.

2 Likes