Nodemcu v3 connected in 2 pcf8574 with 8relays and push button

how can i control 8 relays with 8 push button on nodemcu v3?plss help me...

Can you post a little schematic of how you wired it and the code that is not working?

i still don't have the codes. i keep on searching to fit the codes in my program and setup..

So you are using two I2C modules. Do you have libraries for them?

No problem at this point: there's only one way to hook them up.

This is a problem, though. Nobody will be able to read your mind. You should begin with a clear picture of what you want your project to do and with some skeleton of a program, even if it's not working for now. Then, others can step in and help you solve the problem. But first and foremost: what is the problem?

my problem is i don't understand the code of pcf8574 that is why i need help from someone who knows how to program my setup..

i want to control my 8 relays with nodemcu v3 by push button. but i dont know where to begin specially on programming my setup..

If by this:

you mean the library, then you don't need to understand how the code works internally. Just look at the header file and at the example file (most libraries come with one).

This is too vague. Your goal may be clear to you, but unless you explain it, nobody else will know what it is.

1 Like

i hope you'd understand this picture..

If that's all the hardware you are going to use, then you can hook up your buttons directly to digital pins and do the same for the 8 outputs, or you can use a shift register for them. This will reduce the complexity and the overhead. Also, I suggest that you start on a smaller scale; for instance, with just 2 buttons (like you seem to have done already) and 2 relays, or even 2 simple LEDs to emulate what you want the relays to do.

But one issue remains, and it is of importance, so don't overlook it: what on earth do you want your prototype to do? What behaviour are you after? And, last but not least, what have you tried?

1 Like

i already tried 4 relays with blynk-app and push button, and it works. but i want to extend into 8 relays for future use. the title of my project that i want to propose for our thesis is SMART Home Circuit. i want to control all the lights installed in the house including the outlets. . .

additional, safety features like sensors. that's why i need a lot of extra GPIO's pins. . .

what library of pcf8574 can I pinin/pinout using nobemcu v3 so that I can control my 8 relays?

I'm sorry, but I can't make any sense of this sentence. If you're looking for a library, search for "pcf8574" within the IDE>Tools>Manage Libraries... You'll find a few of them.

However, you still haven't answered the question I asked on post #12, in bold. Bother to read it again?

1 Like

I'm sorry too, but I'm trying my best to explain clearly for you to understand. I think I already explained it to you on post #13.

If this looks is clearly explained to you, I wonder what you manage to write when you are trying to be obscure. You also continue to ignore the part about the code you have tried but that is not working. Where is that blessed code?

#include <PCF8574.h>
#include <Wire.h>

PCF8574 pcf8574a(0x24);
PCF8574 pcf8574b(0x21);

// uncomment the applicable line if using Uno or ESP8266
#define intPin D3 // interrupt input Uno
//#define intPin D4 // interrupt input NodeMCU ESP8266

volatile bool buttonPressed = false; // button interrupt flag
byte buttonReg; // button read register

void setup() {

// initialize PCF8574 with an interrupt pin and set all outputs to '1' (Relays off)
Wire.begin();
pinMode(intPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(intPin), buttonISR, FALLING);
pcf8574a.begin(0xFF); // turn off all Relays

}

void loop() {

// if a button press was detected via interrupt, check if the button press
// occurred on one of the "toggle" control buttons and toggle the relay if so
if (buttonPressed) {
delay(50); // crude debounce
buttonReg = pcf8574b.read8();

// toggle a relay if button pressed
if (!bitRead(buttonReg, 0)) {
  pcf8574a.toggle(1);
}

// toggle a relay if button pressed
if (!bitRead(buttonReg, 1)) {
  pcf8574a.toggle(2);
}

}

// clear interrupt flag
buttonPressed = false;
}

// interrupt service routine
void buttonISR() {
buttonPressed = true;
}

There at last! Now, would you mind putting that code within code tags and explaining what your goal is and what is and is not working in your code?

1 Like

I'm a newbie with this c++ programming. I just copy this codes from youtube. To be honest, I don't really understand this i2c codes and I appreciate it if you teach me.

The 8 relays is connected in the PCF8574(0x24) and my push buttons is attached on the other PCF8574(0x21).

No problem, we all were at some point. But, in this case, I suggest that you start with something within your level of expertise and add a little challenge at a time to gain more knowledge in little increments. Can you write (and i mean write yourself, not grab from God nows where) some little code to blink an LED? Two LEDs at different frequencies? Eight of them? A pushbutton that will toggle and LED on and off with each pulse? A pushbutton that will cycle amongst five different blinking patterns for your array of LEDs? Are you familiar withe finite-state machines? These, in my opinion, are useful building blocks to build stuff and write code for uCs, even if you never blink another LED again after that.

On the other hand, this is hardly a sound approach to programming (and to many other things too, but I digress...). Unless that guy (or gal) from Youtube has exactly your same problem and is using exactly your same hardware in exactly your same configuration, things are guaranteed not to work. Moreover, if you use code you don't understand, things will sooner or later go sideways on you, like what happened to this guy.