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

Hi! I´m trying to do an arduino SmartLock, with a Servo and a Bluetooth Model (hc-05), but keep getting error. How can i fix it?

Thank you

#include <SoftwareSerial.h>
#include <Servo.h>
#include <EEPROM.h>
Servo servoMotor; // Declaramos la variable para controlar el servo
SoftwareSerial BT1(10, 11); // RX | TX
Servo servo;
char state;
void setup()
{ pinMode(8, OUTPUT);        // Al poner en HIGH forzaremos el modo AT
  pinMode(9, OUTPUT);        // cuando se alimente de aqui
  digitalWrite(9, HIGH);
  delay (500) ;              // Espera antes de encender el modulo
  Serial.begin(9600);        // Iniciamos el monitor serie para mostrar el resultado
  Serial.println("Levantando el modulo HC-06");
  digitalWrite (8, HIGH);    //Enciende el modulo
  Serial.println("Esperando comandos AT:");
  BT1.begin(9600);
  servoMotor.attach(7);  // Iniciamos el servo para que empiece a trabajar con el pin 7
  // codigo del chino
  if (EEPROM.read(0) == 1) // Reads the EEPROM value stored to know what state the door lock was in before it was last turned off
  { // An EEPROM value of 1 means UNLOCKED and a value of 2 means LOCKED
    servo.write(70); // Rotates the servo to the unlocked position
    delay(200);
  }
  else if (EEPROM.read(0) == 2)
  {
    servo.write(120); // Rotates the servo to the locked position
    delay(200);
    // arriba termina el codigo de tostada francesa sexy

  }

  void loop(){
   if (Serial.available() > 0)
      char data;
    data = Serial.read(); // The variable data is used to store the value sent by the Android app

    switch (data)
    {
      case '1':
        if (EEPROM.read(0) == 1) //An EEPROM value of 1 means it is currently unlocked
        {
          EEPROM.write(0, 2); // Writes the number 2 to address 0 on the Arduino's EEPROM. This value will be used by the Arduino to remember the last state the door lock was in
          Serial.print("3"); // Sends the number 3 to the Android app. To see what this does, please see the Android Studio Project file

          for (int a = 70; a <= 120; a++) // Rotates the servo to the locked position
          {
            servo.write(a);
            delay(15);
            Serial.println(servo.read());
          }
        }
        else if (EEPROM.read(0) == 2) //An EEPROM value of 2 means it i currently locked
        {
          EEPROM.write(0, 1); // Writes the number 1 to address 0 on the Arduino's EEPROM. This value will be used by the Arduino to remember the last state the door lock was in
          Serial.print("4"); // Sends the number 4 to the Android app. The number sent will be used by the app to update the locked/unlocked icon
          for (int x = 120; x >= 70; x--) // Rotates the servo to the unlocked position
          {
            servo.write(x);
            delay(15);
          }
        }
        break;
      case '3':
        // This part of the switch case statement is used everytime the Arduino is turned on
        // Basically, the Android app sends a command asking the Arduino to send the current state of the lock in order to accordingly update the locked/unlocked icon in the app
        if (EEPROM.read(0) == 1)
        {
          Serial.print("4");
        }
        else if (EEPROM.read(0) == 2)
        {
          Serial.print("3");
        }
        break;
    }
  }

}

You are missing the end curly brace for the setup() function.

  }

  void loop()

Where is the opening brace to that closing brace?

A { needs a }

.

I'll buy coffee.

.

larryd:
I'll buy coffee.

.

. :slight_smile:

Hey guys, can you help me out? I keep on trying to use this code, but I keep getting a function-definition is not allowed here before { token:

const int pingPin = 2;

int sensingRangeUnit = 11; int buzzerLimit = 100; int buzzerFrequency;

void setup() {

pinMode(3, OUTPUT); // sets the digital pin 3 as output for a buzzer pinMode(4, OUTPUT); // sets the digital pin 4 as output for an LED pinMode(5, OUTPUT); // sets the digital pin 5 as output for an LED pinMode(6, OUTPUT); // sets the digital pin 6 as output for an LED pinMode(7, OUTPUT); // sets the digital pin 7 as output for an LED pinMode(8, OUTPUT); // sets the digital pin 8 as output for an LED pinMode(9, OUTPUT); // sets the digital pin 9 as output for an LED pinMode(10, OUTPUT); // sets the digital pin 10 as output for an LED pinMode(11, OUTPUT); // sets the digital pin 11 as output for an LED pinMode(12, OUTPUT); // sets the digital pin 12 as output for an LED pinMode(13, OUTPUT); // sets the digital pin 13 as output for an LED Serial.begin(9600);

}

void loop() { long duration, inches, cm;

pinMode(pingPin, OUTPUT); digitalWrite(pingPin, LOW); delayMicroseconds(2); digitalWrite(pingPin, HIGH); delayMicroseconds(5); digitalWrite(pingPin, LOW);

pinMode(pingPin, INPUT); duration = pulseIn(pingPin, HIGH);

// convert the time into a distance inches = microsecondsToInches(duration); cm = microsecondsToCentimeters(duration); Serial.print(inches); Serial.print("in, "); Serial.print(cm); Serial.print("cm"); Serial.println();

if (inches < (sensingRangeUnit*1)) { digitalWrite(4, HIGH); } else { digitalWrite(4, LOW); }

if (inches < (sensingRangeUnit*2)) { digitalWrite(5, HIGH); } else { digitalWrite(5, LOW); }

if (inches < (sensingRangeUnit*3)) { digitalWrite(6, HIGH); } else { digitalWrite(6, LOW); }

if (inches < (sensingRangeUnit*4)) { digitalWrite(7, HIGH); } else { digitalWrite(7, LOW); }

if (inches < (sensingRangeUnit*5)) { digitalWrite(8, HIGH); } else { digitalWrite(8, LOW); }

if (inches < (sensingRangeUnit*6)) { digitalWrite(9, HIGH); } else { digitalWrite(9, LOW); }

if (inches < (sensingRangeUnit*7)) { digitalWrite(10, HIGH); } else { digitalWrite(10, LOW); }

if (inches < (sensingRangeUnit*8)) { digitalWrite(11, HIGH); } else { digitalWrite(11, LOW); }

if (inches < (sensingRangeUnit*9)) { digitalWrite(12, HIGH); } else { digitalWrite(12, LOW); }

if (inches < (sensingRangeUnit*10)) { digitalWrite(13, HIGH); } else { digitalWrite(13, LOW); }

if (inches < buzzerLimit) { buzzerFrequency = (((buzzerLimit - inches)*255)/buzzerLimit); analogWrite(3, buzzerFrequency); } else { analogWrite(3, 0); } delay(100); }

long microsecondsToInches(long microseconds) { // According to Parallax's datasheet))), there are // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per // second). This gives the distance travelled by the ping, outbound // and return, so we divide by 2 to get the distance of the obstacle. return microseconds / 74 / 2; }

long microsecondsToCentimeters(long microseconds) { // The speed of sound is 340 m/s or 29 microseconds per centimeter. // The ping travels out and back, so to find the distance of the // object we take half of the distance travelled. return microseconds / 29 / 2; }

you should start your own thread.

Always show us your ‘current’ compete sketch.
Use CTRL T to format the sketch.
Please use code tags.
Use the </> icon in the posting menu.

[code] Paste sketch here. [/code]

Thanks