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
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.
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.
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
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.
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
}
}
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.
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
@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.
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
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.
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.