expected unqualified-id before numeric constant !!!

Hello Cmmunity,

This is my first post cause I can't find solution to my problem !

Some syntax problem with the if cause Arduino say me :

expected unqualified-id before numeric constant

This is my code :

const int pingPin = 7;
const int WaterPin=7;//Pour détecter l'eau
const int pompe=12;//Pour controller la pompe


void setup() {

  Serial.begin(9600);
  pinMode(pompe,OUTPUT);
  
  
}

void loop()
{

  long duration, cm;
  



  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);

  pinMode(pingPin, INPUT);
  duration = pulseIn(pingPin, HIGH);

  cm = microsecondsToCentimeters(duration);
  
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
  
  delay(100);
}


long microsecondsToCentimeters(long microseconds)
{
  
  return microseconds / 29 / 2;
}


    if (cm <= 5)  {  
    // On allume la pompe   
    digitalWrite(pompe, HIGH);  
  } else if (cm >= 15) {
    // On éteint la pompe
    digitalWrite(pompe, LOW); 
  }  else   {
    digitalWrite(pompe, LOW); 
}

Thanks a lot !

Raphael.

    if (cm <= 5)  {  
    // On allume la pompe   
    digitalWrite(pompe, HIGH);  
  } else if (cm >= 15) {
    // On éteint la pompe
    digitalWrite(pompe, LOW); 
  }  else   {
    digitalWrite(pompe, LOW); 
}

Is that code meant to be in loop?

Yes !

I just beggin...

raphael753:
I just beggin...

I don't understand. Does that mean you need more help?

No that's good !

Thanks a lot !

So now you know keeping good indentation can actually solve or avoid problems :slight_smile:

Just remember the magic keys: CTRL+T