Function-definition is not allowed here before ‘{’ token

#include <SoftwareSerial.h>

#include <BlynkSimpleStream.h>

char auth = "T57Fo6UaEqluT90dR-j2px9SSiLqaSmd";

const int ch=3;
const int Relay1 = 3; //water pump1 (alkhali)
const int Relay2 = 4; //water pump2 (Acid)
const int Relay3 = 5; //water pump3 (mixing)

const int PH_SENSOR = A0;

unsigned long int run_time = 0;
unsigned long int avgValue;

bool refilling = true; //false
int buffer_data[10], temp;

BLYNK_READ(V0) {
Blynk.virtualWrite(V0, millis() / 1000);

void setup() {
Serial.begin(9600); //baudrate
DebugSerial.begin(9600);

Serial.println("Inalisis konfigurasi pin pada kontroller...");
//inisiasi pin input
pinMode(Relay1, OUTPUT);
pinMode(Relay2, OUTPUT);
pinMode(Relay3, OUTPUT);

pinMode(PH_SENSOR, INPUT);

digitalWrite(Relay1, LOW);
delay(60000);
digitalWrite(Relay2, LOW);
delay(60000);
digitalWrite(Relay3, HIGH);
Blynk.begin(Serial, auth);
Serial.begin(9600);
}

void loop()
{

//amik data sensor
for(int i = 0; i < 10; i++) {
buffer_data[i] = analogRead(PH_SENSOR);
delay(80); //delay 80ms, bagusnya 100
}

for(int i = 0; i < 9; i++) {
for(int j = i+1; j < 10; j++) if(buffer_data[i] > buffer_data[j]) {
temp = buffer_data[i];
buffer_data[i] = buffer_data[j];
buffer_data[j] = temp;
}
}
avgValue = 0;

for(int i = 3; i < 9; i++) {
avgValue += buffer_data[i];
}

float pHVol = (float)avgValue* 5.0 / 1024 / 6;
float ph_value = -5.70 * pHVol + 21.34;

if(ph_value < 6 ) {// kondisi air acid wajib tukar
if(!refilling) {
refilling = true;

  digitalWrite(Relay1, HIGH);
  delay(1200);  
  digitalWrite(Relay1, LOW); 
  Serial.println("[debug]: Water to acidic!");   
}

}

if(ph_value > 8) {// kondisi air alkhali wajib tukar
if(!refilling) {
refilling = true;

  digitalWrite(Relay2, HIGH);
  delay(1200); 
  digitalWrite(Relay2, LOW);  
  Serial.println("[debug]: Water to alkhali!");   
}

}

while (ph_value = 7 ) {// kondisi air dah elok)
if(!refilling) {
refilling = false;

  digitalWrite(Relay1, LOW);
  digitalWrite(Relay2, LOW); 
  Serial.println("[debug]: Water is neutral!");
  Blynk.run();

}
}
}

// the error is
test:45:1: error: a function-definition is not allowed here before '{' token
test:102:1: error: expected '}' at end of input
exit status 1
a function-definition is not allowed here before '{' token

when i try to fix it, its give more error. help please

@natsuo_ath, your topic has been moved to a more suitable section of the forum.

Can yu please take some time to read How to get the best out of this forum and next apply what you read about code tags to your post.

====
You're missing a } ; where does BLYNK_READ(V0) end?

1 Like

It is hard to tell since you didn't post your code properly but it maybe that you don't have a closing brace for the following function.

BLYNK_READ(V0) {
Blynk.virtualWrite(V0, millis() / 1000);
1 Like

sorry im still new '(

wait ill try it!

You should post code by using code-tags
There is an automatic function for doing this in the Arduino-IDE
just three steps

  1. press Ctrl-T for autoformatting your code
  2. do a rightclick with the mouse and choose "copy for forum"
  3. paste clipboard into write-window of a posting

best regards Stefan

also, char auth = needs to be const char auth [] =

edit your initial post using </>