Relays on after reboot

Hello, I connected Blynk app on iphone to Nodemcu v0.9 on wifi to run 4 channel relay. Works fine, but when my nodemcu reboots, relay associated with Blynk buttons turn on automatically regardless of button status . It seems the board does not remember previous status of buttons. Help please.

  if (isFirstConnect) {
    Blynk.syncAll(); // use this to sync all the pins [not recommended]
    Blynk.syncVirtual(V1, V2, V3, V4); // sync only the virtural pins used in you Blynk app to sync the last state stored in the Blynk server.
    isFirstConnect = false;
  ReCnctCount = 0;

BLYNK_CONNECTED This function does what you are looking for. Please go through the docs to know more.

Thanks, but what shall I do with this, shall I creat a new sketch in Arduino IDE an dupload it, sorry Im just a biginner in this IOT.

I’d suggest you take a few steps back and get to know Arduino, Nodemcu and digital pin and relay behaviour first - then add Blynk/wifi on top of that.

Different pins have different behaviour on startup, some are pulled HIGH, some LOW, some momentary, some indeterminant etc . . . you need to research you board and see what is happening with the pins you are using in your sketch. Then you have a number of choice:

  1. Modify your sketch to accommodate the startup state for each pin;
  2. Select different pins that fit your need better, or
  3. Set the state of the pins (digitalWrite) on startup - this may work but you may still see erratic behaviour temporarily during startup.

You need to understand your hardware and adjust your sketch accordingly.


Thanks Bill, but your reply adds nothing to my question.
All what I need is to make my nodemcu remember the last state of the relay after power loss and that is why we have this community to share help. Some god guys may help in here

O…K… your comment shows that you have very, very little understanding of Arduino or the hardware . . .

It appears that you are basically asking for someone else to write a sketch for you? It won’t be me.

Good luck.


Bill is absolutely right.
What you are trying to do has a lot of hidden problems behind it.
It would be nice if you start to throw some light on the basics.

Here we only help to identify the issue and point out what you are missing on, but we do not write the code/sketch here. We are all volunteers here, no one is paying us(just for your info). ONLY BLYNK RELATED

There are not some, there are many big brains in this community, but without you knowing the basics, its very hard for us to point you out on the right direction.

Now you post your sketch here (properly formatted with ``` triple backticks or tilde).
I will try to help you out .
But learning by yourself will help you out in a long run.

1 Like

You have to memorize the state of the relays in a blynk virtual pin or store the state in the nodemcu memory.
Don’t forget that at start, relay will take the state of nodemcu pin till the code begin and restore the last value of the state.


This might help you choose better pins to use on your NodeMCU:

And reading-up about the Blynk.sync commands that were mentioned in the 2nd post will allow you to synchronize your relays with the state that is held on the server (if that’s actually what you want to do - it can be a dangerous or inappropriate choice).



It appears that you are basically asking for someone else to write a sketch for you? It won’t be me.

I believe you can’t @Bill_Donnelly

Thanks @Blynk_Coeur

1 Like

This doe not really helps @PeteKnight

A word of advice @1zaq1.
This is a community of users who willingly share their time and knowledge to help each other with (mostly) Blynk related stuff. @Bill_Donnelly is an extremely knowledgeable and well respected member of this community who has excellent coding skills and a wealth of experience of Blynk. As a result, this comment by you is totally inappropriate…

Bill’s advice to you was excellent, and I’m certain that all of the regulars who have contributed to this topic agree with him.

I’d suggest that you apologise to Bill for your comments, and learn a little humility. When you ask experts for advice and they give it freely then you’d do well to heed that advice and thank them for their time and patience rather than taking the approach that you did.

We expect forum members to behave in a friendly manner towards each other and those that don’t will have their use accounts suspended - either temporarily or permanently. Take this as your one and only reminder that inappropriate and unfriendly behaviour won’t be tolerated here.



Sorry to say… This is so RUDE.
Requesting some time helps. But being rude never helps. Everyone will step back.

I had told you to post your sketch, so that i can help you out, but you are asking for out of the box solution.

I feel no one will spoon feed you here.

1 Like

You feel it is rude to tell someone he does not know how to code, I have been told like this in the first post @Madhukesh, how it feels like

From the above replies I got, I come to the conclusion that you may know the hardware basics, and you know how to connect hardware, but I see you find it difficult to connect to people. Relax and if you do not like to provide help, no offense please

That user may be a beginner, doe not know how to code or whatever, you should not have used the word ‘rude’ @Madhukesh

Take it as a challenge and start learning… when i came here for the first time even i was treated the same way… i too felt too bad. But today this has made me learn hell lot of things.

If they had just gave me what i asked for, then i would have not been in a position to help you today. This is why there are so any volunteers(enhanced knowledge here) in this community able to help others.

I learnt many things from this community, now i am trying to serve a back a bit…

The way you spoke you @Bill_Donnelly is totally wrong…

@PeteKnight it is left to you. See how you can go through this…

1 Like

@Madhukesh you used the word ‘rude’ for the second time. I hope other users got a better experience in this community

@Bill_Donnelly unfortunately you won’t be getting an apology from @1zaq1 for the while, as I’ve silenced him for the rest of the week due to the tone of his comments.