Controlling 4 bulbs at once in single button

HI Team,
I successfully connected 4 bulbs in my home with Blynk app, It has 4 button to control each bulb.

Now I need to turn on all 4 bulbs at once using single button
please advice both side which program and app side how to add 4 gpio pins to single button and how program using Arduino IDE

Thanks in advanced

First, you need to decide the logic for this master switch. If it’s an on/off button widget, how do you want it to respond when just one, two or 3 of your individual lights are turned on?
Do you want the master switch to still show ‘off’, so that pressing it will turn the remaining lights on? Maybe not what you want if you’re trying to turn everything that is already on into the off state?

An alternative may be two button widgets in pushbutton mode, one labelled “all on” and the other “all off”.

Once you’ve decided on the desired logic/functionality then you can begin coding.

Pete.

1 Like

Dear pete Thanks for advice and reply

I have decided the logic for the master switch , Just simply added a button and assigned a gpio pin . That is all in the Blynk app side

Now I need to program it in the Arduino iDE

it is very simple to check the signal coming from the gpio pin using “if” statement and activate all the io pins which is control the bulbs

The issue what I have is blynk.run();

Do I need to remove the function called blynk.run();

Please advice

Sorry, as you haven’t shared what the logic will be, its difficult to advise. However, what I would say, based on what you have shared is:

You’d be much better off assigning a virtual pin.

Blynk.run should be in your void loop, and nothing else - except maybe timer.run of you’re planning on checking a GPIO pin on a regular basis - but not needed if you use a virtual pin as suggested.

You’ll probably need to do pinMode statements for each in in your void setup.
You’ll also need to update your ‘master’ button via a Blynk.virtualWrite (assuming you go for the virtual pin suggestion), but the logic behind when you do this is what I was discussing initially.

Blynk.run is a command, not a function. It needs to be inside the function called void loop, which executes continuously.

Pete.

Dear Pete My respect for detailed reply
Still I do not understand the logic
I have created 4 buttons
Button_1 is assigned to gp4
Button_ 2 is assigned to gp16
Button_3 is assigned to gp0
Button_4 is assigned to gp5

Now I need to create new button called Button_5 to turn on all the bulbs at once

Suppose we assigned a V10 for Button_5 , Then how all bulbs turn on without code when pressed Button_5

Please advice
Thanks in advanced

You just want to turn all the bulbs ON with this bitton, not OFF ?

What do you mean by “without code”

Pete.

It cannot be done without code. Basic GPIO pin manipulation can be done using the basic BLYNK Sketch. For more advanced features, like turning multiple GPIOs ON/OFF at one time, you will need to add more code to the Sketch.

1 Like

Sorry I need to Turn ON and Turn OFF all the bulbs at once

Without code mean
In the void loop() of Arduino IDE

This would also be a good time to get away from direct GPIO pin manipulation with the app buttons, and move into the world of virtual pins. This allows for updating the button states on the app. Which is what you will want to do if you are adding a master button. Otherwise, when you use the master button to turn all lights ON, the other buttons will still show OFF.

For the single buttons You would use this function. You would change the virtual pin for each one.

BLYNK_WRITE(V1)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable 
   if (pinValue == 1)
      {
        digitalWrite(4, HIGH); //or LOW if relay is active LOW
      }
   else
    {
      digitalWrite(4, LOW); //or HIGH if relay is active LOW
    }
}

for the Master button You would use this function.

BLYNK_WRITE(V5)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable 
   if (pinValue == 1)
      {
        digitalWrite(4, HIGH); //or LOW if relay is active LOW
        digitalWrite(16, HIGH); //or LOW if relay is active LOW
        digitalWrite(0, HIGH); //or LOW if relay is active LOW
        digitalWrite(5, HIGH); //or LOW if relay is active LOW
        Blynk.virtualWrite(V1, HIGH);//or LOW if relay is active LOW
        Blynk.virtualWrite(V2, HIGH);//or LOW if relay is active LOW
        Blynk.virtualWrite(V3, HIGH);//or LOW if relay is active LOW
        Blynk.virtualWrite(V4, HIGH);//or LOW if relay is active LOW
      }
   else
    {
        digitalWrite(4, LOW); //or HIGH if relay is active LOW
        digitalWrite(16, LOW); //or HIGH if relay is active LOW
        digitalWrite(0, LOW); //or HIGH if relay is active LOW
        digitalWrite(5, LOW); //or HIGH if relay is active LOW
        Blynk.virtualWrite(V1, LOW);//or HIGH if relay is active LOW
        Blynk.virtualWrite(V2, LOW);//or HIGH if relay is active LOW
        Blynk.virtualWrite(V3, LOW);//or HIGH if relay is active LOW
        Blynk.virtualWrite(V4, LOW);//or HIGH if relay is active LOW
    }
}
1 Like

Are all the bulbs connected to a single ESP8266 board or 4 different modules ?
If its all in the same module then you will have to go for @Toro_Blanco code mentioned in the previous post.

If there are separate modules for each bulb then you can use Blynk tag to achieve what you are looking for without coding.

Dear Toro Thanks for the reply and advice

Now it is very clear everything

Can you please explain the reason for following code

Blynk.virtualWrite(V1, HIGH);//or LOW if relay is active LOW
Blynk.virtualWrite(V2, HIGH);//or LOW if relay is active LOW
Blynk.virtualWrite(V3, HIGH);//or LOW if relay is active LOW
Blynk.virtualWrite(V4, HIGH);//or LOW if relay is active LOW

Thanks in advanced

Dear Madhukesh Thanks for reply

Still I am using single module

Thanks

@dayan, you need to take a step back here, because you didn’t understand my first post about the logic.

The master button widget is itself a switch, it has two states - On and Off.
For you to use it to switch all of your lights that are on into the off state, then you want your master switch to be in the On state itself, so that turning it to Off also turns all of your lights off.

If one of your lights is on, because you’ve turned it on with the individual switch, and you then want to turn the other three lights on using the master switch, your master switch needs to be in the Off position, otherwise you will first of all be turning the single light off, before turning all of the lights on. This is undesirable from my point of view, because if your room is in darkness except for the light from your one bulb, turning that off - and making the room totally dark before then turning all of the bulbs on - has safety implications and certainly isn’t what you would normally do if manually controlling the lights.

Also, the opposite applies when you want to turn the lights off. If you have one or two lights on, but then want to turn them off before going to bed, you wouldn’t normally turn all of the lights on, before then turning them all off.
To achieve this then your master switch needs to be in the On position, but that conflicts with what I’ve described above.

For this reason, I don’t believe that one switch is actually the correct solution for your requirements. a better solution would be a push (non latching) button for “all on” and another for “all off”.

The desired operational logic is what you need to decide before you start designing the solution. Otherwise it’s a bit like starting to build a house without a proper plan for what the completed building will look like.

Pete.

1 Like

Dear Pete Thanks for the very detailed reply

I just understood what you ware explaining in your first reply , I am sorry that is my fault

Your point is very correct but first I need to get the experience my self to turn On and OFF all bulbs at once using single button So then I will face the issue what you have explaining

Thanks for your kind support

Agreed. And your above explanation is not something I considered. With my example above, if you happen to turn on all of the lights via the single Switch, and then want to turn them all OFF via the master Switch. You would have to push it twice, as the master switch would start as OFF. So you would have to turn it ON, and then OFF so that it issued the correct commands.

2 Likes

Hi
Iwant todo my iot project with arduino uno and esp 8266 . And i use the example code but arduino ide couldnt compling it. Because esp ESP8266Lib.h library doesnt work.
Please ,if you know why it was that write me.

Pete.