How to solve: error: expected constructor, destructor, or type conversion

I'm developing a New project , Everything is fine exept one issue. When I execute my code I get the following error:
error: expected constructor, destructor, or type conversion before '(' token

This is my code:

#define enA 9
#define in1 4
#define in2 5
#define enB 10
#define in3 6
#define in4 7

int motorSpeedA = 0;
int motorSpeedB = 0;

int val = 0;

void setup() {
  pinMode(enA, OUTPUT);
  pinMode(enB, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
  Serial.begin(9600); 
}

void loop() {
  //Read input from bluetooth module:
  if( Serial.available())
  {
    val = Serial.read();
  }
  //Input key switch
    switch (val) {
    case '0':    
      motorSpeedA = 0;
      motorSpeedB = 0;//Code when no key is pressed
      break;
    case '1':  
      // Set Motor A forward
      digitalWrite(in1, LOW);
      digitalWrite(in2, HIGH);
      // Set Motor B forward
      digitalWrite(in3, LOW);
      digitalWrite(in4, HIGH);//Code when UP key is pressed
      motorSpeedA= 255;
      motorSpeedB= 255;
      break;
      case '2':    
      // Set Motor A backward
      digitalWrite(in1, HIGH);
      digitalWrite(in2, LOW);
      // Set Motor B backward
      digitalWrite(in3, HIGH);
      digitalWrite(in4, LOW);//Code when DOWN key is pressed
      motorSpeedA= 255;
      motorSpeedB= 255; 
      break;
    case '3':
      analogWrite(enA, 180); //speed 0 - 255
      analogWrite(enB, 180); //speed 0 - 255
      digitalWrite(in1, LOW);
      digitalWrite(in2, HIGH);
      digitalWrite(in3, HIGH);
      digitalWrite(in4, LOW);    
      //Code when LEFT key is pressed
      break;   
    case '4':    
      //Code when RIGHT key is pressed
      analogWrite(enA, 180); //speed 0 - 255
      analogWrite(enB, 180); //speed 0 - 255
      digitalWrite(in1, HIGH);
      digitalWrite(in2, LOW);
      digitalWrite(in3, LOW);
      digitalWrite(in4, HIGH);     
      break;
    case '5':    
      //Code when X key is pressed
      motorSpeedA = 0; 
      break;
    case '6':    
      //Code when O key is pressed
      motorSpeedB=0; 
      break;
    default:
      motorSpeedA = 255;
      motorSpeedB = 255;
      // default code (should never run)
    } 
  }
  analogWrite(enA, motorSpeedA); // Send PWM signal to motor A
  analogWrite(enB, motorSpeedB);
}

Pls help me with this issue

When I execute my code

Nope.

Please post the exact error message (all of it)

This is all of the error message:

Arduino: 1.8.7 (Windows 8.1), Board: "Arduino/Genuino Uno"

BT_controller:87:14: error: expected constructor, destructor, or type conversion before '(' token

analogWrite(enA, motorSpeedA); // Send PWM signal to motor A

^

BT_controller:88:14: error: expected constructor, destructor, or type conversion before '(' token

analogWrite(enB, motorSpeedB);

^

I hope you can solve my problem bro....

BT_controller:89:1: error: expected declaration before '}' token

}

^

exit status 1
expected constructor, destructor, or type conversion before '(' token

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

If you use autoformat (ctrl-t or Tools, Auto Format) you will see that the last 2 lines (the analogWrites) are outside of loop(). Mind your curly brackets.

1 Like

Count the {
Count the }

1 Like

Thanks Bro.

I've got another error.

this is the error message:

Arduino: 1.8.7 (Windows 8.1), Board: "Arduino/Genuino Uno"

BT_controller:89:1: error: expected declaration before '}' token

}

^

exit status 1
expected declaration before '}' token

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

PLS help me in this error

See earlier replies.
If you make ANY changes to your code, you should post the new code.

I just found out the answer.

There was a extra '{' at the last line of the code . Thats why I got a error message.

Anyway thank you guys for helping me.

This is my new Code;

#define enA 9
#define in1 4
#define in2 5
#define enB 10
#define in3 6
#define in4 7

int motorSpeedA = 0;
int motorSpeedB = 0;

int val = 0;

void setup() {
  pinMode(enA, OUTPUT);
  pinMode(enB, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
  Serial.begin(38400);
}

void loop() {
  //Read input from bluetooth module:
  if ( Serial.available())
  {
    val = Serial.read();
    delay(10);
  }
  delay(10);
  //Input key switch
  switch (val) {
    case '0':
      motorSpeedA = 0;
      motorSpeedB = 0;//Code when no key is pressed
      break;
    case '1':
      // Set Motor A forward
      digitalWrite(in1, LOW);
      digitalWrite(in2, HIGH);
      // Set Motor B forward
      digitalWrite(in3, LOW);
      digitalWrite(in4, HIGH);//Code when UP key is pressed
      motorSpeedA = 255;
      motorSpeedB = 255;
      break;
    case '2':
      // Set Motor A backward
      digitalWrite(in1, HIGH);
      digitalWrite(in2, LOW);
      // Set Motor B backward
      digitalWrite(in3, HIGH);
      digitalWrite(in4, LOW);//Code when DOWN key is pressed
      motorSpeedA = 255;
      motorSpeedB = 255;
      break;
    case '3':
      analogWrite(enA, 180); //speed 0 - 255
      analogWrite(enB, 180); //speed 0 - 255
      digitalWrite(in1, LOW);
      digitalWrite(in2, HIGH);
      digitalWrite(in3, HIGH);
      digitalWrite(in4, LOW);
      //Code when LEFT key is pressed
      break;
    case '4':
      //Code when RIGHT key is pressed
      analogWrite(enA, 180); //speed 0 - 255
      analogWrite(enB, 180); //speed 0 - 255
      digitalWrite(in1, HIGH);
      digitalWrite(in2, LOW);
      digitalWrite(in3, LOW);
      digitalWrite(in4, HIGH);
      break;
    case '5':
      //Code when X key is pressed
      motorSpeedA = 0;
      break;
    case '6':
      //Code when O key is pressed
      motorSpeedB = 0;
      break;
    default:
      motorSpeedA = 255;
      motorSpeedB = 255;
      // default code (should never run)
  }
  analogWrite(enA, motorSpeedA); // Send PWM signal to motor A
  analogWrite(enB, motorSpeedB);
}

Thank you :slight_smile: :slight_smile: :slight_smile: :slight_smile: