Turn on 4 Relays with One button using Blynk

First of all, using the pins you’ve chosen may not be the best idea.
If you translate the “D” numbers of the NodeMCU into GPIO numbers the you get this:

D1 = GPIO5
D2 = GPIO4
D3 = GPIO0
D4 = GPIO2
D5 = GPIO14
D6 = GPIO12
D7 = GPIO13
D8 = GPIO15

As you’ll see from this:

using GPIO’s 0, 2 and 15 are potentially problematic, as having something connected to them at power-on could cause the NodeMCU to boot into the wrong mode, preventing the execution of your sketch.
As the NodeMCU doesn’t have enough suitable pins to do what you wnat then you may end0up using multiple devices (and Bridge code) or an ESP32.

To answer your original question, if you had a button widget (in switch mode) connected to pin V1 then the code would look like this:

BLYNK_WRITE(V1) // Triggered automatically when the value of V1 changes
{
 if(param.asInt) // if the value from the widget is 1
 {
    digitalWrite(D1,LOW);
    digitalWrite(D2,LOW);
    digitalWrite(D3,LOW);
    digitalWrite(D4,LOW);
 }
 else // if the value from the widget is 0
 {
    digitalWrite(D1,HIGH);
    digitalWrite(D2,HIGH);
    digitalWrite(D3,HIGH);
    digitalWrite(D4,HIGH);
 }
}

Obviously you’d use your newly selected pin numbers rather than the ones above.

Pete.

1 Like