Error: expected constructor, destructor, or type conversion before '(' token conversion

Hello I am Making a project involving the 'HC - SR04' ultrasonic sensor and the 'HC - 05' Bluetooth
module. I am having the following error in the code. When I didn't add the Bluetooth module in the code it was working just fine. Help will be appreciated.
CODE:

int Trig = 7;
int echo = 6;
int Led = 12;
long Time;
int distance;
int VALUE;
void setup()
{
  pinMode(Trig,OUTPUT);
  pinMode(echo, INPUT);
  pinMode(Led, OUTPUT);
  pinMode(11, OUTPUT);

}

void loop()
{
  Serial.begin(9600);
  if (Serial.available() > 0)
  VALUE = Serial.read();
  if(VALUE == '1'){
    digitalWrite(Led, HIGH);
  }  else if(VALUE == '0'){
    digitalWrite(Led, LOW);
  }
  }
  digitalWrite(Trig, LOW);
  delay(2);
  digitalWrite(Trig, HIGH);
  delay(10);
  digitalWrite(Trig, LOW);
  
  Time = pulseIn(echo, HIGH);
  distance = Time*0.034/2;
  
  
  if(distance <= 30){
    digitalWrite(Led, HIGH);
    delay(200);
    digitalWrite(Led, LOW);
    delay(200);
    digitalWrite(Led, HIGH);
    Serial.println("INTRUDER ALERT!!");
    digitalWrite(11, HIGH);}
  
}

Thank you.

You've got an extra } that needs to go...

void loop()
{
   Serial.begin(9600);
   if (Serial.available() > 0)
      VALUE = Serial.read();
   if (VALUE == '1')
   {
      digitalWrite(Led, HIGH);
   }
   else if (VALUE == '0')
   {
      digitalWrite(Led, LOW);
   }
} // <<<<<<<<<<<<<<<<<<<<   extra } closes loop() early
digitalWrite(Trig, LOW);
delay(2);
digitalWrite(Trig, HIGH);
delay(10);
digitalWrite(Trig, LOW);

Use the very handy IDE autoformat tool (ctrl-t or Tools, Auto format) and you will see the above. Note the indenting plainly shows where you have the extra closing curly bracket pointed out by member @red_car. Since the loop() function is closed early, all the rest of the code is outside of a function which is an error.

Thank you very much. Will do the following changes.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.