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

i have made a code but i got an error which is ( a function-defination is not allowed here before { token

full code is here

#include<LiquidCrystal.h>
LiquidCrystal lcd (9,10, 7, 6, 5, 4);
int sensor1 = 31;
int sensor2 = 32;
int sensor3 = 33;
int sensor4 = 34;
int motor1 = 36;
int motor2 = 37;
int motor3 = 38;
int motor4 = 39;
int led1 = 40;
int led2 = 41;
int led3 = 42;
int led4 = 43;
int rain = 30;
int buz = 44;
void setup()
{
  lcd.begin(16, 2);
  pinMode(sensor1, INPUT);
  pinMode(sensor2, INPUT);
  pinMode(sensor3, INPUT);
  pinMode(sensor4, INPUT);
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(motor1, OUTPUT);
  pinMode(motor2, OUTPUT);
  pinMode(motor3, OUTPUT);
  pinMode(motor4, OUTPUT);
  pinMode(buz, OUTPUT);
  pinMode(rain, INPUT);
  lcd.print("SMART IRRIGATION");
  lcd.setCursor(2, 1);
  lcd.print("...SYSTEM...");
  delay(2000);
  lcd.clear();
  lcd.print("PRESENTED BY");
  lcd.setCursor(2, 1);
  lcd.print("BSC ELECTRICAL");
  delay(2000);
  lcd.clear();
  lcd.print("GROUP MEMBERS");
  lcd.setCursor(2, 1);
  lcd.print("---------------");
  delay(2000);
  lcd.clear();
  lcd.print("IKRAM UL HAQ");
  lcd.setCursor(2, 1);
  lcd.print("BEEF15M003");
  delay(2000);
  lcd.clear();
  lcd.print("BEHZAD ASGHAR");
  lcd.setCursor(2, 1);
  lcd.print("BEEF15M026");
  delay(2000);
  lcd.clear();
  lcd.print("TALHA HAIDER");
  lcd.setCursor(2, 1);
  lcd.print("BEEF15M039");
  delay(2000);
  lcd.clear();
  void loop()
{
    if digitalRead(sensor1 , HIGH);

    {
      digitalWrite(led1, LOW);
      digitalWrite(motor1, LOW);
      lcd.print("NORMAL MOISTURE 1"
                lcd.setCursor(2, 1);
                lcd.print("MOTOR1 OFF");
                delay (2000);
                lcd.clear();
    }
    else if digitalRead(sensor1, LOW);
    {
      digitalWrite(led1, HIGH);
      digitalWrite(motor1, HIGH);
      lcd.print("LOW MOSITURE 1");
      lcd.setCursor(2, 1);
      lcd.print("MOTOR1 ON");
      delay(2000);
      lcd.clear();
    }
    if digitalRead(sensor2, HIGH);
    {
      digitalWrite(led2 , LOW);
      digitalWrite(motor2, LOW);
      lcd.print("NORMAL MOISTURE 2");
      lcd.setCursor(2, 1);
      lcd.print("MOTOR2 OFF");
      delay(2000);
      lcd.clear();
    }
    else if digitalRead(sensor2, LOW);
    {
      digitalWrite(led2, HIGH);
      digitalWrite(motor2 , HIGH);
      lcd.print("LOW MOISTURE 2");
      lcd.setCursor(2, 1);
      lcd.print("MOTOR2 ON");
      delay(2000);
      lcd.clear();
    }
    if digitalRead(sensor3, HIGH);
    {
      digitalWrite(led3, LOW);
      digitalWrite(motor3, LOW);
      lcd.print("NORMAL MOISTURE 3");
      lcd.setCursor(2, 1);
      lcd.print("MOTOR3 OFF";
      delay(2000);
      lcd.clear();
    }
    else if digitalRead(sensor3, LOW);
    {
      digitalWrite(led3, HIGH);
      digitalWrite(motor3, HIGH);
      lcd.print("LOW MOISTURE 3");
      lcd.setCursor(2, 1);
      lcd.print("MOTOR3 on");
      delay(2000);
      lcd.clear();
    }
    if digitalRead(sensor4, HIGH);
    {
      digitalWrite(led4, LOW);
      digitalWrite(motor4, LOW);
      lcd.print("NORMAL MOISTURE 4");
      lcd.setCursor(2, 1);
      lcd.print("MOTOR4 OFF";
                delay(2000);
                lcd.clear();
    }
    else if digitalRead(sensor4, LOW);
    {
      digitalWrite(led4, HIGH);
      digitalWrite(motor4, HIGH);
      lcd.print("LOW MOISTURE 4");
      lcd.setCursor(2, 1);
      lcd.print("MOTOR4 on");
      delay(2000);
      lcd.clear();
    }
  }

Where does the setup function end?

you have

void setup()

in line 1 and line 19
try removing line 1??

horace:
you have

void setup()

in line 1 and line 19
try removing line 1??

Are looking at the same code as me?

@horace
here is the complete code error msg

C:\Users\M.FAISAL\Desktop\NEW_CODE_FOR_IRRIGATION_SELF\NEW_CODE_FOR_IRRIGATION_SELF.ino: In function ‘void setup()’:

NEW_CODE_FOR_IRRIGATION_SELF:65: error: a function-definition is not allowed here before ‘{’ token

{

^

NEW_CODE_FOR_IRRIGATION_SELF:147: error: expected ‘}’ at end of input

}

^

Using library LiquidCrystal at version 1.0.4 in folder: C:\Program Files (x86)\Arduino\libraries\LiquidCrystal
exit status 1
a function-definition is not allowed here before ‘{’ token

And when you've fixed that, there's this

  if digitalRead(sensor1 , HIGH);

else if digitalRead(sensor1, LOW);etc, etc

Use tools -> auto format in the IDE. this will properly indent your code.

After that, all functions definitions should start at the beginning of a line.

...
...
void setup()
{
  ...
  ...
  void loop()
  {
    ...
    ...

As you can see, the definition of loop() does not start at the beginning of a line which indicates a mismatch of { and } before that.

AWOL is correct with the question where setup() ends.

in my void setup () function i was missing a brace } at the end of setup
now that is fixed.

Next you can start working at the other problems.

Something like below also does not look right :wink:

    lcd.print("NORMAL MOISTURE 1"
              lcd.setCursor(2, 1);
              lcd.print("MOTOR1 OFF");
              delay (2000);
              lcd.clear();

No { in sight so all lines should start at the same position after an auto-format.

sterretje:
Next you can start working at the other problems.

Something like below also does not look right :wink:

    lcd.print("NORMAL MOISTURE 1"

lcd.setCursor(2, 1);
              lcd.print(“MOTOR1 OFF”);
              delay (2000);
              lcd.clear();



No { in sight so all lines should start at the same position after an auto-format.

i can not under stand what are you trying to say.
may be you are saying that each of the lcd function should start from brace

 { lcd.print("NORMAL MOISTURE 4");
    lcd.setCursor(2, 1);
    lcd.print("MOTOR4 OFF";
              delay(2000);
              lcd.clear();}
lcd.print("NORMAL MOISTURE 1"
                lcd.setCursor(2, 1);

That first line is missing its );

now thats also done

  lcd.print("LOW MOSITURE 1");
    lcd.setCursor(2, 1);
    lcd.print("MOTOR1 ON");

itx-opps:
now thats also done

  lcd.print("LOW MOSITURE 1");

lcd.setCursor(2, 1);
    lcd.print("MOTOR1 ON");

You did not autoformat after that :wink: It would have looked like

    lcd.print("NORMAL MOISTURE 1");
    lcd.setCursor(2, 1);
    lcd.print("MOTOR1 OFF");
    delay (2000);
    lcd.clear();

let see it is now auto formated

#include<LiquidCrystal.h>
LiquidCrystal lcd (9, 10, 7, 6, 5, 4);
int sensor1 = 31;
int sensor2 = 32;
int sensor3 = 33;
int sensor4 = 34;
int motor1 = 36;
int motor2 = 37;
int motor3 = 38;
int motor4 = 39;
int led1 = 40;
int led2 = 41;
int led3 = 42;
int led4 = 43;
int rain = 30;
int buz = 44;
void setup()
{
  pinMode(sensor1, INPUT);
  pinMode(sensor2, INPUT);
  pinMode(sensor3, INPUT);
  pinMode(sensor4, INPUT);
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(motor1, OUTPUT);
  pinMode(motor2, OUTPUT);
  pinMode(motor3, OUTPUT);
  pinMode(motor4, OUTPUT);
  pinMode(buz, OUTPUT);
  pinMode(rain, INPUT);
  lcd.begin(16, 2);
  lcd.print("SMART IRRIGATION");
  lcd.setCursor(2, 1);
  lcd.print("...SYSTEM...");
  delay(2000);
  lcd.clear();
  lcd.print("PRESENTED BY");
  lcd.setCursor(2, 1);
  lcd.print("BSC ELECTRICAL");
  delay(2000);
  lcd.clear();
  lcd.print("GROUP MEMBERS");
  lcd.setCursor(2, 1);
  lcd.print("---------------");
  delay(2000);
  lcd.clear();
  lcd.print("IKRAM UL HAQ");
  lcd.setCursor(2, 1);
  lcd.print("BEEF15M003");
  delay(2000);
  lcd.clear();
  lcd.print("BEHZAD ASGHAR");
  lcd.setCursor(2, 1);
  lcd.print("BEEF15M026");
  delay(2000);
  lcd.clear();
  lcd.print("TALHA HAIDER");
  lcd.setCursor(2, 1);
  lcd.print("BEEF15M039");
  delay(2000);
  lcd.clear();
}
void mtr1()
{
  if digitalRead(sensor1 , HIGH);

  {
    digitalWrite(led1, LOW);
    digitalWrite(motor1, LOW);
    lcd.print("NORMAL MOISTURE 1");
    lcd.setCursor(2, 1);
    lcd.print("MOTOR1 OFF");
    delay (2000);
    lcd.clear();
  }
  else
  {
    digitalWrite(led1, HIGH);
    digitalWrite(motor1, HIGH);
    lcd.print("LOW MOSITURE 1");
    lcd.setCursor(2, 1);
    lcd.print("MOTOR1 ON");
    delay(2000);
    lcd.clear();
  }
}
void mtr2()
{
  if digitalRead(sensor2, HIGH);
  {
    digitalWrite(led2 , LOW);
    digitalWrite(motor2, LOW);
    lcd.print("NORMAL MOISTURE 2");
    lcd.setCursor(2, 1);
    lcd.print("MOTOR2 OFF");
    delay(2000);
    lcd.clear();
  }
  else
  {
    digitalWrite(led2, HIGH);
    digitalWrite(motor2 , HIGH);
    lcd.print("LOW MOISTURE 2");
    lcd.setCursor(2, 1);
    lcd.print("MOTOR2 ON");
    delay(2000);
    lcd.clear();
  }
}
void mtr3()
{
  if digitalRead(sensor3, HIGH);
  {
    digitalWrite(led3, LOW);
    digitalWrite(motor3, LOW);
    lcd.print("NORMAL MOISTURE 3");
    lcd.setCursor(2, 1);
    lcd.print("MOTOR3 OFF");
    delay(2000);
    lcd.clear();
  }
  else
  {
    digitalWrite(led3, HIGH);
    digitalWrite(motor3, HIGH);
    lcd.print("LOW MOISTURE 3");
    lcd.setCursor(2, 1);
    lcd.print("MOTOR3 on");
    delay(2000);
    lcd.clear();
  }
}
void mtr4()
{
  if digitalRead(sensor4, HIGH);
  {
    digitalWrite(led4, LOW);
    digitalWrite(motor4, LOW);
    lcd.print("NORMAL MOISTURE 4");
    lcd.setCursor(2, 1);
    lcd.print("MOTOR4 OFF");
    delay(2000);
    lcd.clear();
  }
  else
  {
    digitalWrite(led4, HIGH);
    digitalWrite(motor4, HIGH);
    lcd.print("LOW MOISTURE 4");
    lcd.setCursor(2, 1);
    lcd.print("MOTOR4 on");
    delay(2000);
    lcd.clear();
  }
}

but again gives new error msg
err msg is
C:\Users\M.FAISAL\Desktop\NEW_CODE_FOR_IRRIGATION_SELF\NEW_CODE_FOR_IRRIGATION_SELF.ino: In function ‘void mtr1()’:

NEW_CODE_FOR_IRRIGATION_SELF:67: error: expected ‘(’ before ‘digitalRead’

if digitalRead(sensor1 , HIGH);

^

NEW_CODE_FOR_IRRIGATION_SELF:78: error: ‘else’ without a previous ‘if’

else

^

C:\Users\M.FAISAL\Desktop\NEW_CODE_FOR_IRRIGATION_SELF\NEW_CODE_FOR_IRRIGATION_SELF.ino: In function ‘void mtr2()’:

NEW_CODE_FOR_IRRIGATION_SELF:91: error: expected ‘(’ before ‘digitalRead’

if digitalRead(sensor2, HIGH);

^

NEW_CODE_FOR_IRRIGATION_SELF:101: error: ‘else’ without a previous ‘if’

else

^

C:\Users\M.FAISAL\Desktop\NEW_CODE_FOR_IRRIGATION_SELF\NEW_CODE_FOR_IRRIGATION_SELF.ino: In function ‘void mtr3()’:

NEW_CODE_FOR_IRRIGATION_SELF:114: error: expected ‘(’ before ‘digitalRead’

if digitalRead(sensor3, HIGH);

^

NEW_CODE_FOR_IRRIGATION_SELF:124: error: ‘else’ without a previous ‘if’

else

^

C:\Users\M.FAISAL\Desktop\NEW_CODE_FOR_IRRIGATION_SELF\NEW_CODE_FOR_IRRIGATION_SELF.ino: In function ‘void mtr4()’:

NEW_CODE_FOR_IRRIGATION_SELF:137: error: expected ‘(’ before ‘digitalRead’

if digitalRead(sensor4, HIGH);

^

NEW_CODE_FOR_IRRIGATION_SELF:147: error: ‘else’ without a previous ‘if’

else

^

Using library LiquidCrystal at version 1.0.4 in folder: C:\Program Files (x86)\Arduino\libraries\LiquidCrystal
exit status 1
expected ‘(’ before ‘digitalRead’

  if digitalRead(sensor1 , HIGH);Three things wrong here.

AWOL already pointed that one out :wink:

Look closely at the example code in the reference for if..else and compare it with what you created.

Tip:
If you're new to this programming, you write in small pieces and compile and test. Having four functions with the same mistake does not make sense.

:slight_smile: i have made these three thing ok now the code is

#include<LiquidCrystal.h>
LiquidCrystal lcd (9, 10, 7, 6, 5, 4);
int sensor1 = 31;
int sensor2 = 32;
int sensor3 = 33;
int sensor4 = 34;
int motor1 = 36;
int motor2 = 37;
int motor3 = 38;
int motor4 = 39;
int led1 = 40;
int led2 = 41;
int led3 = 42;
int led4 = 43;
int rain = 30;
int buz = 44;
void setup()
{
  pinMode(sensor1, INPUT);
  pinMode(sensor2, INPUT);
  pinMode(sensor3, INPUT);
  pinMode(sensor4, INPUT);
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(motor1, OUTPUT);
  pinMode(motor2, OUTPUT);
  pinMode(motor3, OUTPUT);
  pinMode(motor4, OUTPUT);
  pinMode(buz, OUTPUT);
  pinMode(rain, INPUT);
  lcd.begin(16, 2);
  lcd.print("SMART IRRIGATION");
  lcd.setCursor(2, 1);
  lcd.print("...SYSTEM...");
  delay(2000);
  lcd.clear();
  lcd.print("PRESENTED BY");
  lcd.setCursor(2, 1);
  lcd.print("BSC ELECTRICAL");
  delay(2000);
  lcd.clear();
  lcd.print("GROUP MEMBERS");
  lcd.setCursor(2, 1);
  lcd.print("---------------");
  delay(2000);
  lcd.clear();
  lcd.print("IKRAM UL HAQ");
  lcd.setCursor(2, 1);
  lcd.print("BEEF15M003");
  delay(2000);
  lcd.clear();
  lcd.print("BEHZAD ASGHAR");
  lcd.setCursor(2, 1);
  lcd.print("BEEF15M026");
  delay(2000);
  lcd.clear();
  lcd.print("TALHA HAIDER");
  lcd.setCursor(2, 1);
  lcd.print("BEEF15M039");
  delay(2000);
  lcd.clear();
}
void mtr1()
{
  if (digitalRead(sensor1)== HIGH)

  {
    digitalWrite(led1, LOW);
    digitalWrite(motor1, LOW);
    lcd.print("NORMAL MOISTURE 1");
    lcd.setCursor(2, 1);
    lcd.print("MOTOR1 OFF");
    delay (2000);
    lcd.clear();
  }
  else
  {
    digitalWrite(led1, HIGH);
    digitalWrite(motor1, HIGH);
    lcd.print("LOW MOSITURE 1");
    lcd.setCursor(2, 1);
    lcd.print("MOTOR1 ON");
    delay(2000);
    lcd.clear();
  }
}
void mtr2()
{
  if (digitalRead(sensor2)== HIGH)
  {
    digitalWrite(led2 , LOW);
    digitalWrite(motor2, LOW);
    lcd.print("NORMAL MOISTURE 2");
    lcd.setCursor(2, 1);
    lcd.print("MOTOR2 OFF");
    delay(2000);
    lcd.clear();
  }
  else
  {
    digitalWrite(led2, HIGH);
    digitalWrite(motor2 , HIGH);
    lcd.print("LOW MOISTURE 2");
    lcd.setCursor(2, 1);
    lcd.print("MOTOR2 ON");
    delay(2000);
    lcd.clear();
  }
}
void mtr3()
{
  if (digitalRead(sensor3)== HIGH)
  {
    digitalWrite(led3, LOW);
    digitalWrite(motor3, LOW);
    lcd.print("NORMAL MOISTURE 3");
    lcd.setCursor(2, 1);
    lcd.print("MOTOR3 OFF");
    delay(2000);
    lcd.clear();
  }
  else
  {
    digitalWrite(led3, HIGH);
    digitalWrite(motor3, HIGH);
    lcd.print("LOW MOISTURE 3");
    lcd.setCursor(2, 1);
    lcd.print("MOTOR3 on");
    delay(2000);
    lcd.clear();
  }
}
void mtr4()
{
  if (digitalRead(sensor4)== HIGH)
  {
    digitalWrite(led4, LOW);
    digitalWrite(motor4, LOW);
    lcd.print("NORMAL MOISTURE 4");
    lcd.setCursor(2, 1);
    lcd.print("MOTOR4 OFF");
    delay(2000);
    lcd.clear();
  }
  else
  {
    digitalWrite(led4, HIGH);
    digitalWrite(motor4, HIGH);
    lcd.print("LOW MOISTURE 4");
    lcd.setCursor(2, 1);
    lcd.print("MOTOR4 on");
    delay(2000);
    lcd.clear();
  }
}

with this error msg

C:\Users\M67BC~1.FAI\AppData\Local\Temp\build7a35629f1972894cc573ba0a0c21eb38.tmp/core\core.a(main.cpp.o): In function `main’:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/main.cpp:43: undefined reference to `loop’

collect2.exe: error: ld returned 1 exit status

Using library LiquidCrystal at version 1.0.4 in folder: C:\Program Files (x86)\Arduino\libraries\LiquidCrystal
exit status 1
Error compiling.

Well, can you see a function called loop?

AWOL:
Well, can you see a function called loop?

AWOL:
Well, can you see a function called loop?

i really cant not understand that what is the loop reference
i am new to programing and used four loops for 4 different functions
will any one of you elaborate the loop

An Arduino sketch has two required functions, setup() and loop(). Even if these functions are empty, they are required (e.g. the bare minimum example)