Relays all firing at once

Hi all,

I am using Blynk IO to fire 4 separate pumps. Each pump is connected to a button on the Blynk App. I am not super familiar with coding, would someone tell me if anything I have written is causing all four relays to be firing at once? If one output is selected, they all seem to go.

#define BLYNK_PRINT Serial
#include <SoftwareSerial.h>
#include <Blynk.h>
#include <BlynkSimpleSerialBLE.h>

#define Coke 7
#define GingerAle 8
#define Rye 9
#define Rum 10

SoftwareSerial DebugSerial (2, 3); //RX, TX
char auth[] = "xxxxxxxxxxxxxxxxxxxx"; //Connection Code for Blynk

BlynkTimer timer;

void setup() {
  // put your setup code here, to run once:
pinMode (Coke , OUTPUT);
pinMode (GingerAle , OUTPUT);
pinMode (Rye , OUTPUT);
pinMode (Rum , OUTPUT);

Serial.begin(9600);
Blynk.begin(Serial, auth);
}

BLYNK_WRITE(V2) {
int buttonState = param.asInt();
  if (buttonState == 1)
   {
     digitalWrite(Coke , HIGH);
     timer.setTimeout(1000L, COKEOFF);
    } else {
      digitalWrite (Coke , LOW);
    }
}



BLYNK_WRITE(V3) {
int buttonState = param.asInt();
  if (buttonState == 1)
   {
     digitalWrite(GingerAle , HIGH);
     timer.setTimeout(1000L, GINGERALEOFF);
    } else {
      digitalWrite (GingerAle , LOW);
    }
}


BLYNK_WRITE(V4) {
int buttonState = param.asInt();
  if (buttonState == 1)
   {
     digitalWrite(Rye , HIGH);
     timer.setTimeout(1000L, RYEOFF);
    } else {
      digitalWrite (Rye , LOW);
    }
}

BLYNK_WRITE(V5) {
int buttonState = param.asInt();
  if (buttonState == 1)
   {
     digitalWrite(Rum , HIGH);
     timer.setTimeout(1000L, RUMOFF);

    } else {
      digitalWrite (Rum , LOW);
    }
}

void COKEOFF()
{
      digitalWrite(Coke , LOW);
     
   }
   
void GINGERALEOFF()
{
      digitalWrite(GingerAle , LOW);
     
   }
   
void RYEOFF()
{
      digitalWrite(Rye , LOW);
     
   }
     
void RUMOFF()
{
      digitalWrite(Rum , LOW);
     
   }

   
void loop()
{
  Blynk.run();
  timer.run();

}

Not sure what could be causing your issue, but you may benefit from doing a digitalWrite on each output once it is declared in your setup(). This may help you to be sure they start as OFF when booting.

void setup() {
  // put your setup code here, to run once:
pinMode (Coke , OUTPUT);
 digitalWrite(Coke , LOW);
pinMode (GingerAle , OUTPUT);
 digitalWrite(GingerAle, LOW);
pinMode (Rye , OUTPUT);
 digitalWrite(Rye, LOW);
pinMode (Rum , OUTPUT);
 digitalWrite(Rum, LOW);

Serial.begin(9600);
Blynk.begin(Serial, auth);
}
1 Like

You’ve defined a SoftwareSerial port called "DebugSerial`, which is presumably where your debug messages are meant to be going, via an FTDI adapter I presume…

and you’re using your hardware serial port to connect to your Bluetooth device…

But, you’re then telling Blynk to send its debug messages to the hardware serial port rather than the "DebugSerial` port…

This is going to mess things up big time, and I’m surprised that you’re even getting as far as a Blynk connection to your device.

My guess is that you’re using an Uno, and an HC-05 and don’t own an FTDI adapter (or even know what one is), and that you’ve never seen any debug messages from Blynk.

If that’s the case then I’d recommend using the hardware serial port for debugging and the software serial port for your HC-05, and click the spyglass icon in the top right had corner of the Arduino IDE top see your debug messages.

I’d also recommend that when you create a new topic you provide all of the information that’s requested, so we don’t have to do so much guessing.

Pete.