Keep getting error a function is not allowed here before '{' token before

I am keep getting this error:

C:\Users\Admin\Documents\Arduino\sketch_apr3a\sketch_apr3a.ino: In function 'void setup()':
C:\Users\Admin\Documents\Arduino\sketch_apr3a\sketch_apr3a.ino:192:15: error: a function-definition is not allowed here before '{' token
   void loop() {
               ^

exit status 1

Compilation error: a function-definition is not allowed here before '{' token

Tried ctrl + T but it didnt fix

here is my code:

#include <EEPROM.h>
#include "GravityTDS.h"
#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

int X;
int Y;
float TIME = 0;
float FREQUENCY = 0;
float WATER = 0;
float TOTAL = 0;
float LS = 0;
const int input = A0;

int buzzer = 8;

int relay_pump = 9;

int BTN = 10;
int btnCount = 0;

int BTN2 = 11;  // button for forcefull shutdown of motor
int btn2Count = 0;

int starttime;
int endtime;

int choice;

#define TdsSensorPin A1
GravityTDS gravityTds;

float temperature = 25, tdsValue = 0;

void setup() {
  Serial.begin(9600);
  pinMode(buzzer, OUTPUT);
  pinMode(relay_pump, OUTPUT);
  pinMode(BTN, INPUT_PULLUP);
  pinMode(BTN2, INPUT_PULLUP);


  {  //intro

    lcd.begin(16, 2);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Water Flow Meter");
    lcd.setCursor(0, 1);
    lcd.print(" Project no. 15 ");
    delay(2000);
    pinMode(input, INPUT);
  }
  {
    gravityTds.setPin(TdsSensorPin);

    gravityTds.setAref(5.0);  //reference voltage on ADC, default? 5.0V on Arduino UNO

    gravityTds.setAdcRange(1024);  //1024 for 10bit ADC;4096 for 12bit ADC

    gravityTds.begin();  //initialization
  }
  {
    while (TOTAL < 0.5) {
      X = pulseIn(input, HIGH);
      Y = pulseIn(input, LOW);
      TIME = X + Y;
      FREQUENCY = 1000000 / TIME;
      WATER = FREQUENCY / 7.5;
      LS = WATER / 60;
      TOTAL = TOTAL + LS;


      Serial.println(FREQUENCY);
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("WFR.: ");
      lcd.print(WATER);
      lcd.print(" L/M");
      lcd.setCursor(0, 1);
      lcd.print("TOTAL:");
      lcd.print(TOTAL);
      lcd.print(" L");
    }
    {
      gravityTds.setTemperature(temperature);

      gravityTds.update();

      tdsValue = gravityTds.getTdsValue();
    }
    if (tdsValue < 80) {
      choice = 1;
      for (int i = 0; i < 8; i++) {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("WATER AVAILABLE");
        lcd.setCursor(0, 1);
        lcd.print("At Good Quality");

        digitalWrite(buzzer, HIGH);
        delay(800);


        lcd.clear();

        digitalWrite(buzzer, LOW);
        delay(500);
      }
    } else if (tdsValue < 200) {
      choice = 1;
      for (int i = 0; i < 8; i++) {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("WATER AVAILABLE");
        lcd.setCursor(0, 1);
        lcd.print("At Fine Quality");

        digitalWrite(buzzer, HIGH);
        delay(800);


        lcd.clear();

        digitalWrite(buzzer, LOW);
        delay(500);
      }
    } else {
      for (int i = 0; i < 8; i++) {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("WATER AVAILABLE");
        lcd.setCursor(0, 1);
        lcd.print("At bad Quality");

        digitalWrite(buzzer, HIGH);
        delay(2000);


        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Do you want to");
        lcd.setCursor(0, 1);
        lcd.print("fill?(yes/no)");

        digitalWrite(buzzer, LOW);
        delay(1200);
      }
      choice = 0;  // 0 for no choice

      starttime = millis();
      endtime = starttime;


      while (choice = 0 || starttime - endtime <= 6000)  //the loop will continue until user selects a choice and till 3 seconds after the selection so user get chance to cancel or change their decision
      {
        int val = digitalRead(BTN);
        if (val == 0) {
          btnCount = btnCount + 1;
        }
        switch (btnCount) {
          case 1:
            choice = 1;  // 1 for yes
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("Yes.Press 2 more");
            lcd.setCursor(0, 1);
            lcd.print("times to cancel");
            break;
          case 2:
            choice = 2;  //2 for no
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("No.Press 1 more");
            lcd.setCursor(0, 1);
            lcd.print("times to cancel");
            break;
          case 3:
            choice = 0;  // 0 for no choice, the loop continues until user does any choice
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("No choice");
            lcd.setCursor(0, 1);
            lcd.print("selected ");
            btnCount = btnCount - 3;
        }
        endtime = millis();
      }
    }
  }
  void loop() {
    int val2 = digitalRead(BTN2);
    if (val2 == 0) {
      btn2Count = btn2Count + 1;
    } else {
    }
    switch (btn2Count) {
      case 0:
        if (choice = 1) {
          digitalWrite(relay_pump, LOW);  // this 5v pump is used as motor
          X = pulseIn(input, HIGH);
          Y = pulseIn(input, LOW);
          TIME = X + Y;
          FREQUENCY = 1000000 / TIME;
          WATER = FREQUENCY / 7.5;
          LS = WATER / 60;
          TOTAL = TOTAL + LS;
          gravityTds.setTemperature(temperature);

          gravityTds.update();

          tdsValue = gravityTds.getTdsValue();

          lcd.clear();
          lcd.setCursor(0, 0);
          lcd.print("WFR.: ");
          lcd.print(WATER);
          lcd.print(" L/M");
          lcd.setCursor(0, 1);
          lcd.print("TOTAL:");
          lcd.print(TOTAL);
          lcd.print(" L");

          X = pulseIn(input, HIGH);
          Y = pulseIn(input, LOW);
          TIME = X + Y;
          FREQUENCY = 1000000 / TIME;
          WATER = FREQUENCY / 7.5;
          LS = WATER / 60;
          TOTAL = TOTAL + LS;
          gravityTds.setTemperature(temperature);

          gravityTds.update();

          tdsValue = gravityTds.getTdsValue();

          lcd.clear();
          lcd.setCursor(0, 0);
          ? lcd.print("TOTAL:");
          lcd.print(TOTAL);
          lcd.print(" L");
          lcd.setCursor(0, 1);
          lcd.print("TDS.: ");
          lcd.print(tdsValue);
          lcd.print(" ppm");

          X = pulseIn(input, HIGH);
          Y = pulseIn(input, LOW);
          TIME = X + Y;
          FREQUENCY = 1000000 / TIME;
          WATER = FREQUENCY / 7.5;
          LS = WATER / 60;
          TOTAL = TOTAL + LS;
          gravityTds.setTemperature(temperature);

          gravityTds.update();

          tdsValue = gravityTds.getTdsValue();

          lcd.clear();
          lcd.setCursor(0, 0);
          lcd.print("TDS.: ");
          lcd.print(tdsValue);
          lcd.print(" ppm")
            lcd.setCursor(0, 1);
          lcd.print("WFR.: ");
          lcd.print(WATER);
          lcd.print(" L/M");

        } else {
          lcd.clear();
          lcd.setCursor(0, 0);
          lcd.print("Motor is off");
        }
        break;

      case 1:
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Motor is off");
        break;
            case 2;
            btn2Count = btn2count - 2;      
            }    
           }      
           }              type or paste code here

can anyone help me in fixing this pls?

This is certainly wrong! Remove it!

That's in the setup function.
I'm trying hard to think of a situation where that would ever happen.
It happens several times.

removed but still getting the same error

It can't fix things, but it can highlight problems.
Which it did.

removed those curly bracket pairs but still didnt fix...I think the problem is somewhere in this line:

  void loop() {

the error message is keep highlighting this line

Can't see your code...

There is nothing at all wrong with that line of code.
(I would prefer to see the { on a new line, but that's just my Linux kernel coding preferences)

here is the code:

#include <EEPROM.h>
#include "GravityTDS.h"
#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

int X;
int Y;
float TIME = 0;
float FREQUENCY = 0;
float WATER = 0;
float TOTAL = 0;
float LS = 0;
const int input = A0;

int buzzer = 8;

int relay_pump = 9;

int BTN = 10;
int btnCount = 0;

int BTN2 = 11;  // button for forcefull shutdown of motor
int btn2Count = 0;

int starttime;
int endtime;

int choice;

#define TdsSensorPin A1
GravityTDS gravityTds;

float temperature = 25, tdsValue = 0;

void setup() {
  Serial.begin(9600);
  pinMode(buzzer, OUTPUT);
  pinMode(relay_pump, OUTPUT);
  pinMode(BTN, INPUT_PULLUP);
  pinMode(BTN2, INPUT_PULLUP);

  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Water Flow Meter");
  lcd.setCursor(0, 1);
  lcd.print(" Project no. 15 ");
  delay(2000);
  pinMode(input, INPUT);

  gravityTds.setPin(TdsSensorPin);

  gravityTds.setAref(5.0);  //reference voltage on ADC, default? 5.0V on Arduino UNO

  gravityTds.setAdcRange(1024);  //1024 for 10bit ADC;4096 for 12bit ADC

  gravityTds.begin();  //initialization
  {
    while (TOTAL < 0.5) {
      X = pulseIn(input, HIGH);
      Y = pulseIn(input, LOW);
      TIME = X + Y;
      FREQUENCY = 1000000 / TIME;
      WATER = FREQUENCY / 7.5;
      LS = WATER / 60;
      TOTAL = TOTAL + LS;


      Serial.println(FREQUENCY);
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("WFR.: ");
      lcd.print(WATER);
      lcd.print(" L/M");
      lcd.setCursor(0, 1);
      lcd.print("TOTAL:");
      lcd.print(TOTAL);
      lcd.print(" L");
    }
    {
      gravityTds.setTemperature(temperature);

      gravityTds.update();

      tdsValue = gravityTds.getTdsValue();
    }
    if (tdsValue < 80) {
      choice = 1;
      for (int i = 0; i < 8; i++) {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("WATER AVAILABLE");
        lcd.setCursor(0, 1);
        lcd.print("At Good Quality");

        digitalWrite(buzzer, HIGH);
        delay(800);


        lcd.clear();

        digitalWrite(buzzer, LOW);
        delay(500);
      }
    } else if (tdsValue < 200) {
      choice = 1;
      for (int i = 0; i < 8; i++) {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("WATER AVAILABLE");
        lcd.setCursor(0, 1);
        lcd.print("At Fine Quality");

        digitalWrite(buzzer, HIGH);
        delay(800);


        lcd.clear();

        digitalWrite(buzzer, LOW);
        delay(500);
      }
    } else {
      for (int i = 0; i < 8; i++) {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("WATER AVAILABLE");
        lcd.setCursor(0, 1);
        lcd.print("At bad Quality");

        digitalWrite(buzzer, HIGH);
        delay(2000);


        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Do you want to");
        lcd.setCursor(0, 1);
        lcd.print("fill?(yes/no)");

        digitalWrite(buzzer, LOW);
        delay(1200);
      }
      choice = 0;  // 0 for no choice

      starttime = millis();
      endtime = starttime;


      while (choice = 0 || starttime - endtime <= 6000)  //the loop will continue until user selects a choice and till 3 seconds after the selection so user get chance to cancel or change their decision
      {
        int val = digitalRead(BTN);
        if (val == 0) {
          btnCount = btnCount + 1;
        }
        switch (btnCount) {
          case 1:
            choice = 1;  // 1 for yes
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("Yes.Press 2 more");
            lcd.setCursor(0, 1);
            lcd.print("times to cancel");
            break;
          case 2:
            choice = 2;  //2 for no
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("No.Press 1 more");
            lcd.setCursor(0, 1);
            lcd.print("times to cancel");
            break;
          case 3:
            choice = 0;  // 0 for no choice, the loop continues until user does any choice
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("No choice");
            lcd.setCursor(0, 1);
            lcd.print("selected ");
            btnCount = btnCount - 3;
        }
        endtime = millis();
      }
    }
  }
  void loop() {
    int val2 = digitalRead(BTN2);
    if (val2 == 0) {
      btn2Count = btn2Count + 1;
    } else {
    }
    switch (btn2Count) {
      case 0:
        if (choice = 1) {
          digitalWrite(relay_pump, LOW);  // this 5v pump is used as motor
          X = pulseIn(input, HIGH);
          Y = pulseIn(input, LOW);
          TIME = X + Y;
          FREQUENCY = 1000000 / TIME;
          WATER = FREQUENCY / 7.5;
          LS = WATER / 60;
          TOTAL = TOTAL + LS;
          gravityTds.setTemperature(temperature);

          gravityTds.update();

          tdsValue = gravityTds.getTdsValue();

          lcd.clear();
          lcd.setCursor(0, 0);
          lcd.print("WFR.: ");
          lcd.print(WATER);
          lcd.print(" L/M");
          lcd.setCursor(0, 1);
          lcd.print("TOTAL:");
          lcd.print(TOTAL);
          lcd.print(" L");

          X = pulseIn(input, HIGH);
          Y = pulseIn(input, LOW);
          TIME = X + Y;
          FREQUENCY = 1000000 / TIME;
          WATER = FREQUENCY / 7.5;
          LS = WATER / 60;
          TOTAL = TOTAL + LS;
          gravityTds.setTemperature(temperature);

          gravityTds.update();

          tdsValue = gravityTds.getTdsValue();

          lcd.clear();
          lcd.setCursor(0, 0);
          ? lcd.print("TOTAL:");
          lcd.print(TOTAL);
          lcd.print(" L");
          lcd.setCursor(0, 1);
          lcd.print("TDS.: ");
          lcd.print(tdsValue);
          lcd.print(" ppm");

          X = pulseIn(input, HIGH);
          Y = pulseIn(input, LOW);
          TIME = X + Y;
          FREQUENCY = 1000000 / TIME;
          WATER = FREQUENCY / 7.5;
          LS = WATER / 60;
          TOTAL = TOTAL + LS;
          gravityTds.setTemperature(temperature);

          gravityTds.update();

          tdsValue = gravityTds.getTdsValue();

          lcd.clear();
          lcd.setCursor(0, 0);
          lcd.print("TDS.: ");
          lcd.print(tdsValue);
          lcd.print(" ppm")
            lcd.setCursor(0, 1);
          lcd.print("WFR.: ");
          lcd.print(WATER);
          lcd.print(" L/M");

        } else {
          lcd.clear();
          lcd.setCursor(0, 0);
          lcd.print("Motor is off");
        }
        break;

      case 1:
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Motor is off");
        break;
      case 2;
       btn2Count = btn2count - 2;
        break;        }    
         }      
        }              

here is the error message:

C:\Users\Admin\Documents\Arduino\sketch_apr3a\sketch_apr3a.ino: In function 'void setup()':
C:\Users\Admin\Documents\Arduino\sketch_apr3a\sketch_apr3a.ino:187:15: error: a function-definition is not allowed here before '{' token
   void loop() {
               ^

exit status 1

Compilation error: a function-definition is not allowed here before '{' tokentype or paste code here

The error is because you have randomly placed { and } in your code. They need to be in pairs... for every { there must be a }.

In many cases you have {} around parts of the code for no good reason... like here for example...

I thought we'd agreed that that doesn't happen?

uh worked.. i escaped from that error but got bunch of another:

`C:\Users\Admin\Documents\Arduino\sketch_apr3a\sketch_apr3a.ino: In function 'void loop()':
C:\Users\Admin\Documents\Arduino\sketch_apr3a\sketch_apr3a.ino:235:11: error: expected primary-expression before '?' token
           ? lcd.print("TOTAL:");
           ^
C:\Users\Admin\Documents\Arduino\sketch_apr3a\sketch_apr3a.ino:235:32: error: expected ':' before ';' token
           ? lcd.print("TOTAL:");
                                ^
C:\Users\Admin\Documents\Arduino\sketch_apr3a\sketch_apr3a.ino:235:32: error: expected primary-expression before ';' token
C:\Users\Admin\Documents\Arduino\sketch_apr3a\sketch_apr3a.ino:261:13: error: expected ';' before 'lcd'
             lcd.setCursor(0, 1);
             ^~~
C:\Users\Admin\Documents\Arduino\sketch_apr3a\sketch_apr3a.ino:278:13: error: expected ':' before ';' token
       case 2;
             ^
C:\Users\Admin\Documents\Arduino\sketch_apr3a\sketch_apr3a.ino:279:20: error: 'btn2count' was not declared in this scope
        btn2Count = btn2count - 2;
                    ^~~~~~~~~
C:\Users\Admin\Documents\Arduino\sketch_apr3a\sketch_apr3a.ino:279:20: note: suggested alternative: 'btn2Count'
        btn2Count = btn2count - 2;
                    ^~~~~~~~~
                    btn2Count
C:\Users\Admin\Documents\Arduino\sketch_apr3a\sketch_apr3a.ino: At global scope:
C:\Users\Admin\Documents\Arduino\sketch_apr3a\sketch_apr3a.ino:282:9: error: expected declaration before '}' token
         }
         ^

exit status 1

Compilation error: expected primary-expression before '?' token`

i think i will have to look into all of them one by one
thanks

This is a problem. '=' is assign '==' is comparison.

while (choice = 0 || starttime - endtime <= 6000)

if (choice = 1) {

This is a problem too.

case 2;

1 Like

You're quite a way off, so I don't know why you've marked this solved.

Fixed.

#include <EEPROM.h>
#include "GravityTDS.h"
#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

int X;
int Y;
float TIME = 0;
float FREQUENCY = 0;
float WATER = 0;
float TOTAL = 0;
float LS = 0;
const int input = A0;

int buzzer = 8;

int relay_pump = 9;

int BTN = 10;
int btnCount = 0;

int BTN2 = 11;  // button for forcefull shutdown of motor
int btn2Count = 0;

int starttime;
int endtime;

int choice;

#define TdsSensorPin A1
GravityTDS gravityTds;

float temperature = 25, tdsValue = 0;

void setup() {
  Serial.begin(9600);
  pinMode(buzzer, OUTPUT);
  pinMode(relay_pump, OUTPUT);
  pinMode(BTN, INPUT_PULLUP);
  pinMode(BTN2, INPUT_PULLUP);

  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Water Flow Meter");
  lcd.setCursor(0, 1);
  lcd.print(" Project no. 15 ");
  delay(2000);
  pinMode(input, INPUT);

  gravityTds.setPin(TdsSensorPin);

  gravityTds.setAref(5.0);  //reference voltage on ADC, default? 5.0V on Arduino UNO

  gravityTds.setAdcRange(1024);  //1024 for 10bit ADC;4096 for 12bit ADC

  gravityTds.begin();  //initialization
  {
    while (TOTAL < 0.5) {
      X = pulseIn(input, HIGH);
      Y = pulseIn(input, LOW);
      TIME = X + Y;
      FREQUENCY = 1000000 / TIME;
      WATER = FREQUENCY / 7.5;
      LS = WATER / 60;
      TOTAL = TOTAL + LS;

      Serial.println(FREQUENCY);
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("WFR.: ");
      lcd.print(WATER);
      lcd.print(" L/M");
      lcd.setCursor(0, 1);
      lcd.print("TOTAL:");
      lcd.print(TOTAL);
      lcd.print(" L");

      gravityTds.setTemperature(temperature);

      gravityTds.update();

      tdsValue = gravityTds.getTdsValue();

      if (tdsValue < 80) {
        choice = 1;
        for (int i = 0; i < 8; i++) {
          lcd.clear();
          lcd.setCursor(0, 0);
          lcd.print("WATER AVAILABLE");
          lcd.setCursor(0, 1);
          lcd.print("At Good Quality");

          digitalWrite(buzzer, HIGH);
          delay(800);


          lcd.clear();

          digitalWrite(buzzer, LOW);
          delay(500);
        }
      } else if (tdsValue < 200) {
        choice = 1;
        for (int i = 0; i < 8; i++) {
          lcd.clear();
          lcd.setCursor(0, 0);
          lcd.print("WATER AVAILABLE");
          lcd.setCursor(0, 1);
          lcd.print("At Fine Quality");

          digitalWrite(buzzer, HIGH);
          delay(800);


          lcd.clear();

          digitalWrite(buzzer, LOW);
          delay(500);
        }
      } else {
        for (int i = 0; i < 8; i++) {
          lcd.clear();
          lcd.setCursor(0, 0);
          lcd.print("WATER AVAILABLE");
          lcd.setCursor(0, 1);
          lcd.print("At bad Quality");

          digitalWrite(buzzer, HIGH);
          delay(2000);

          lcd.clear();
          lcd.setCursor(0, 0);
          lcd.print("Do you want to");
          lcd.setCursor(0, 1);
          lcd.print("fill?(yes/no)");

          digitalWrite(buzzer, LOW);
          delay(1200);
        }
        choice = 0;  // 0 for no choice

        starttime = millis();
        endtime = starttime;
      }

      while (choice = 0 || starttime - endtime <= 6000)  //the loop will continue until user selects a choice and till 3 seconds after the selection so user get chance to cancel or change their decision
      {
        int val = digitalRead(BTN);
        if (val == 0) {
          btnCount = btnCount + 1;
        }
        switch (btnCount) {
          case 1:
            choice = 1;  // 1 for yes
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("Yes.Press 2 more");
            lcd.setCursor(0, 1);
            lcd.print("times to cancel");
            break;
          case 2:
            choice = 2;  //2 for no
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("No.Press 1 more");
            lcd.setCursor(0, 1);
            lcd.print("times to cancel");
            break;
          case 3:
            choice = 0;  // 0 for no choice, the loop continues until user does any choice
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("No choice");
            lcd.setCursor(0, 1);
            lcd.print("selected ");
            btnCount = btnCount - 3;
        }
        endtime = millis();
      }
    }
  }
}

void loop() {
  int val2 = digitalRead(BTN2);
  if (val2 == 0) {
    btn2Count = btn2Count + 1;
  } else {
  }
  switch (btn2Count) {
    case 0:
      if (choice = 1) {
        digitalWrite(relay_pump, LOW);  // this 5v pump is used as motor
        X = pulseIn(input, HIGH);
        Y = pulseIn(input, LOW);
        TIME = X + Y;
        FREQUENCY = 1000000 / TIME;
        WATER = FREQUENCY / 7.5;
        LS = WATER / 60;
        TOTAL = TOTAL + LS;
        gravityTds.setTemperature(temperature);

        gravityTds.update();

        tdsValue = gravityTds.getTdsValue();

        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("WFR.: ");
        lcd.print(WATER);
        lcd.print(" L/M");
        lcd.setCursor(0, 1);
        lcd.print("TOTAL:");
        lcd.print(TOTAL);
        lcd.print(" L");

        X = pulseIn(input, HIGH);
        Y = pulseIn(input, LOW);
        TIME = X + Y;
        FREQUENCY = 1000000 / TIME;
        WATER = FREQUENCY / 7.5;
        LS = WATER / 60;
        TOTAL = TOTAL + LS;
        gravityTds.setTemperature(temperature);

        gravityTds.update();

        tdsValue = gravityTds.getTdsValue();

        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("TOTAL:");
        lcd.print(TOTAL);
        lcd.print(" L");
        lcd.setCursor(0, 1);
        lcd.print("TDS.: ");
        lcd.print(tdsValue);
        lcd.print(" ppm");

        X = pulseIn(input, HIGH);
        Y = pulseIn(input, LOW);
        TIME = X + Y;
        FREQUENCY = 1000000 / TIME;
        WATER = FREQUENCY / 7.5;
        LS = WATER / 60;
        TOTAL = TOTAL + LS;
        gravityTds.setTemperature(temperature);

        gravityTds.update();

        tdsValue = gravityTds.getTdsValue();

        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("TDS.: ");
        lcd.print(tdsValue);
        lcd.print(" ppm");
        lcd.setCursor(0, 1);
        lcd.print("WFR.: ");
        lcd.print(WATER);
        lcd.print(" L/M");

      } else {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Motor is off");
      }
      break;

    case 1:
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Motor is off");
      break;
    case 2:
      btn2Count = btn2Count - 2;
      break;
  }
}

...for a limited definition of the word .

1 Like

fixed that
can you help in this

C:\Users\Admin\Documents\Arduino\sketch_apr3a\sketch_apr3a.ino: In function 'void loop()':
C:\Users\Admin\Documents\Arduino\sketch_apr3a\sketch_apr3a.ino:235:11: error: expected primary-expression before '?' token
           ? lcd.print("TOTAL:");
           ^
C:\Users\Admin\Documents\Arduino\sketch_apr3a\sketch_apr3a.ino:235:32: error: expected ':' before ';' token
           ? lcd.print("TOTAL:");
                                ^
C:\Users\Admin\Documents\Arduino\sketch_apr3a\sketch_apr3a.ino:235:32: error: expected primary-expression before ';' token
C:\Users\Admin\Documents\Arduino\sketch_apr3a\sketch_apr3a.ino:261:13: error: expected ';' before 'lcd'
             lcd.setCursor(0, 1);
             ^~~
C:\Users\Admin\Documents\Arduino\sketch_apr3a\sketch_apr3a.ino:278:13: error: expected ':' before ';' token
       case 2;
             ^
C:\Users\Admin\Documents\Arduino\sketch_apr3a\sketch_apr3a.ino:279:20: error: 'btn2count' was not declared in this scope
        btn2Count = btn2count - 2;
                    ^~~~~~~~~
C:\Users\Admin\Documents\Arduino\sketch_apr3a\sketch_apr3a.ino:279:20: note: suggested alternative: 'btn2Count'
        btn2Count = btn2count - 2;
                    ^~~~~~~~~
                    btn2Count
C:\Users\Admin\Documents\Arduino\sketch_apr3a\sketch_apr3a.ino: At global scope:
C:\Users\Admin\Documents\Arduino\sketch_apr3a\sketch_apr3a.ino:282:9: error: expected declaration before '}' token
         }
         ^

exit status 1

Compilation error: expected primary-expression before '?' token

Get rid of the '?'

Do what the error message suggests

Colon, not semi.

Declare 'btn2count' in that context.

Of course, I could give better answers if you posted the code, and not the error messages.

#include <EEPROM.h>
#include "GravityTDS.h"
#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

int X;
int Y;
float TIME = 0;
float FREQUENCY = 0;
float WATER = 0;
float TOTAL = 0;
float LS = 0;
const int input = A0;

int buzzer = 8;

int relay_pump = 9;

int BTN = 10;
int btnCount = 0;

int BTN2 = 11;  // button for forcefull shutdown of motor
int btn2Count = 0;

int starttime;
int endtime;

int choice;

#define TdsSensorPin A1
GravityTDS gravityTds;

float temperature = 25, tdsValue = 0;

void setup() {
  Serial.begin(9600);
  pinMode(buzzer, OUTPUT);
  pinMode(relay_pump, OUTPUT);
  pinMode(BTN, INPUT_PULLUP);
  pinMode(BTN2, INPUT_PULLUP);

  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Water Flow Meter");
  lcd.setCursor(0, 1);
  lcd.print(" Project no. 15 ");
  delay(2000);
  pinMode(input, INPUT);

  gravityTds.setPin(TdsSensorPin);

  gravityTds.setAref(5.0);  //reference voltage on ADC, default? 5.0V on Arduino UNO

  gravityTds.setAdcRange(1024);  //1024 for 10bit ADC;4096 for 12bit ADC

  gravityTds.begin();  //initialization
  
    while (TOTAL < 0.5) {
      X = pulseIn(input, HIGH);
      Y = pulseIn(input, LOW);
      TIME = X + Y;
      FREQUENCY = 1000000 / TIME;
      WATER = FREQUENCY / 7.5;
      LS = WATER / 60;
      TOTAL = TOTAL + LS;


      Serial.println(FREQUENCY);
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("WFR.: ");
      lcd.print(WATER);
      lcd.print(" L/M");
      lcd.setCursor(0, 1);
      lcd.print("TOTAL:");
      lcd.print(TOTAL);
      lcd.print(" L");
    }
    
      gravityTds.setTemperature(temperature);

      gravityTds.update();

      tdsValue = gravityTds.getTdsValue();
    
    if (tdsValue < 80) {
      choice = 1;
      for (int i = 0; i < 8; i++) {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("WATER AVAILABLE");
        lcd.setCursor(0, 1);
        lcd.print("At Good Quality");

        digitalWrite(buzzer, HIGH);
        delay(800);


        lcd.clear();

        digitalWrite(buzzer, LOW);
        delay(500);
      }
    } else if (tdsValue < 200) {
      choice = 1;
      for (int i = 0; i < 8; i++) {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("WATER AVAILABLE");
        lcd.setCursor(0, 1);
        lcd.print("At Fine Quality");

        digitalWrite(buzzer, HIGH);
        delay(800);


        lcd.clear();

        digitalWrite(buzzer, LOW);
        delay(500);
      }
    } else {
      for (int i = 0; i < 8; i++) {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("WATER AVAILABLE");
        lcd.setCursor(0, 1);
        lcd.print("At bad Quality");

        digitalWrite(buzzer, HIGH);
        delay(2000);


        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Do you want to");
        lcd.setCursor(0, 1);
        lcd.print("fill?(yes/no)");

        digitalWrite(buzzer, LOW);
        delay(1200);
      }
      choice = 0;  // 0 for no choice

      starttime = millis();
      endtime = starttime;


      while (choice == 0 || starttime - endtime <= 6000)  //the loop will continue until user selects a choice and till 3 seconds after the selection so user get chance to cancel or change their decision
      {
        int val = digitalRead(BTN);
        if (val == 0) {
          btnCount = btnCount + 1;
        }
        switch (btnCount) {
          case 1:
            choice = 1;  // 1 for yes
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("Yes.Press 2 more");
            lcd.setCursor(0, 1);
            lcd.print("times to cancel");
            break;
          case 2:
            choice = 2;  //2 for no
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("No.Press 1 more");
            lcd.setCursor(0, 1);
            lcd.print("times to cancel");
            break;
          case 3:
            choice = 0;  // 0 for no choice, the loop continues until user does any choice
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("No choice");
            lcd.setCursor(0, 1);
            lcd.print("selected ");
            btnCount = btnCount - 3;
        }
        endtime = millis();
      }
    }
  }
  void loop() {
    int val2 = digitalRead(BTN2);
    if (val2 == 0) {
      btn2Count = btn2Count + 1;
    } else {
    }
    switch (btn2Count) {
      case 0:
        if (choice = 1) {
          digitalWrite(relay_pump, LOW);  // this 5v pump is used as motor
          X = pulseIn(input, HIGH);
          Y = pulseIn(input, LOW);
          TIME = X + Y;
          FREQUENCY = 1000000 / TIME;
          WATER = FREQUENCY / 7.5;
          LS = WATER / 60;
          TOTAL = TOTAL + LS;
          gravityTds.setTemperature(temperature);

          gravityTds.update();

          tdsValue = gravityTds.getTdsValue();

          lcd.clear();
          lcd.setCursor(0, 0);
          lcd.print("WFR.: ");
          lcd.print(WATER);
          lcd.print(" L/M");
          lcd.setCursor(0, 1);
          lcd.print("TOTAL:");
          lcd.print(TOTAL);
          lcd.print(" L");

          X = pulseIn(input, HIGH);
          Y = pulseIn(input, LOW);
          TIME = X + Y;
          FREQUENCY = 1000000 / TIME;
          WATER = FREQUENCY / 7.5;
          LS = WATER / 60;
          TOTAL = TOTAL + LS;
          gravityTds.setTemperature(temperature);

          gravityTds.update();

          tdsValue = gravityTds.getTdsValue();

          lcd.clear();
          lcd.setCursor(0, 0);
          ? lcd.print("TOTAL:");
          lcd.print(TOTAL);
          lcd.print(" L");
          lcd.setCursor(0, 1);
          lcd.print("TDS.: ");
          lcd.print(tdsValue);
          lcd.print(" ppm");

          X = pulseIn(input, HIGH);
          Y = pulseIn(input, LOW);
          TIME = X + Y;
          FREQUENCY = 1000000 / TIME;
          WATER = FREQUENCY / 7.5;
          LS = WATER / 60;
          TOTAL = TOTAL + LS;
          gravityTds.setTemperature(temperature);

          gravityTds.update();

          tdsValue = gravityTds.getTdsValue();

          lcd.clear();
          lcd.setCursor(0, 0);
          lcd.print("TDS.: ");
          lcd.print(tdsValue);
          lcd.print(" ppm")
            lcd.setCursor(0, 1);
          lcd.print("WFR.: ");
          lcd.print(WATER);
          lcd.print(" L/M");

        } else {
          lcd.clear();
          lcd.setCursor(0, 0);
          lcd.print("Motor is off");
        }
        break;

      case 1:
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Motor is off");
        break;
      case 2;
       btn2Count = btn2count - 2;
        break;        }    
         }      
        }              

thanks a lot for your amazing work
this code has no errors!

but i want to fix my code step by step so in future i can fix them by my own

Very good wish.
The best option is to read some ะก language textbook, since judging by the questions, you have a very poor understanding of C syntax