Hello I have a small problem, there is an error message that I do not understand

Hello I have a small problem, there is an error message that I do not understand ...

Here it is: Arduino: 1.8.6 (Windows 10), Card: "Arduino / Genuino Uno"

C: \ Users \ User \ Documents \ Arduino \ temperature \ temperature.ino: In function 'void loop ()':

temperature: 8: 15: error: a function-definition is not allowed here

void setup () {

^

temperature: 56: 3: error: expected '}' at end of input

}

^

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

I put it in full, I do not know how to interpret and correct it I am a beginner. Thank you in advance !

temperature.ino (1.36 KB)

You seem to have put your setup() function inside your loop() function and you don't have the correct numbers of matching { }

You can't define a function inside another function. Have a look at any of the examples that come with the Arduino IDE.

If you use the AutoFormat tool this sort of problem is easier to see.

...R

Thank you very much for your response to my message, but I think I have solved the problem at this place but there is the same thing to mark lower, but I do not see where the problem is! And I do not have the inpretion that he has the same problem! I give you my code as an attachment and a screenshot.

The new error message: Arduino: 1.8.6 (Windows 10), Card: "Arduino / Genuino Uno"

C: \ Users \ User \ Documents \ Arduino \ temperature \ temperature.ino: In function 'void setup ()':

temperature: 16: 13: error: a function-definition is not allowed here

void loop () {

^

temperature: 56: 3: error: expected '}' at end of input

}

^

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

Thank you so much !

temperature.ino (1.36 KB)

It speeds things up if you post your code.

How ?

I put it in attachment

Thank !

Please include short programs in your Post using the code button </> so they look like this (from Reply #2)

void loop() {
  // put your main code here, to run repeatedly:
  const int sensorPin = A0;
 const float baselineTemp = 20.0;

} void setup (){
   Serial.begin(9600); // ouvrir un port serie 
   for(int pinNumber   = 2; pinNumber<5; pinNumber++){
     pinMode(pinNumber, OUTPUT);
     digitalWrite(pinNumber, LOW);
    
  
  }
 void loop(){
 int sensorVal = analogRead(sensorPin);
 Serial.print("Valeur Capteur :");
 Serial.print(sensorVal);
  // convertir la lecture du CAN EN TENSION 
  float voltage = ( sensorVal/1024.0) * 5.0;
  Serial.print (",Volts :").
  Serial.print(voltage);
  Serial.print(",degres C : ");
  // convertir la tension en temperature en degres 
  float temperature =(voltage - .5) *100;
  Serial.println(temperature)
  if(temperature < baselineTemp){
   digitalWrite(2,LOW);
   digitalWrite(3,LOW);
   digitalWrite(4,LOW);
   }else if(temperature >= baselineTemp+2 &&
  temperature < baselineTemp+4){
     digitalWrite(2, HIGHT);
     digitalWrite(3, LOW);
     digitalWrite(4, LOW);

      }else if(temperature >= baselineTemp+4 &&
  temperature < baselineTemp+6){
     digitalWrite(2, HIGH);
     digitalWrite(3, LOW);
     digitalWrite(4, LOW);

      }else if(temperature >= baselineTemp+6{
      digitalWrite(2, HIGH);
      digitalWrite(3, HIGH);
      digitalWrite(4, HIGH);

    


    
 }
delay(1);
  
  }

Now you have 2 loop() functions. That is not allowed either. Have you studied the layout of several of the examples that come with the Arduino IDE ?

...R

I'm sorry but I do not understand where are my mistakes I followed the arduino starter book, could you please correct me? And I do not know what the IDE is...

Thank you so much

Imagine you have two children.

You name them both "Hildegard".

You want to call one of them in for dinner.

Now, replace "Hildegard" with "loop", and try to imagine the compiler's dilemma.

Juju14a:
And I do not know what the IDE is...

The Arduino IDE is the programming system that you download to your PC so you can program your Arduino.

...R

So must I delete my first loop? But where do I put the const int and float? If I just suprimme my loop I have the same error message below.

The error message:

Arduino : 1.8.6 (Windows 10), Carte : "Arduino/Genuino Uno"

C:\Users\Utilisateur\Documents\Arduino\temperature\temperature.ino: In function 'void setup()':

temperature:15:13: error: a function-definition is not allowed here before '{' token

void loop(){

^

temperature:55:3: error: expected '}' at end of input

}

^

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

My code: < // put your main code here, to run repeatedly:
const int sensorPin = A0;
const float baselineTemp = 20.0;

void setup (){
Serial.begin(9600); // ouvrir un port serie
for(int pinNumber = 2; pinNumber<5; pinNumber++){
pinMode(pinNumber, OUTPUT);
digitalWrite(pinNumber, LOW);

}
void loop(){
int sensorVal = analogRead(sensorPin);
Serial.print("Valeur Capteur :");
Serial.print(sensorVal);
// convertir la lecture du CAN EN TENSION
float voltage = ( sensorVal/1024.0) * 5.0;
Serial.print (",Volts :").
Serial.print(voltage);
Serial.print(",degres C : ");
// convertir la tension en temperature en degres
float temperature =(voltage - .5) *100;
Serial.println(temperature)
if(temperature < baselineTemp){
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
}else if(temperature >= baselineTemp+2 &&
temperature < baselineTemp+4){
digitalWrite(2, HIGHT);
digitalWrite(3, LOW);
digitalWrite(4, LOW);

}else if(temperature >= baselineTemp+4 &&
temperature < baselineTemp+6){
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);

}else if(temperature >= baselineTemp+6{
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);

}
delay(1);

} >

Thank you so much !

Your setup function is missing one of these }

Could you tell me where please ?

And I have attached to you photos of my code copied from the official manual of arduino, it does not specify that I must put above const int and float.

And also I'm sorry I can not post pictures of the manual but know that this is the manual K020007
Thanks

Juju14a:
Could you tell me where please ?

At the end of the setup function, before the loop function.

Thank you but now I have this:

Arduino : 1.8.6 (Windows 10), Carte : "Arduino/Genuino Uno"

C:\Users\Utilisateur\Documents\Arduino\temperature\temperature.ino: In function 'void loop()':

temperature:43:49: error: expected ')' before '{' token

} else if(temperature >= baselineTemp+6{

^

exit status 1
expected ')' before '{' token
.

I thought I understood so I put a parenthesis but it did not work, what should I do?

You should post your code.

Juju14a:
what should I do?

You should read the error message.

temperature:43:49: error: expected ')' before '{' token

          } else if(temperature >= baselineTemp+6{

Where is the {?
Is there a ) right before it?

< // put your main code here, to run repeatedly:
const int sensorPin = A0;
const float baselineTemp = 20.0;

void setup (){
Serial.begin(9600); // ouvrir un port serie
for(int pinNumber = 2; pinNumber<5; pinNumber++){
pinMode(pinNumber, OUTPUT);
digitalWrite(pinNumber, LOW);

} }
void loop(){
int sensorVal = analogRead(sensorPin);
Serial.print("Valeur Capteur :");
Serial.print(sensorVal);
// convertir la lecture du CAN EN TENSION
float voltage = ( sensorVal/1024.0) * 5.0;
Serial.print (",Volts :");
Serial.print(voltage);
Serial.print(",degres C : ");
// convertir la tension en temperature en degres
float temperature =(voltage - .5) *100;
Serial.println(temperature);
if(temperature < baselineTemp){
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
}else if(temperature >= baselineTemp+2 &&
temperature < baselineTemp+4){
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);

}else if(temperature >= baselineTemp+4 &&
temperature < baselineTemp+6){
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);

} else if(temperature >= baselineTemp+6{
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);

}
delay(1);

}>

Put each { on a line by itself.
Put each } on a line by itself.

Get rid of all extra lines with nothing in them.

Press Ctrl+T, or select Tools -> Auto Format

And again, where is the {, is there a ) right before it?

} else if(temperature >= baselineTemp+6{

You've done it right in several other places so just do this one the same as the others. Not having correctly paired brackets/braces/parentheses is one of the most common (and easy to solve) problems.

Steve

I tried to do what you told me, I have less error message but I still have this one:

Arduino : 1.8.6 (Windows 10), Carte : "Arduino/Genuino Uno"

temperature:6:1: error: expected unqualified-id before '{' token

{

^

exit status 1
expected unqualified-id before '{' token

My code :

// put your main code here, to run repeatedly:
const int sensorPin = A0;
const float baselineTemp = 20.0;
{
void setup ()
Serial.begin(9600); // ouvrir un port serie
for (int pinNumber = 2; pinNumber < 5; pinNumber++) {
pinMode(pinNumber, OUTPUT);
digitalWrite(pinNumber, LOW);
}
}
void loop()
{
int sensorVal = analogRead(sensorPin);
Serial.print("Valeur Capteur :");
Serial.print(sensorVal);
// convertir la lecture du CAN EN TENSION
float voltage = ( sensorVal / 1024.0) * 5.0;
Serial.print (",Volts :");
Serial.print(voltage);
Serial.print(",degres C : ");
// convertir la tension en temperature en degres
float temperature = (voltage - .5) * 100;
Serial.println(temperature);
if (temperature < baselineTemp) {
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}
else if (temperature >= baselineTemp + 2 &&
temperature < baselineTemp + 4) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}
else if (temperature >= baselineTemp + 4 &&
temperature < baselineTemp + 6) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}
else if (temperature >= baselineTemp + 6{
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
}
delay(1);
}

Thank you so much !