What is Wrong?

Please help me and my friend with our schoolproject.
We are trying to make a temperature triggered alarm.

The error message is:

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

The program is:

[code]const int sensorValue = A0;
const int Celsius = (sensorValue*5000/1024)/10;
const int Fahrenheit = Celsius*1.8+32;
const float basetemp = 75.0;

void setup(){

 {
 //Define the vaults
   Serial.begin(9600);
 //Define pin A0 as input
 pinMode(A0, INPUT);
 //Define pins 10, 11, 12, & 13 as output
 pinMode(10, OUTPUT);
 pinMode(11, OUTPUT);
 pinMode(12, OUTPUT);
 pinMode(13, OUTPUT);
}

{
void loop()

{
 //Assign analog Pin A0 read to the variable mV
 int sensorValue = analogRead(A0);
 //Coversion from mV to Celsius
 Serial.print("Celsius: ");
 Serial.print(Celsius);
 Serial.print("\tFahrenheit: ");
 Serial.print(Fahrenheit);
 Serial.print("\n");
}
 //If temperature less or equal than 59 turn green led on
{
 if(Fahrenheit <= 59);
   digitalWrite(13, HIGH);
   digitalWrite(12, LOW);
   digitalWrite(11, LOW);
   digitalWrite(10, LOW);
} 
 //If temperature less or equal then 100 turn yellow led on
{
   else if(Fahrenheit <= 100)
   digitalWrite(13, LOW);
   digitalWrite(12, HIGH);
   digitalWrite(11, LOW);
   digitalWrite(10, LOW);
}
 //If temperature greater than 100 turn red led and buzzer on

{
   else (Fahrenheit =>100)
   digitalWrite(13, LOW);
   digitalWrite(12, LOW);
   digitalWrite(11, HIGH);
   digitalWrite(10, HIGH);
}
 
 
 delay(2000);
 }

Thanks in advance!

Best regards, Daniel from Brejning Continuation School
Denmark

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Check ALL your { and }.
You have some extra ones.
You should have an equal number of {and }

Press CTRL -T, this will format you code so you can check your brackets.

Tom.... :slight_smile:

Hi,

{
void loop()

The { might be your first problem.

Also have a look at how to code an if statement.

Tom.. :slight_smile:

Hey Tom.

Thanks for the help, but i still dosn't work.

i have checked all the {and}, and there is 6 of each so i can't see the problem?

I have deleted the one before voidloop

Daniel

@Dani125e, To make it easy for people to help you please use the code button </>

so your code looks like this

and is easy to copy to a text editor. See How to use the Forum

Post the latest version of your program in your next Reply and also post the complete error message. It will have a line number.

...R

The edited version of the program

const int sensorValue = A0;
const int Celsius = (sensorValue * 5000 / 1024) / 10;
const int Fahrenheit = Celsius * 1.8 + 32;
const float basetemp = 75.0;

void setup() {

  {
    //Define the vaults
    Serial.begin(9600);
    //Define pin A0 as input
    pinMode(A0, INPUT);
    //Define pins 10, 11, 12, & 13 as output
    pinMode(10, OUTPUT);
    pinMode(11, OUTPUT);
    pinMode(12, OUTPUT);
    pinMode(13, OUTPUT);
  }


  void loop()

  {
    //Assign analog Pin A0 read to the variable mV
    int sensorValue = analogRead(A0);
    //Coversion from mV to Celsius
    Serial.print("Celsius: ");
    Serial.print(Celsius);
    Serial.print("\tFahrenheit: ");
    Serial.print(Fahrenheit);
    Serial.print("\n");
  }
  //If temperature less or equal than 59 turn green led on
  {
    if (Fahrenheit <= 59);
    digitalWrite(13, HIGH);
    digitalWrite(12, LOW);
    digitalWrite(11, LOW);
    digitalWrite(10, LOW);
  }
  //If temperature less or equal then 100 turn yellow led on
  {
    else if (Fahrenheit <= 100)
      digitalWrite(13, LOW);
    digitalWrite(12, HIGH);
    digitalWrite(11, LOW);
    digitalWrite(10, LOW);
  }
  //If temperature greater than 100 turn red led and buzzer on

  {
    else (Fahrenheit => 100)
      digitalWrite(13, LOW);
    digitalWrite(12, LOW);
    digitalWrite(11, HIGH);
    digitalWrite(10, HIGH);
  }


  delay(2000);
}

The full error message

C:\Users\Daniel\Documents\Arduino\sketch_mar06b\sketch_mar06b.ino: In function 'void setup()':

sketch_mar06b:24: error: a function-definition is not allowed here before '{' token

   {

   ^

sketch_mar06b:44: error: 'else' without a previous 'if'

     else if (Fahrenheit <= 100)

     ^

sketch_mar06b:53: error: 'else' without a previous 'if'

     else (Fahrenheit => 100)

     ^

sketch_mar06b:53: error: expected primary-expression before '>' token

     else (Fahrenheit => 100)

                       ^

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

Hi,

===================================================================
const int sensorValue = A0;
const int Celsius = (sensorValue * 5000 / 1024) / 10;
const int Fahrenheit = Celsius * 1.8 + 32;
const float basetemp = 75.0;

void setup() {

{ <===============================
//Define the vaults
Serial.begin(9600);
//Define pin A0 as input
pinMode(A0, INPUT);
//Define pins 10, 11, 12, & 13 as output
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
}

void loop()

{
//Assign analog Pin A0 read to the variable mV
int sensorValue = analogRead(A0);
//Coversion from mV to Celsius
Serial.print("Celsius: ");
Serial.print(Celsius);
Serial.print("\tFahrenheit: ");
Serial.print(Fahrenheit);
Serial.print("\n");
} <======================================
//If temperature less or equal than 59 turn green led on
{
if (Fahrenheit <= 59);
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
}
//If temperature less or equal then 100 turn yellow led on
{
else if (Fahrenheit <= 100)
digitalWrite(13, LOW);
digitalWrite(12, HIGH);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
} Check how to write an IF statement, see post #2
//If temperature greater than 100 turn red led and buzzer on

{
else (Fahrenheit => 100)
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(11, HIGH);
digitalWrite(10, HIGH);
}

delay(2000);
}

Look at the link I left you in post #2, and look at your code above and what I have highlighted in RED.

Tom.... :slight_smile:

After you use tools -> autoformat, all functions (e.g. void loop) should start at the beginning of a line.

In your case it does not, void loop() is indented. This indicates a mismatch of { and } before void loop().

i have checked all the {and}, and there is 6 of each

But are they in the right places ?

Firstly, “const int sensorValue = A0”
so you are creating a constant integer – one that cannot be changed later on – and setting it to A0.
This looks very much like an Arduino pin number, you would be better calling it “sensorPin”.

In your “void loop()” section of code you use sensorValue again, but this time declare it as an “int”. I'm not sure whether these are supposed to be separate variables or the same one, if they are separate you should give them different names or it will be very confusing later on, if they are the same then you only need to define the variable type once, but if you define it as a “const int” you cannot modify it later on ie. you cannot do “sensorValue = analogRead(A0);”

Thanks for the answars now the lampsworks... but the speaker dosn´t
eventhough i set it to HIGH

Dani125e:
Thanks for the answars now the lampsworks... but the speaker dosn´t
eventhough i set it to HIGH

You have to post the latest version of your program.

Without that we are blind.

...R

I can't see anything in your program that tells me that there are any lamps or speakers involved at all. Have you considered giving the pins that you're using useful names like speakerPin or redLEDPin?

It would also help if you said what "lamps" and "speaker" you are using e.g. most speakers won't do anything if you just set a pin high.

Steve