Some Error in Program, Need Solution

Error massage-
C:\hc_05_relay_buzzer_by_uno\hc_05_relay_buzzer_by_uno.ino: In function 'void setup()':
hc_05_relay_buzzer_by_uno:84:3: error: a function-definition is not allowed here before '{' token
{
^
hc_05_relay_buzzer_by_uno:100:3: error: expected '}' at end of input
}
^
Using library SoftwareSerial at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SoftwareSerial
exit status 1
a function-definition is not allowed here before '{' token

Code:

#include <SoftwareSerial.h>
SoftwareSerial BTserial(2, 3); // RX | TX
int relay = 6;
int buzzer = 7;
char c = ' ';

// BTconnected will = false when not connected and true when connected
boolean BTconnected = false;

// connect the STATE pin to Arduino pin D4
const byte BTpin = 4;


void setup()
{
  // set the BTpin for input
  pinMode(BTpin, INPUT);
  pinMode(relay, OUTPUT);
  pinMode(buzzer, OUTPUT);
  // start serial communication with the serial monitor on the host computer
  Serial.begin(9600);
  Serial.println("Arduino is ready");
  Serial.println("Connect the HC-05 to an Android device to continue");

  // wait until the HC-05 has made a connection
  while (!BTconnected)
  {
    if ( digitalRead(BTpin) == HIGH)  {
      BTconnected = true;
      digitalWrite(relay, HIGH); // This will Turn the Relay On
      digitalWrite(buzzer, HIGH); // This will Turn the Buzzer On
      delay(3000); // Wait for 3 seconds

      Serial.println("HC-05 is now connected");
      Serial.println("");

      // Start serial communication with the bluetooth module
      // HC-05 default serial speed for communication mode is 9600 but can be different
      BTserial.begin(9600);

    }

    else
    { digitalWrite(relay, LOW); // This will Turn the Relay Off
      digitalWrite(buzzer, HIGH); // This will Turn the Buzzer On
      delay(1000); // Wait for 1 seconds
      digitalWrite(buzzer, LOW); // This will Turn the Buzzer Off
      delay(1000); // Wait for 1 seconds
      digitalWrite(buzzer, HIGH); // This will Turn the Buzzer On
      delay(1000); // Wait for 1 seconds
      digitalWrite(buzzer, LOW); // This will Turn the Buzzer Off
      delay(1000); // Wait for 1 seconds
      digitalWrite(buzzer, HIGH); // This will Turn the Buzzer On
      delay(1000); // Wait for 1 seconds
      digitalWrite(buzzer, LOW); // This will Turn the Buzzer Off
      delay(1000); // Wait for 1 seconds


      Serial.println("HC-05 is now disconnected");
      Serial.println("");
      // Start serial communication with the Bluetooth module
      // HC-05 default serial speed for communication mode is 9600 but can be different

    };

  }

  void loop()
  {

    // Keep reading from the HC-05 and send to Arduino Serial Monitor
    if (BTserial.available())
    {
      c = BTserial.read();
      Serial.write(c);
    }

    // Keep reading from Arduino Serial Monitor input field and send to HC-05
    if (Serial.available())
    {
      c =  Serial.read();
      BTserial.write(c);
    }

  }

Can you please edit your post to put the code inside code tags.

You are also missing a } at the end of setup! Using CTRL + T will auto format the code, and you will see the mismatch.

Your setup function is missing a final closing brace.

For the compile error, you're missing a brace at the end of setup():

.
.
.
      Serial.println("");
      // Start serial communication with the Bluetooth module
      // HC-05 default serial speed for communication mode is 9600 but can be different

    };

  }

}// <-- missing this

  void loop()
  {

    // Keep reading from the HC-05 and send to Arduino Serial Monitor
    if (BTserial.available())
.
.
.

missdrew:
Can you please edit your post to put the code inside code tags.

You are also missing a } at the end of setup! Using CTRL + T will auto format the code, and you will see the mismatch.

Thanks for your reply,I have tryed ctrl +T /auto format but Don't get any solution.

Thanks for your reply,I have tryed ctrl +T /auto format but Don't get any solution.

But you have been given the solution, THREE times.

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