Weird Behaviour

Hello,

I have a weird thing going on !!
I have a NODEMCU with 4 relays attached with Push buttons. Lets say i have connected appliances A,B,C & D to the relays.
When i turn on A it turns on and also reflects on the app as it should. After a while with no human intervention B turns on, and even this reflects on the app. If i turn it off again it will turn back on after a while. And once in a while D turns on. I know you guys will tell me there is a loose connection . But if i dont turn on any appliances, everything will stay off and will never come ON. I dont know what is causing this issue. I have everything soldered, no loose wires. I have also changed 2 NODEMCU’s till date, still facing the same issue. Is something from server side triggering the relays?(seems lame but felt like a reason). I had posted a similar issue long back, but couldn’t get it.
Will any noise in the power line will cause the relay to trigger ? But again this should not be reflected in the app if it was a powerline problem…
Can someone tell what may be the problem ? I know its not Bynk related. But i wanted to seek advice here as there are some BIG BRAINS like i always say…

The first think I’d look at is whether the pins that your relays are connected to are floating.
Are your relays active HIGH or LOW?
What sort of pull-up/down resistors are you using, or are you specifying anything in your pinMode statements?

Pete.

The relay is active low.
I have declared pin mode as output and later
Digitalwrite high in setup.
I have no physical resistor to pullup . But i have optocouplers to drive the relay pins.

The optocouplers won’t help to keep your pins held HIGH by default.

Are your digitalWrite before or after you connect to Blynk? - Maybe try swapping them around, or repeating after the Blynk connection is established.

Personally, I’d try adding 10K resistors between your pin and +3v3 to keep the pins HIGH, and see if this helps.

You should also examine your code and your app carefully, to ensure that you aren’t doing anything silly.

Pete.

I don’t know if this can fix your problem, but it’s quite easy to test.

I got the very similar issue, when running a system from local server.

After so many months, headaches and failed attempts to fix the issue by searching for bugs in the system (hardware, stray pointers, wrong logic, IDE / library / server versions, etc.). The final and hopeless try did fix the issue, just by cloning then deleting the project, and use the new token.

It seems the root cause is some rare and weird bug in the server code / corrupt project data in the server.

I forgot to mention ! I deleted the whole project and created a new one with new auth token !
I am running the server on rpi zero w. I am not getting what the hell is going on. I am fed up.

If that’s the case, you have to check your program for bugs and hardware design flaws as suggested by @PeteKnight .
Keep researching, fixing and you’ll get lots of experiences back from the exercise. Not totally pointless.

I mentioned about optocoupler to say if there are any noise it wont touch the NODEMCU pins directly.
I have wifimanger, so after all the connection is made and the nodemcu is connected to server, i am setting up the pins

pinMode(RelayPin1, OUTPUT);
digitalWrite(RelayPin1, LOW); 
void lightOff1() {
  digitalWrite(RelayPin1, HIGH);
  LampState1 = 0;
  Blynk.virtualWrite(VPIN1, LOW);
}

void lightOn1() {
  digitalWrite(RelayPin1, LOW);
  LampState1 = 1;
  Blynk.virtualWrite(VPIN1, HIGH);
}

This will turn on the relay…
I have used the same program with other nodemcu, but it will never false trigger. NO CHANGES IN THE CODE.

I have also changed the server once(reinstalled server), but still same problem.

These two statements appear to contradict each other.

Optocouplers on the relays can isolate ‘back EMF’ from the relay coils, but I can almost guarantee that you will have wired the relay board in a way which totally defeats the opto isolation. Do some googling and you’ll understand why a single supply cant work the way that you think it is.

But/ regardless of that, I think you need to eliminate the possibility that your GPIO pins are floating a an intermediate voltage. It’s almost certain that your relays are designed to work with either 5v or 3.3v. That means that a full 3.3v logic signal is already significantly below the 5v ‘optimum’ HIGH signal level, so it only needs to drift down slightly before you’re into that grey area where the relay can’t decide if it’s seeing a HIGH or a LOW logic signal.
Pull-up resistors are the solution for this.

Pete.

Sorry, I mean to say when testing on bench it works fine. Because installing in a closure i always test it for 3 or 4 days. During this time it never false trigger.

Yes. I have not removed the jumper from the relay board providing an external power supply. But i have a small circuit of optocoupler (DIY) that has been connected to nodemcu apart from the once on the relay board.

I think i will have to focus on this. I will add the pullup resistors and see if that solves the issue…

That’s quite a lot different from the information you’ve provided so far, which makes it very difficult for us to assist you.

I’d pay very careful attention to the voltage levels on the logic pins of your relay board with this set-up. If you can then find a specification sheet for the board, or do some tests with a stabilised variable power supply to see at which voltages the relays drop-out and re-engage then compare these to the actual voltages you are seeing on the pins.

Are you controlling any loads that have fans in them?
If so, you may need X rated capacitors across the load terminals to prevent interference.

Pete.

Yep i have a fan on one of the relay. And i have a X rated capacitor. And also i have another for snubber circuit.

Only after so much of testing i have soldered everything in place or else everything will be still on my breadboard. Previously i had no such issues. But from only from past 5 days i am facing this issue. And before 6 months or so i had faced the same problem and it went away on its own. GHOST PRESENCE :sweat_smile: