"does not name a type" issue

Hi, I'm using an arduino mega, and when I want to upload my program it's says, "serial does not name a type" but i don't understand i have the good librairies ... And at first it was working well..
if someone has an idea about what could have happened ?

Here is my program:

#include <LiquidCrystal.h>

#include <LiquidCrystal_I2C.h>

#include <SoftwareSerial.h>

#define PIN_TX 10  
#define PIN_RX 11

//initialisation des valeurs recupérées toutes les 5MIN
const int capteur = A9 ;
int valeur = 0 ;
float temp;
const int capteur2 = A13 ;
int valeur2 = 0;
float hum;

//initialisation des min max moy 1=temperature
float min1;
float max1;
float somme_valeurs1 = 0.0;
int nbr_valeurs1 = 0 ;
float moytotale1;

//initialisation des min max moy 2=humidité
float min2;
float max2;
float somme_valeurs2 = 0.0;
int nbr_valeurs2 = 0 ;
float moytotale2;

SoftwareSerial mySerial(PIN_TX,PIN_RX);


void setup() {
  // put your setup code here, to run once:
  mySerial.begin(9600);
  Serial.begin(9600);
  delay(1000); 
  //initialisation de premiere valeur du minimum et maximum temperature
  valeur = analogRead(capteur);
  temp = valeur * 5.0 /100;
  min1 = temp;
  max1 = temp;

  //initialisation de premiere valeur du minimum et maximum humidité
  valeur2 = analogRead(capteur2);
  hum = valeur2 * 50/ 5.38 /100;
  min2 = hum;
  max2 = hum;
}
void loop() {
  // put your main code here, to run repeatedly:
 
  //delay(30000); //5min
    //TEMPERATURE
    valeur = analogRead(capteur);
    // conversion temp de la valeur lue en degres
    temp = valeur * 5.0 /100;
    Serial.println("la temperature est de:");
    Serial.println(temp);
    //minimum temperature
    if (temp < min1){
      min1 = temp;
    }
    //maximum temperature
    if (temp > max1){
      max1 = temp;
    }
    //accumulation des valeurs pour le calcul de la moyenne des valeurs de temperature en fin de boucle
    nbr_valeurs1 += 1;
    somme_valeurs1 += temp;
    
    //HUMIDITE
     valeur2 = analogRead(capteur2);
    // conversion humidité valeur en pourcentage
    hum = valeur2 * 50/ 5.38 /100 ;
    Serial.println("l'humidité est de:");
    Serial.println(hum);
    //minimum humidité
    if (hum < min2){
      min2 = hum;
    }
    //maximum humidité
    if (hum > max2){
      max2 = hum;
    }
    //accumulation des valeurs pour le calcul de la moyenne des valeurs d'humidité en fin de boucle
    nbr_valeurs2 += 1;
    somme_valeurs2 += hum;
    delay(2000);
  }  
  Serial.println("la temperature minimum est de :");
  Serial.println(min1);
  Serial.println("la temperature maximum est de :");
  Serial.println(max1);
  Serial.println("l'humidité minimum est de :");
  Serial.println(min2);
  Serial.println("l'humidité maximum est de :");
  Serial.println(max2);
  
  //Calcul des moyennes à la fin de la journée
  moytotale1 = somme_valeurs1 / nbr_valeurs1;
  Serial.println("la temperature moyenne est de:");
  Serial.println(moytotale1);
  moytotale2 = somme_valeurs2 / nbr_valeurs2;
  Serial.println("l'humidité moyenne est de:");
  Serial.println(moytotale2);
}

there is a closing brace preceding that line.

the compiler is expecting a function definition and return type

Thanks for your response. Well I've changed it and it still the same problem, I don't think it came from there..

#include <SoftwareSerial.h>

#include <SoftwareSerial.h>
#define PIN_TX 10  
#define PIN_RX 11

//initialisation des valeurs recupérées toutes les 5MIN
const int capteur = A9 ;
int valeur = 0 ;
float temp;
const int capteur2 = A13 ;
int valeur2 = 0;
float hum;

//initialisation des min max moy 1=temperature
float min1;
float max1;



//initialisation des min max moy 2=humidité
float min2;
float max2;



SoftwareSerial mySerial(PIN_TX,PIN_RX);

void setup() {
  // put your setup code here, to run once:
  mySerial.begin(9600);
  Serial.begin(9600);
  delay(1000); 
  //initialisation de premiere valeur du minimum et maximum temperature
  valeur = analogRead(capteur);
  temp = valeur * 5.0 /100;
  min1 = temp;
  max1 = temp;

  //initialisation de premiere valeur du minimum et maximum humidité
  valeur2 = analogRead(capteur2);
  hum = valeur2 * 50/ 5.38 /100;
  min2 = hum;
  max2 = hum;
}
void loop() {
  // put your main code here, to run repeatedly:
 
  //delay(30000); //5min
    //TEMPERATURE
    valeur = analogRead(capteur);
    // conversion temp de la valeur lue en degres
    temp = valeur * 5.0 /100;
    Serial.println("la temperature est de:");
    Serial.println(temp);
    //minimum temperature
    if (temp < min1){
      min1 = temp;
    }
    //maximum temperature
    if (temp > max1){
      max1 = temp;
    }
    //accumulation des valeurs pour le calcul de la moyenne des valeurs de temperature en fin de boucle
    float somme_valeurs1 = 0.0;
    int nbr_valeurs1 = 0 ;
    nbr_valeurs1 += 1;
    somme_valeurs1 += temp;
    
    //HUMIDITE
     valeur2 = analogRead(capteur2);
    // conversion humidité valeur en pourcentage
    hum = valeur2 * 50/ 5.38 /100 ;
    Serial.println("l'humidité est de:");
    Serial.println(hum);
    //minimum humidité
    if (hum < min2){
      min2 = hum;
    }
    //maximum humidité
    if (hum > max2){
      max2 = hum;
    }
    
    //accumulation des valeurs pour le calcul de la moyenne des valeurs d'humidité en fin de boucle
    float somme_valeurs2 = 0.0;
    int nbr_valeurs2 = 0 ;
    nbr_valeurs2 += 1;
    somme_valeurs2 += hum;
    delay(2000);
  }  
  Serial.println("la temperature minimum est de :");
  Serial.println(min1);
  Serial.println("la temperature maximum est de :");
  Serial.println(max1);
  Serial.println("l'humidité minimum est de :");
  Serial.println(min2);
  Serial.println("l'humidité maximum est de :");
  Serial.println(max2);
  
  //Calcul des moyennes à la fin de la journée*
  float moytotale1;
  moytotale1 = somme_valeurs1 / nbr_valeurs1;
  Serial.println("la temperature moyenne est de:");
  Serial.println(moytotale1);
  float moytotale2;
  moytotale2 = somme_valeurs2 / nbr_valeurs2;
  Serial.println("l'humidité moyenne est de:");
  Serial.println(moytotale2);

Post the COMPLETE error message. Copy / paste it verbatim. Don't give us your interpretation of it.

sketch_jul08a:92:3: error: 'Serial' does not name a type
   Serial.println("la temperature minimum est de :");
   ^~~~~~
sketch_jul08a:93:3: error: 'Serial' does not name a type
   Serial.println(min1);
   ^~~~~~
sketch_jul08a:94:3: error: 'Serial' does not name a type
   Serial.println("la temperature maximum est de :");
   ^~~~~~
sketch_jul08a:95:3: error: 'Serial' does not name a type
   Serial.println(max1);
   ^~~~~~
sketch_jul08a:96:3: error: 'Serial' does not name a type
   Serial.println("l'humidité minimum est de :");
   ^~~~~~
sketch_jul08a:97:3: error: 'Serial' does not name a type
   Serial.println(min2);
   ^~~~~~
sketch_jul08a:98:3: error: 'Serial' does not name a type
   Serial.println("l'humidité maximum est de :");
   ^~~~~~
sketch_jul08a:99:3: error: 'Serial' does not name a type
   Serial.println(max2);
   ^~~~~~
sketch_jul08a:103:3: error: 'moytotale1' does not name a type
   moytotale1 = somme_valeurs1 / nbr_valeurs1;
   ^~~~~~~~~~
sketch_jul08a:104:3: error: 'Serial' does not name a type
   Serial.println("la temperature moyenne est de:");
   ^~~~~~
sketch_jul08a:105:3: error: 'Serial' does not name a type
   Serial.println(moytotale1);
   ^~~~~~
sketch_jul08a:107:3: error: 'moytotale2' does not name a type
   moytotale2 = somme_valeurs2 / nbr_valeurs2;
   ^~~~~~~~~~
sketch_jul08a:108:3: error: 'Serial' does not name a type
   Serial.println("l'humidité moyenne est de:");
   ^~~~~~
sketch_jul08a:109:3: error: 'Serial' does not name a type
   Serial.println(moytotale2);
   ^~~~~~
exit status 1
'Serial' does not name a type

further down, same problem (may not be last)

    somme_valeurs2 += hum;
    delay(2000);
}
Serial.println("la temperature minimum est de :");
Serial.println(min1);

yeah thank you, but I don't have any function definition to make anymore, I just want it to print the results.. This is where I don't undersand what I shall do

when do you want to print?

When the loop is over

All code has to be inside a function. Only declarations can be at top-level in the file.

If you used auto-format on the first version you posted you'd have seen where the rogue } was.

do you mean a the end of loop?
id so why not include it at the end of loop()?

So I just have to put the rogue at the end, for it to be included in a function?

yeah
??

owww I must be really tired, just as simple as that.. sorry about that, thank you haha!

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