Control Multiple Digital Pins from one virtual pin

Hi, I am using Blynk bluetooth through galaxy s7 and and HC-05 bluetooth module. I am currently tring to write code to turn on 4 relays from one virtual pin. I get the “function definition is not allowed here” error as soon as the loop begans.

#define BLYNK_PRINT Serial


#include <BlynkSimpleSerialBLE.h>
#include <SoftwareSerial.h>
#include <DHT.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "a65f6c3231ec43c1a92f078d78c6a163";

SoftwareSerial SerialBLE(10, 11); // RX, TX

#define DHTPIN 9          // What digital pin we're connected to

// Uncomment whatever type you're using!
#define DHTTYPE DHT11  
# define All_zones 12
//relay control pins 
#define RELAY_EN1 30
#define RELAY_EN2 31
#define RELAY_EN3 32
#define RELAY_EN4 33
//#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21   // DHT 21, AM2301

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(true); // or dht.readTemperature(true) for Fahrenheit

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, h," %" );
  Blynk.virtualWrite(V6, t," F");
}

 BLYNK_WRITE(V7) { // V10 is the virtual pin that toggles this operation
  if (param.asInt()==1) { // check if the widget data is true. this would be an int value if using a slider, but 0/1 logic applies
   digitalWrite(RELAY_EN1,LOW);
    digitalWrite(RELAY_EN2,LOW);
    digitalWrite(RELAY_EN3,LOW);
    digitalWrite(RELAY_EN4,LOW);
  } else {
    digitalWrite(RELAY_EN1,HIGH);
    digitalWrite(RELAY_EN2,HIGH);
    digitalWrite(RELAY_EN3,HIGH);
    digitalWrite(RELAY_EN4,HIGH);
  }

void setup()
{
  // Debug console
  Serial.begin(9600);
//pinMode(All_zones,INPUT);
  SerialBLE.begin(9600);
  Blynk.begin(SerialBLE, auth);

 

  

  Serial.println("Waiting for connections...");

  dht.begin();

  // Setup a function to be called every second
  timer.setInterval(1000L, sendSensor);
}

void loop()
{
  Blynk.run();
  timer.run();
  
}
BLYNK_WRITE(V7) { // V10 is the virtual pin that toggles this operation
if (param.asInt()==1) { // check if the widget data is true. this would be an int value if using a slider, but 0/1 logic applies
digitalWrite(RELAY_EN1,LOW);
digitalWrite(RELAY_EN2,LOW);
digitalWrite(RELAY_EN3,LOW);
digitalWrite(RELAY_EN4,LOW);
} else {
digitalWrite(RELAY_EN1,HIGH);
digitalWrite(RELAY_EN2,HIGH);
digitalWrite(RELAY_EN3,HIGH);
digitalWrite(RELAY_EN4,HIGH);
}

You are missing a closing bracket

BLYNK_WRITE(V7) { // V10 is the virtual pin that toggles this operation
if (param.asInt()==1) { // check if the widget data is true. this would be an int value if using a slider, but 0/1 logic applies
digitalWrite(RELAY_EN1,LOW);
digitalWrite(RELAY_EN2,LOW);
digitalWrite(RELAY_EN3,LOW);
digitalWrite(RELAY_EN4,LOW);
} else {
digitalWrite(RELAY_EN1,HIGH);
digitalWrite(RELAY_EN2,HIGH);
digitalWrite(RELAY_EN3,HIGH);
digitalWrite(RELAY_EN4,HIGH);
}
}
1 Like

Easy fix thank you so much

In future, when you post code on the forum, please add triple backticks at the beginning and end of the code so that it displays correctly.
I’ve edited your original post to fix the formatting.

Triple backticks look like this:
```

Pete.

2 Likes