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?