expected unqualified id before if

I have tried with my limited ability to get this error solved but i am beat. :cold_sweat:

What i am trying to do is monitor the hall sensor and if the flow is below 2l/hr then switch the output to low. The if statement is what is troubling me

any help would be much appreciated

// reading liquid flow rate using Seeeduino and Water Flow Sensor from Seeedstudio.com // Code adapted by Charles Gantt from PC Fan RPM code written by Crenn @thebestcasescenario.com // http:/themakersworkbench.com http://thebestcasescenario.com http://seeedstudio.com

volatile int NbTopsFan; //measuring the rising edges of the signal int Calc; int hallsensor = 2; //The pin location of the sensor int ledPin = 13;

void rpm () //This is the function that the interupt calls { NbTopsFan++; //This function measures the rising and falling edge of the hall effect sensors signal } // The setup() method runs once, when the sketch starts void setup() // { pinMode(hallsensor, INPUT); //initializes digital pin 2 as an input Serial.begin(9600); //This is the setup function where the serial port is initialised, attachInterrupt(0, rpm, RISING); //and the interrupt is attached pinMode (ledPin, OUTPUT); } // the loop() method runs over and over again, // as long as the Arduino has power void loop ()

{ NbTopsFan = 0; //Set NbTops to 0 ready for calculations sei(); //Enables interrupts delay (1000); //Wait 1 second cli(); //Disable interrupts

Calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate in L/hour Serial.print (Calc, DEC); //Prints the number calculated above Serial.print (" L/hour\r\n"); //Prints "L/hour" and returns a new line }

if (Calc = >2) { digitalWrite(ledPin, LOW);

}

void loop () 

{
  NbTopsFan = 0;   //Set NbTops to 0 ready for calculations
  sei();      //Enables interrupts
  delay (1000);   //Wait 1 second
  cli();      //Disable interrupts
   
  Calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate in L/hour 
  Serial.print (Calc, DEC); //Prints the number calculated above
  Serial.print (" L/hour\r\n"); //Prints "L/hour" and returns a  new line

  if (Calc >= 2)
  {
  digitalWrite(ledPin, LOW); 
  }
}

You've given the corrected code, but care to actually tell the OP what the problem was, and why, and how to avoid it in the future? How else will he learn?

majenko: You've given the corrected code, but care to actually tell the OP what the problem was, and why, and how to avoid it in the future? How else will he learn?

Figured I'd let him ask, if it's not apparent.

The Problem: It's... the braces. For every left brace there must be a right brace. How to Avoid It: When you start nesting, [u]indent[/u] and keep your braces in place - mind your formatting.

Even better, when you type the left brace create a blank line and type the right brace straight away, then fill in the commands in the braces. Use Auto Format frequently to keep things tidy and to warn of mismatched braces and brackets.

Add to that Serial will NOT work with interrupts disabled.

Thanks guys for your help and support, i am learning slowly.

UKHeliBob:
Even better, when you type the left brace create a blank line and type the right brace straight away, then fill in the commands in the braces. Use Auto Format frequently to keep things tidy and to warn of mismatched braces and brackets.

I use the same technique for any symbol that needs a close. Whether that is parentheses, quotation marks, or code and quote tags here on this forum. An excellent habit to form. :smiley:

An excellent habit to form

I second that. C# and Objective C even supply the closing } for you, so you can't get it in the wrong place. At least without extra effort.

PaulS:

An excellent habit to form

I second that. C# and Objective C even supply the closing } for you, so you can't get it in the wrong place. At least without extra effort.

One of the IDEs I use does that to me. I keep ending up with extra } all over the place...

One of the IDEs I use does that to me. I keep ending up with extra } all over the place...

I'm not the only one, huh? Takes a while to get used to the "help".