invalid conversion from 'int' to 'void'

Hi…I’m new to arduino…i want to developed an automatic valve using a servo motor that will react upon a flow sensor… but my problem is when I want to verify the code, it keep saying “invalid conversion from ‘int’ to ‘void’” at line -attachInterrupt(0, rpm, RISING); //and the interrupt is attached-

#include <Servo.h>

Servo myservo;
volatile int NbTopsFan; //measuring the rising edges of the signal
int Calc;  
int potPin = 0; //analog pin ued to connect the sensor
int ledPin = 9;  //select pin for the servo
int val = 0;  //variable to read the value from the analog pin
int rpm;   //This is the function that the interupt calls 
void setup()
{
  NbTopsFan++;  //This function measures the rising and falling edge of the 
{
  myservo.attach(9); //set up the servo as usual

  pinMode(ledPin, OUTPUT);  //variable to store the value coming from the sensor
  pinMode(potPin, INPUT); //initializes digital pin 0 as an input
  Serial.begin(9600); //for watching the speeds in the serial monitor
  attachInterrupt(0, rpm, RISING); //and the interrupt is attached
}
void loop(){
  NbTopsFan = 0;      //Set NbTops to 0 ready for calculations
  sei();            //Enables interrupts
 val = analogRead(potPin);    // read the value from the sensor
  val = map(val,0,1023,0,179);
  cli();            //Disable interrupts
  Calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate 
   if (val>79) myservo.writeMicroseconds(0);  //set servo to mid-point
  
   else if (val<80) myservo.writeMicroseconds(1500);  
 
  Serial.print (Calc, DEC); //Prints the number calculated above
  Serial.print (" L/hour\r\n"); //Prints "L/hour" and returns a  new line
  Serial.println(val);
 delay(10); 

}

please someone help me…thank you very much

You don't have a function called rpm for the interrupt to call, you have a variable called rpm

int rpm;   //This is the function that the interupt calls

No it isn't - it's an integer variable that can store between -32768 and 32767.

Your curly braces are also mis-nested - you need to indent your code properly to make it readable.

thank you.. so what is the problem with this line? since its highlighted.. i still don't get it..

attachInterrupt(0, rpm, RISING); //and the interrupt is attached-

what its relation to this line:-

int rpm;   //This is the function that the interupt calls

(in case if I have change the word 'function' to 'variable')

MarkT: Your curly braces are also mis-nested - you need to indent your code properly to make it readable.

sorry Markt.. can you show me where the code I need to indent? sorry..still learning..

ijultohid: sorry Markt.. can you show me where the code I need to indent? sorry..still learning..

In the Arduino IDE, press Ctrl+T

sketch_may03a.ino: In function 'void setup()': sketch_may03a:19: error: invalid conversion from 'int' to 'void ()()' sketch_may03a:19: error: initializing argument 2 of 'void attachInterrupt(uint8_t, void ()(), int)' sketch_may03a:22: error: a function-definition is not allowed here before '{' token sketch_may03a:39: error: expected `}' at end of input

These messages show my error..really dont know how to edit the code..

ijultohid: sketch_may03a.ino: In function 'void setup()': sketch_may03a:19: error: invalid conversion from 'int' to 'void ()()' sketch_may03a:19: error: initializing argument 2 of 'void attachInterrupt(uint8_t, void ()(), int)' sketch_may03a:22: error: a function-definition is not allowed here before '{' token sketch_may03a:39: error: expected `}' at end of input

These messages show my error..really dont know how to edit the code..

Each left curly brace should have a corresponding right curly brace.

Arrch:

ijultohid: sketch_may03a.ino: In function 'void setup()': sketch_may03a:19: error: invalid conversion from 'int' to 'void ()()' sketch_may03a:19: error: initializing argument 2 of 'void attachInterrupt(uint8_t, void ()(), int)' sketch_may03a:22: error: a function-definition is not allowed here before '{' token sketch_may03a:39: error: expected `}' at end of input

These messages show my error..really dont know how to edit the code..

Each left curly brace should have a corresponding right curly brace.

you mean every '{' must be pair with this code '}' also right?

This is my code after editing, i have change the int to void for the rpm

void rpm()   //integer function that can store between -32768 and 32767.

this is my full code

#include <Servo.h>

Servo myservo;
volatile int NbTopsFan; //measuring the rising edges of the signal
int Calc;  
int potPin = 0; //analog pin ued to connect the sensor
int ledPin = 9;  //select pin for the servo
int val = 0;  //variable to read the value from the analog pin
void rpm()   //integer function that can store between -32768 and 32767.

{
  NbTopsFan++;  //This function measures the rising and falling edge of the 
}
{
  myservo.attach(9); //set up the servo as usual

  pinMode(ledPin, OUTPUT);  //variable to store the value coming from the sensor
  pinMode(potPin, INPUT); //initializes digital pin 0 as an input
  Serial.begin(9600); //for watching the speeds in the serial monitor
  attachInterrupt(0, rpm, RISING); //and the interrupt is attached
}
void loop()
{
  NbTopsFan = 0;      //Set NbTops to 0 ready for calculations
  sei();            //Enables interrupts
  val = analogRead(potPin);    // read the value from the sensor
  val = map(val,0,1023,0,179);
  cli();            //Disable interrupts
  Calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate 
   
   if (val>79) myservo.writeMicroseconds(0);  //set servo to mid-point
  
   else if (val<80) myservo.writeMicroseconds(1500);  
 
  Serial.print (Calc, DEC); //Prints the number calculated above
  Serial.print (" L/hour\r\n"); //Prints "L/hour" and returns a  new line
  Serial.println(val);
 delay(10); 

}

BUT I still got this error message at this line,

{
  NbTopsFan++;  //This function measures the rising and falling edge of the 
}
{

it says
sketch_may03a:14: error: expected unqualified-id before ‘{’ token

hmm…how do i fix this error?

ijultohid: hmm...how do i fix this error?

See my previous post.

I think you've dived in a bit too deep, too soon with this project.

Interrupts and functions should be "phase II" of your Arduino journey if you are, as you say, new to this.

Phase I ought to be the core learning examples here and then have a look at functions

As Jimbo says, you may have dived in too deep but you can fix the code. First I suggest that you move the rpm function to the very end of your code as the current layout is confusing both to read and to the compiler.

void rpm()   //integer function that can store between -32768 and 32767.
{
  NbTopsFan++;  //This function measures the rising and falling edge of the 
}

The comments are wrong but that won't affect operation of the program.

Once you have done that you will see more easily that you have no setup() function. Well, you have the code for it but no function name. Add the function name and the code will compile. Whether or not it works or does what you want I do not know.

Helo guys…thanks for the help before this…
this is my code after editing and it seems doesnt have any error

#include <Servo.h>

Servo myservo;
volatile int NbTopsFan; //measuring the rising edges of the signal
int Calc;                               
int hallsensor = 0;    //analogue pin of the sensor
int ledPin = 9;  //select pin for the servo

int val = 0;  //variable to read the value from the analog pin
void rpm()
{
  NbTopsFan++;  //This function measures the rising and falling edge of the 
  
}
void setup()
{
 
  myservo.attach(9); //set up the servo as usual
  
   
  pinMode(hallsensor, INPUT); //initializes digital pin 0 as an input
  pinMode(ledPin, OUTPUT);  //variable to store the value coming from the sensor
  Serial.begin(9600); //for watching the speeds in the serial monitor
  attachInterrupt(0, rpm, RISING); //and the interrupt is attached
}

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 
  val = analogRead(hallsensor); // read the value from sensor
  val = map(val,0,1023,0,179);
  if (val>79)myservo.writeMicroseconds(0);  //set servo to mid-point
  
  else if (val<80)myservo.writeMicroseconds(1500);
  
  Serial.print (Calc, DEC); //Prints the number calculated above
  Serial.println(val);
  Serial.print (" L/hour\r\n"); //Prints "L/hour" and returns a  new line
 delay(10); 
}

BUT I still got one problem, why the when I open the serial monitor there are no value for the ‘L/hour’ although I had write the

 Serial.print (Calc, DEC); //Prints the number calculated above

and

Serial.print (" L/hour\r\n"); //Prints "L/hour" and returns a  new line

the serial monitor just look like this:
( Here I attach the serial monitor pic)

Is this the suitable code? any suggestion on what the suitable code for me if I want to control the servo motor degree of rotation due to the flow rate calculate by the flow sensor…

SERIAL MONITOR.PNG

Try printing a marker character like [ before printing the value and another such as ] after the value so that you can see whether anything is being printed at all for the value. Is there a reason why you do not use Serial.println() to print a linefeed after " L/hour" ?

Incidentally, Calc is defined as an int as is NbTopsFan so when you do Calc = (NbTopsFan * 60 / 7.5) you will get an integer as the answer. This may not matter but you should be aware of it.

UKHeliBob: Try printing a marker character like [ before printing the value and another such as ] after the value so that you can see whether anything is being printed at all for the value. Is there a reason why you do not use Serial.println() to print a linefeed after " L/hour" ?

Incidentally, Calc is defined as an int as is NbTopsFan so when you do Calc = (NbTopsFan * 60 / 7.5) you will get an integer as the answer. This may not matter but you should be aware of it.

thanks my friend.. but i still dont understand what is your mean by "Try printing a marker character like [ before printing the value and another such as ] after the value so that you can see whether anything is being printed at all for the value."

sorry..can you give an example?

can you give an example?

char *crap = "This is a message";

Serial.print("crap = [");
Serial.print(crap);
Serial.println("]");