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.
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
{
//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
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);”
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.