BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

How to make sure that when you turn on one button, the rest are turned off?

Hi everyone! I use NodeMCU v3 with esp8266, I need to make it so that only one button always works, when I turn on one, the others turn off, let’s say there is button 1 and button 2. Button 1 is on, when button 2 is turned on, button 1 should turn off and on the contrary.I have 8 relays and I need to make sure that when you turn on one relay using the button in blynk, all the others are turned off. Buttons made on virtual pins. I
Thank you for your attention and good mood to all!

How good are your C++ programming skills?

Pete.

I apologize for being stupid. I just started to learn C ++. I think it’s possible somehow through “if”. Here is my code. Thank you

#define RELE2 D2
#define RELE3 D3
#define RELE4 D4
#define RELE5 D5
#define RELE6 D6
#define RELE7 D7
#define RELE8 D8
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
bool brele1;
bool brele2;
bool brele3;
bool brele4;
bool brele5;
bool brele6;
bool brele7;
bool brele8;

char auth[] = "******";
char ssid[] = "****";
char pass[] = "*****";

void setup()
{
  Serial.begin(115200);
  Blynk.begin(auth,ssid,pass);
  pinMode(RELE1,OUTPUT);
  pinMode(RELE2,OUTPUT);
  pinMode(RELE3,OUTPUT);
  pinMode(RELE4,OUTPUT);
  pinMode(RELE5,OUTPUT);
  pinMode(RELE6,OUTPUT);
  pinMode(RELE7,OUTPUT);
  pinMode(RELE8,OUTPUT);
  
  digitalWrite(RELE1,HIGH);
  digitalWrite(RELE2,HIGH);
  digitalWrite(RELE3,HIGH);
  digitalWrite(RELE4,HIGH);
  digitalWrite(RELE5,HIGH);
  digitalWrite(RELE6,HIGH);
  digitalWrite(RELE7,HIGH);
  digitalWrite(RELE8,HIGH);

  Blynk.virtualWrite(1,HIGH);
  Blynk.virtualWrite(2,HIGH);
  Blynk.virtualWrite(3,HIGH);
  Blynk.virtualWrite(4,HIGH);
  Blynk.virtualWrite(5,HIGH);
  Blynk.virtualWrite(6,HIGH);
  Blynk.virtualWrite(7,HIGH);
  Blynk.virtualWrite(8,HIGH);
  }

  BLYNK_WRITE(V1)
  {
  brele1 = param.asInt();
  digitalWrite(RELE1,brele1);
  }
  BLYNK_WRITE(V2)
  {
  brele2 = param.asInt();
  digitalWrite(RELE2,brele2);
  }
  BLYNK_WRITE(V3)
  {
  brele3 = param.asInt();
  digitalWrite(RELE3,brele3);
  }
  BLYNK_WRITE(V4)
  {
  brele4 = param.asInt();
  digitalWrite(RELE4,brele4);
  }
  BLYNK_WRITE(V5)
  {
  brele5 = param.asInt();
  digitalWrite(RELE5,brele5);
  }
  BLYNK_WRITE(V6)
  {
  brele6 = param.asInt();
  digitalWrite(RELE6,brele6);
  }
  BLYNK_WRITE(V7)
  {
  brele7 = param.asInt();
  digitalWrite(RELE7,brele7);
  }
  BLYNK_WRITE(V8)
  {
  brele8 = param.asInt();
  digitalWrite(RELE8,brele8);
  }
void loop()
{
  Blynk.run();
} ```

Please Help me.Thanks!

@nehetos please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

I have edited. I apologize for the error.Please help me with my trouble.Thanks in advance!

This needs to be expanded with digitalWrites that turn the other relays off, when RELE1 is turned on.

The same needs to happen for the other BLYNK_WRITE commands as well.

Pete.

Can you please show an example on one? I don’t really know how to write:(

BLYNK_WRITE(V1)
{
brele1 = param.asInt();
digitalWrite(RELE1,brele1);
digitalWrite(RELE2,LOW);
digitalWrite(RELE3,LOW);
digitalWrite(RELE4,LOW);
digitalWrite(RELE5,LOW);
digitalWrite(RELE6,LOW);
digitalWrite(RELE7,LOW);
digitalWrite(RELE8,LOW);
}

Maybe like this?

You’ll need an if statement in there, so that it only does this when the switch is turned on. You’ll also need to update the Blynk switch widgets with Blynk.virtualWrite statements.
Note that it depends if your relays are active HIGH or LOW. If they turn on when you want them off then change the LOWs to HIGHs.

BLYNK_WRITE(V1)
{
brele1 = param.asInt();
if (brele1 ==1)
  {
    digitalWrite(RELE1,brele1);
    digitalWrite(RELE2,LOW);
    digitalWrite(RELE3,LOW);
    digitalWrite(RELE4,LOW);
    digitalWrite(RELE5,LOW);
    digitalWrite(RELE6,LOW);
    digitalWrite(RELE7,LOW);
    digitalWrite(RELE8,LOW);
    Blynk.virtualWrite(V2,0);
    Blynk.virtualWrite(V3,0);
    Blynk.virtualWrite(V4,0);
  \\ repeat the other virtual pins in here.....
  }
}

Pete.

Thank you very much, everything worked, but there is one problem, now when all the relay buttons are off in Blynk, all the relays are working. I tried to solve this problem by writing such a code to each BLYNK_WRITE. But it didn’t work, help me please.
Or one relay stays on, again in Blynk all the buttons are off.
In general, now I can not turn off all the relays( HELP ME PLEASE. Thank you!

 if (brele1 ==0)
    {
     digitalWrite(RELE1,LOW);
     digitalWrite(RELE2,LOW);
     digitalWrite(RELE3,LOW);
     digitalWrite(RELE4,LOW);
     digitalWrite(RELE5,LOW);
     digitalWrite(RELE6,LOW);
     digitalWrite(RELE7,LOW);
     digitalWrite(RELE8,LOW);
     Blynk.virtualWrite(V1,0);
     Blynk.virtualWrite(V2,0);
     Blynk.virtualWrite(V3,0);
     Blynk.virtualWrite(V4,0);
     Blynk.virtualWrite(V5,0);
     Blynk.virtualWrite(V6,0);
     Blynk.virtualWrite(V7,0);
     Blynk.virtualWrite(V8,0); 
    }

Whole code:

#define RELE1 D1
#define RELE2 D2
#define RELE3 D3
#define RELE4 D4
#define RELE5 D5
#define RELE6 D6
#define RELE7 D7
#define RELE8 D8
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
bool brele1;
bool brele2;
bool brele3;
bool brele4;
bool brele5;
bool brele6;
bool brele7;
bool brele8;

char auth[] = "******";
char ssid[] = "******";
char pass[] = "************";

void setup()
{
  Serial.begin(115200);
  Blynk.begin(auth,ssid,pass);
  pinMode(RELE1,OUTPUT);
  pinMode(RELE2,OUTPUT);
  pinMode(RELE3,OUTPUT);
  pinMode(RELE4,OUTPUT);
  pinMode(RELE5,OUTPUT);
  pinMode(RELE6,OUTPUT);
  pinMode(RELE7,OUTPUT);
  pinMode(RELE8,OUTPUT);
  
  digitalWrite(RELE1,HIGH);
  digitalWrite(RELE2,HIGH);
  digitalWrite(RELE3,HIGH);
  digitalWrite(RELE4,HIGH);
  digitalWrite(RELE5,HIGH);
  digitalWrite(RELE6,HIGH);
  digitalWrite(RELE7,HIGH);
  digitalWrite(RELE8,HIGH);

  Blynk.virtualWrite(1,HIGH);
  Blynk.virtualWrite(2,HIGH);
  Blynk.virtualWrite(3,HIGH);
  Blynk.virtualWrite(4,HIGH);
  Blynk.virtualWrite(5,HIGH);
  Blynk.virtualWrite(6,HIGH);
  Blynk.virtualWrite(7,HIGH);
  Blynk.virtualWrite(8,HIGH);
  }
  
  BLYNK_WRITE(V1)
  {
  brele1 = param.asInt();
  if (brele1 ==1)
    {
     digitalWrite(RELE1,brele1);
     digitalWrite(RELE2,LOW);
     digitalWrite(RELE3,LOW);
     digitalWrite(RELE4,LOW);
     digitalWrite(RELE5,LOW);
     digitalWrite(RELE6,LOW);
     digitalWrite(RELE7,LOW);
     digitalWrite(RELE8,LOW);
     Blynk.virtualWrite(V2,0);
     Blynk.virtualWrite(V3,0);
     Blynk.virtualWrite(V4,0);
     Blynk.virtualWrite(V5,0);
     Blynk.virtualWrite(V6,0);
     Blynk.virtualWrite(V7,0);
     Blynk.virtualWrite(V8,0);
    }
  }
  BLYNK_WRITE(V2)
  {
  brele2 = param.asInt();
  if (brele2 ==1)
    {
     digitalWrite(RELE2,brele2);
     digitalWrite(RELE1,LOW);
     digitalWrite(RELE3,LOW);
     digitalWrite(RELE4,LOW);
     digitalWrite(RELE5,LOW);
     digitalWrite(RELE6,LOW);
     digitalWrite(RELE7,LOW);
     digitalWrite(RELE8,LOW);
     Blynk.virtualWrite(V1,0);
     Blynk.virtualWrite(V3,0);
     Blynk.virtualWrite(V4,0);
     Blynk.virtualWrite(V5,0);
     Blynk.virtualWrite(V6,0);
     Blynk.virtualWrite(V7,0);
     Blynk.virtualWrite(V8,0);
     }
  }
  BLYNK_WRITE(V3)
  {
  brele3 = param.asInt();
  if (brele3 ==1)
    {
     digitalWrite(RELE3,brele3);
     digitalWrite(RELE1,LOW);
     digitalWrite(RELE2,LOW);
     digitalWrite(RELE4,LOW);
     digitalWrite(RELE5,LOW);
     digitalWrite(RELE6,LOW);
     digitalWrite(RELE7,LOW);
     digitalWrite(RELE8,LOW);
     Blynk.virtualWrite(V1,0);
     Blynk.virtualWrite(V2,0);
     Blynk.virtualWrite(V4,0);
     Blynk.virtualWrite(V5,0);
     Blynk.virtualWrite(V6,0);
     Blynk.virtualWrite(V7,0);
     Blynk.virtualWrite(V8,0);
    }
  }
  BLYNK_WRITE(V4)
  {
  brele4 = param.asInt();
  if (brele4 ==1)
    {
     digitalWrite(RELE4,brele4);
     digitalWrite(RELE1,LOW);
     digitalWrite(RELE2,LOW);
     digitalWrite(RELE3,LOW);
     digitalWrite(RELE5,LOW);
     digitalWrite(RELE6,LOW);
     digitalWrite(RELE7,LOW);
     digitalWrite(RELE8,LOW);
     Blynk.virtualWrite(V1,0);
     Blynk.virtualWrite(V2,0);
     Blynk.virtualWrite(V3,0);
     Blynk.virtualWrite(V5,0);
     Blynk.virtualWrite(V6,0);
     Blynk.virtualWrite(V7,0);
     Blynk.virtualWrite(V8,0);
    }
  }
  BLYNK_WRITE(V5)
  {
  brele5 = param.asInt();
  if (brele5 ==1)
    {
     digitalWrite(RELE5,brele5);
     digitalWrite(RELE1,LOW);
     digitalWrite(RELE2,LOW);
     digitalWrite(RELE3,LOW);
     digitalWrite(RELE4,LOW);
     digitalWrite(RELE6,LOW);
     digitalWrite(RELE7,LOW);
     digitalWrite(RELE8,LOW);
     Blynk.virtualWrite(V1,0);
     Blynk.virtualWrite(V2,0);
     Blynk.virtualWrite(V3,0);
     Blynk.virtualWrite(V4,0);
     Blynk.virtualWrite(V6,0);
     Blynk.virtualWrite(V7,0);
     Blynk.virtualWrite(V8,0);
    }
  }
  BLYNK_WRITE(V6)
  {
  brele6 = param.asInt();
  if (brele6 ==1)
    {
     digitalWrite(RELE6,brele6);
     digitalWrite(RELE1,LOW);
     digitalWrite(RELE2,LOW);
     digitalWrite(RELE3,LOW);
     digitalWrite(RELE4,LOW);
     digitalWrite(RELE5,LOW);
     digitalWrite(RELE7,LOW);
     digitalWrite(RELE8,LOW);
     Blynk.virtualWrite(V1,0);
     Blynk.virtualWrite(V2,0);
     Blynk.virtualWrite(V3,0);
     Blynk.virtualWrite(V4,0);
     Blynk.virtualWrite(V5,0);
     Blynk.virtualWrite(V7,0);
     Blynk.virtualWrite(V8,0);
    }
  }
  BLYNK_WRITE(V7)
  {
  brele7 = param.asInt();
  if (brele7 ==1)
    {
     digitalWrite(RELE7,brele7);
     digitalWrite(RELE1,LOW);
     digitalWrite(RELE2,LOW);
     digitalWrite(RELE3,LOW);
     digitalWrite(RELE4,LOW);
     digitalWrite(RELE5,LOW);
     digitalWrite(RELE6,LOW);
     digitalWrite(RELE8,LOW);
     Blynk.virtualWrite(V1,0);
     Blynk.virtualWrite(V2,0);
     Blynk.virtualWrite(V3,0);
     Blynk.virtualWrite(V4,0);
     Blynk.virtualWrite(V5,0);
     Blynk.virtualWrite(V6,0);
     Blynk.virtualWrite(V8,0);
    }
  }
  BLYNK_WRITE(V8)
  {
  brele8 = param.asInt();
  if (brele8 ==1)
    {
     digitalWrite(RELE8,brele8);
     digitalWrite(RELE1,LOW);
     digitalWrite(RELE2,LOW);
     digitalWrite(RELE3,LOW);
     digitalWrite(RELE4,LOW);
     digitalWrite(RELE5,LOW);
     digitalWrite(RELE6,LOW);
     digitalWrite(RELE7,LOW);
     Blynk.virtualWrite(V1,0);
     Blynk.virtualWrite(V2,0);
     Blynk.virtualWrite(V3,0);
     Blynk.virtualWrite(V4,0);
     Blynk.virtualWrite(V5,0);
     Blynk.virtualWrite(V6,0);
     Blynk.virtualWrite(V7,0);
    }
  }
void loop()
{
  Blynk.run();
}

Okay, you probably need an else in these to turn the relay off when the switch widget goes off…

BLYNK_WRITE(V1)
  {
  brele1 = param.asInt();
  if (brele1 ==1)
    {
     digitalWrite(RELE1,brele1);
     digitalWrite(RELE2,LOW);
     digitalWrite(RELE3,LOW);
     digitalWrite(RELE4,LOW);
     digitalWrite(RELE5,LOW);
     digitalWrite(RELE6,LOW);
     digitalWrite(RELE7,LOW);
     digitalWrite(RELE8,LOW);
     Blynk.virtualWrite(V2,0);
     Blynk.virtualWrite(V3,0);
     Blynk.virtualWrite(V4,0);
     Blynk.virtualWrite(V5,0);
     Blynk.virtualWrite(V6,0);
     Blynk.virtualWrite(V7,0);
     Blynk.virtualWrite(V8,0);
    }
    else
    {
     digitalWrite(RELE1,!brele1);
    }
  }

Pete.

Thank you,Pete!..
But unfortunately this does not work (Relays still do not turn off.Look:

BLYNK_WRITE(V1)
  {
  brele1 = param.asInt();
  if (brele1 ==1)
    {
     digitalWrite(RELE1,brele1);
     digitalWrite(RELE2,LOW);
     digitalWrite(RELE3,LOW);
     digitalWrite(RELE4,LOW);
     digitalWrite(RELE5,LOW);
     digitalWrite(RELE6,LOW);
     digitalWrite(RELE7,LOW);
     digitalWrite(RELE8,LOW);
     Blynk.virtualWrite(V2,0);
     Blynk.virtualWrite(V3,0);
     Blynk.virtualWrite(V4,0);
     Blynk.virtualWrite(V5,0);
     Blynk.virtualWrite(V6,0);
     Blynk.virtualWrite(V7,0);
     Blynk.virtualWrite(V8,0);
    }
    else
    {
      digitalWrite(RELE1,!brele1);
    }
  }
  BLYNK_WRITE(V2)
  {
  brele2 = param.asInt();
  if (brele2 ==1)
    {
     digitalWrite(RELE2,brele2);
     digitalWrite(RELE1,LOW);
     digitalWrite(RELE3,LOW);
     digitalWrite(RELE4,LOW);
     digitalWrite(RELE5,LOW);
     digitalWrite(RELE6,LOW);
     digitalWrite(RELE7,LOW);
     digitalWrite(RELE8,LOW);
     Blynk.virtualWrite(V1,0);
     Blynk.virtualWrite(V3,0);
     Blynk.virtualWrite(V4,0);
     Blynk.virtualWrite(V5,0);
     Blynk.virtualWrite(V6,0);
     Blynk.virtualWrite(V7,0);
     Blynk.virtualWrite(V8,0);
     }
     else
      {
        digitalWrite(RELE2,!brele2);
      }
  }
  brele1 = param.asInt();
  if (brele1 ==1)
    {
     digitalWrite(RELE1,brele1);
    }
    else
    {
      digitalWrite(RELE1,!brele1);
    }

Doesn’t make much sense, you’re always turning it on. Just go with digitalWrite(RELE1, LOW); in the else section.

Now I’m confused. Doesn’t

digitalWrite(RELE1,!brele1);

Mean Not? Because of the “!”?

1 Like

I ran into this and I wrote this function for Particle devices but this should work for yours I believe or maybe give you an idea of what to do. It’s in the language you want I believe. Later on I was going to add things like have it auto know how many buttons are in array and more advance know what is linked together automatically without having to change code changing only something in Blynk app… , but this should work for you!!!

    void turnOffBtns(int btnSwitchOn)
    {
    int i = 0;
    int j = 0;
    int btnSwitches[12] = {5,6,7,8,9,10,11,12,14,15,17,50};// Which virtual pins are to be linked together? Remember to change "int btnSwitches[12]" to the correct amount of buttons.

            for(i=0; i<127; i++) {//Check all 128 virtual pins
                    for(j=0; j<12; j++) { //Only check the correct amount in array. Remember to change "12" to the same number as "int btnSwitches[12]"
                            
                            if(i == btnSwitches[j]){//btnSwitches check buttons that we list only to turn off.  We check only those we really want out of total virtual pins
                    
                                    if(i == btnSwitchOn){//Turn on the one we want if it's a match with the virtual pin that was passed into function
                                            Blynk.virtualWrite(btnSwitchOn,HIGH);

                                    } else {// Turn off all other button/virtual pins from list if it's not the virtual pin that was passed into the function..
                                            Blynk.virtualWrite(i,LOW);
                                    }
                            }
                    }
             }
    }


turnOffBtns(5);// Place in your code wherever, call function with this. Turn Virtual Pin 5 "ON" Only.

Hope this helps. I hate hard coding things and always try to find a way to have less code… Also I haven’t tried it but will at some point and have been thinking about putting BLYNK_WRITE(btnSwitchOn); in this function or something like that in it’s own separate function and use the usual sets of code with if statements one time rather than 12 different times. Goal would be to just not write 12 cases of the below with the same code every time like we all do…

     BLYNK_WRITE(V5)
     {
             int thisBtn = param.asInt();
              if (thisBtn == 1)
                       turnOffBtns(5)
              }
     }

Hi, thank you very much for your code! But I’m new to programming, can you please show where to insert
and how it will look in my code, this part:

 void turnOffBtns(int btnSwitchOn)
    {
    int i = 0;
    int j = 0;
    int btnSwitches[12] = {5,6,7,8,9,10,11,12,14,15,17,50};// Which virtual pins are to be linked together? Remember to change "int btnSwitches[12]" to the correct amount of buttons.

            for(i=0; i<127; i++) {//Check all 128 virtual pins
                    for(j=0; j<12; j++) { //Only check the correct amount in array. Remember to change "12" to the same number as "int btnSwitches[12]"
                            
                            if(i == btnSwitches[j]){//btnSwitches check buttons that we list only to turn off.  We check only those we really want out of total virtual pins
                    
                                    if(i == btnSwitchOn){//Turn on the one we want if it's a match with the virtual pin that was passed into function
                                            Blynk.virtualWrite(btnSwitchOn,HIGH);

                                    } else {// Turn off all other button/virtual pins from list if it's not the virtual pin that was passed into the function..
                                            Blynk.virtualWrite(i,LOW);
                                    }
                            }
                    }
             }
    }

And this is my code:

#define RELE1 D1
#define RELE2 D2
#define RELE3 D3
#define RELE4 D4
#define RELE5 D5
#define RELE6 D6
#define RELE7 D7
#define RELE8 D8
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
bool brele1;
bool brele2;
bool brele3;
bool brele4;
bool brele5;
bool brele6;
bool brele7;
bool brele8;

char auth[] = "6Vc4Oz-NCAzKp10lPHFiFMQxLMdRfkFA";
char ssid[] = "tenet";
char pass[] = "30121969";

void setup()
{
  Serial.begin(115200);
  Blynk.begin(auth,ssid,pass);
  pinMode(RELE1,OUTPUT);
  pinMode(RELE2,OUTPUT);
  pinMode(RELE3,OUTPUT);
  pinMode(RELE4,OUTPUT);
  pinMode(RELE5,OUTPUT);
  pinMode(RELE6,OUTPUT);
  pinMode(RELE7,OUTPUT);
  pinMode(RELE8,OUTPUT);
  
  digitalWrite(RELE1,HIGH);
  digitalWrite(RELE2,HIGH);
  digitalWrite(RELE3,HIGH);
  digitalWrite(RELE4,HIGH);
  digitalWrite(RELE5,HIGH);
  digitalWrite(RELE6,HIGH);
  digitalWrite(RELE7,HIGH);
  digitalWrite(RELE8,HIGH);

  Blynk.virtualWrite(1,HIGH);
  Blynk.virtualWrite(2,HIGH);
  Blynk.virtualWrite(3,HIGH);
  Blynk.virtualWrite(4,HIGH);
  Blynk.virtualWrite(5,HIGH);
  Blynk.virtualWrite(6,HIGH);
  Blynk.virtualWrite(7,HIGH);
  Blynk.virtualWrite(8,HIGH);
  }
  
  BLYNK_WRITE(V1)
  {
  brele1 = param.asInt();
  if (brele1 ==1)
    {
     digitalWrite(RELE1,brele1);
     digitalWrite(RELE2,LOW);
     digitalWrite(RELE3,LOW); 
     digitalWrite(RELE4,LOW);
     digitalWrite(RELE5,LOW);
     digitalWrite(RELE6,LOW);
     digitalWrite(RELE7,LOW);
     digitalWrite(RELE8,LOW);
     Blynk.virtualWrite(V2,0);
     Blynk.virtualWrite(V3,0);
     Blynk.virtualWrite(V4,0);
     Blynk.virtualWrite(V5,0);
     Blynk.virtualWrite(V6,0);
     Blynk.virtualWrite(V7,0);
     Blynk.virtualWrite(V8,0);
    }
  }
  BLYNK_WRITE(V2)
  {
  brele2 = param.asInt();
  if (brele2 ==1)
    {
     digitalWrite(RELE2,brele2);
     digitalWrite(RELE1,LOW);
     digitalWrite(RELE3,LOW);
     digitalWrite(RELE4,LOW);
     digitalWrite(RELE5,LOW);
     digitalWrite(RELE6,LOW);
     digitalWrite(RELE7,LOW);
     digitalWrite(RELE8,LOW);
     Blynk.virtualWrite(V1,0);
     Blynk.virtualWrite(V3,0);
     Blynk.virtualWrite(V4,0);
     Blynk.virtualWrite(V5,0);
     Blynk.virtualWrite(V6,0);
     Blynk.virtualWrite(V7,0);
     Blynk.virtualWrite(V8,0);
     }
  }
  BLYNK_WRITE(V3)
  {
  brele3 = param.asInt();
  if (brele3 ==1)
    {
     digitalWrite(RELE3,brele3);
     digitalWrite(RELE1,LOW);
     digitalWrite(RELE2,LOW);
     digitalWrite(RELE4,LOW);
     digitalWrite(RELE5,LOW);
     digitalWrite(RELE6,LOW);
     digitalWrite(RELE7,LOW);
     digitalWrite(RELE8,LOW);
     Blynk.virtualWrite(V1,0);
     Blynk.virtualWrite(V2,0);
     Blynk.virtualWrite(V4,0);
     Blynk.virtualWrite(V5,0);
     Blynk.virtualWrite(V6,0);
     Blynk.virtualWrite(V7,0);
     Blynk.virtualWrite(V8,0);
    }
  }
  BLYNK_WRITE(V4)
  {
  brele4 = param.asInt();
  if (brele4 ==1)
    {
     digitalWrite(RELE4,brele4);
     digitalWrite(RELE1,LOW);
     digitalWrite(RELE2,LOW);
     digitalWrite(RELE3,LOW);
     digitalWrite(RELE5,LOW);
     digitalWrite(RELE6,LOW);
     digitalWrite(RELE7,LOW);
     digitalWrite(RELE8,LOW);
     Blynk.virtualWrite(V1,0);
     Blynk.virtualWrite(V2,0);
     Blynk.virtualWrite(V3,0);
     Blynk.virtualWrite(V5,0);
     Blynk.virtualWrite(V6,0);
     Blynk.virtualWrite(V7,0);
     Blynk.virtualWrite(V8,0);
    }
  }
  BLYNK_WRITE(V5)
  {
  brele5 = param.asInt();
  if (brele5 ==1)
    {
     digitalWrite(RELE5,brele5);
     digitalWrite(RELE1,LOW);
     digitalWrite(RELE2,LOW);
     digitalWrite(RELE3,LOW);
     digitalWrite(RELE4,LOW);
     digitalWrite(RELE6,LOW);
     digitalWrite(RELE7,LOW);
     digitalWrite(RELE8,LOW);
     Blynk.virtualWrite(V1,0);
     Blynk.virtualWrite(V2,0);
     Blynk.virtualWrite(V3,0);
     Blynk.virtualWrite(V4,0);
     Blynk.virtualWrite(V6,0);
     Blynk.virtualWrite(V7,0);
     Blynk.virtualWrite(V8,0);
    }
  }
  BLYNK_WRITE(V6)
  {
  brele6 = param.asInt();
  if (brele6 ==1)
    {
     digitalWrite(RELE6,brele6);
     digitalWrite(RELE1,LOW);
     digitalWrite(RELE2,LOW);
     digitalWrite(RELE3,LOW);
     digitalWrite(RELE4,LOW);
     digitalWrite(RELE5,LOW);
     digitalWrite(RELE7,LOW);
     digitalWrite(RELE8,LOW);
     Blynk.virtualWrite(V1,0);
     Blynk.virtualWrite(V2,0);
     Blynk.virtualWrite(V3,0);
     Blynk.virtualWrite(V4,0);
     Blynk.virtualWrite(V5,0);
     Blynk.virtualWrite(V7,0);
     Blynk.virtualWrite(V8,0);
    }
  }
  BLYNK_WRITE(V7)
  {
  brele7 = param.asInt();
  if (brele7 ==1)
    {
     digitalWrite(RELE7,brele7);
     digitalWrite(RELE1,LOW);
     digitalWrite(RELE2,LOW);
     digitalWrite(RELE3,LOW);
     digitalWrite(RELE4,LOW);
     digitalWrite(RELE5,LOW);
     digitalWrite(RELE6,LOW);
     digitalWrite(RELE8,LOW);
     Blynk.virtualWrite(V1,0);
     Blynk.virtualWrite(V2,0);
     Blynk.virtualWrite(V3,0);
     Blynk.virtualWrite(V4,0);
     Blynk.virtualWrite(V5,0);
     Blynk.virtualWrite(V6,0);
     Blynk.virtualWrite(V8,0);
    }
  }
  BLYNK_WRITE(V8)
  {
  brele8 = param.asInt();
  if (brele8 ==1)
    {
     digitalWrite(RELE8,brele8);
     digitalWrite(RELE1,LOW);
     digitalWrite(RELE2,LOW);
     digitalWrite(RELE3,LOW);
     digitalWrite(RELE4,LOW);
     digitalWrite(RELE5,LOW);
     digitalWrite(RELE6,LOW);
     digitalWrite(RELE7,LOW);
     Blynk.virtualWrite(V1,0);
     Blynk.virtualWrite(V2,0);
     Blynk.virtualWrite(V3,0);
     Blynk.virtualWrite(V4,0);
     Blynk.virtualWrite(V5,0);
     Blynk.virtualWrite(V6,0);
     Blynk.virtualWrite(V7,0);
    }
  }
void loop()
{
  Blynk.run();
}

THANKS!

Hello!Thank you,But still the relay remains on:(

@nehetos can you confirm if your relays activated when they have a LOW signal applied, or a HIGH signal?

Understanding this will make the coding much easier.

Pete.

If I write like this, then 1 and 2 relays do not turn on at all. I have only done 2 relays so far and when I turn on the first or second, then none work (

BLYNK_WRITE(V1)
  {
  brele1 = param.asInt();
  if (brele1 ==1)
    {
     digitalWrite(RELE1,brele1);
     digitalWrite(RELE2,HIGH);
     digitalWrite(RELE3,HIGH); 
     digitalWrite(RELE4,HIGH);
     digitalWrite(RELE5,HIGH);
     digitalWrite(RELE6,HIGH);
     digitalWrite(RELE7,HIGH);
     digitalWrite(RELE8,HIGH);
     Blynk.virtualWrite(V2,0);
     Blynk.virtualWrite(V3,0);
     Blynk.virtualWrite(V4,0);
     Blynk.virtualWrite(V5,0);
     Blynk.virtualWrite(V6,0);
     Blynk.virtualWrite(V7,0);
     Blynk.virtualWrite(V8,0);
    }
  }
  BLYNK_WRITE(V2)
  {
  brele2 = param.asInt();
  if (brele2 ==1)
    {
     digitalWrite(RELE2,brele2);
     digitalWrite(RELE1,HIGH);
     digitalWrite(RELE3,HIGH);
     digitalWrite(RELE4,HIGH);
     digitalWrite(RELE5,HIGH);
     digitalWrite(RELE6,HIGH);
     digitalWrite(RELE7,HIGH);
     digitalWrite(RELE8,HIGH);
     Blynk.virtualWrite(V1,0);
     Blynk.virtualWrite(V3,0);
     Blynk.virtualWrite(V4,0);
     Blynk.virtualWrite(V5,0);
     Blynk.virtualWrite(V6,0);
     Blynk.virtualWrite(V7,0);
     Blynk.virtualWrite(V8,0);
     }
  }