Please help, what to do? error: a function-definition is not allowed here before

Hey guys, we are making a school project, we are connecting our arduino via bluetooth, our goal is to let a lego technic car drive. We got some code, but we don’t know what exactly is wrong, since we just started learning the language.

// old line: #include <NewSoftSerial.h>   //Software Serial Port
#include <SoftwareSerial.h>               //new line
#define RxD 4
#define TxD 7
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

#define DEBUG_ENABLED  1

// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61); 

// Select which 'port' M1, M2, M3 or M4. In this case, M1
Adafruit_DCMotor *myMotor = AFMS.getMotor(1);
// You can also make another motor on port M2
//Adafruit_DCMotor *myOtherMotor = AFMS.getMotor(2);

// old line: NewSoftSerial blueToothSerial(RxD,TxD);
SoftwareSerial blueToothSerial(RxD,TxD);  //new line

void setup()
  AFMS.begin();  // create with the default frequency 1.6KHz
  //AFMS.begin(1000);  // OR with a different frequency, say 1KHz
  // Set the speed to start, from 0 (off) to 255 (max speed)
  // turn on motor

 pinMode(RxD, INPUT);
 pinMode(TxD, OUTPUT);


void loop()
 char recvChar;
   if(blueToothSerial.available()){//check if there's any data sent from the remote bluetooth shield
     recvChar =;
    if (recvChar = 'V') {
    if (recvChar = 'A') {

      if (recvChar = 'R'){
        // servo1(rechts);

   if (recvChar = 'l'){
  /* if(Serial.available()){//check if there's any data sent from the local serial terminal, you can add the other applications here
     recvChar  =;

void setupBlueToothConnection() 

 blueToothSerial.begin(9600); //Set BluetoothBee BaudRate to default baud rate 38400
 blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
 blueToothSerial.print("\r\n+STNA=SeeedBTSlave\r\n"); //set the bluetooth name as "SeeedBTSlave"
 blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
 blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
 delay(2000); // This delay is required.
 blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable
 Serial.println("The slave bluetooth is inquirable!");
 delay(2000); // This delay is required.

The problem is in the last bit of the code. These are the errors:
Project.ino: In function ‘void loop()’:
Project:88: error: a function-definition is not allowed here before ‘{’ token
Project:100: error: expected `}’ at end of input

Thanks in advance!

Moderator edit: CODE TAGS

The compiler has a problem in line 88, so that is where to look, or in the previous statement.

You can turn on the line number in the settings in the Arduino IDE.
In the menu of the Arduino IDE is also an option to auto-format the text. If you use that, and carefully check the code for '}' and '}' and '(' and ')', you probably find where the mismatch is.

while (1) {
does not have a matching brace. This invalid result is that the setupBlueToothConnection() function is actually defined inside the loop() function.