Pages: [1]   Go Down
Author Topic: 2 or more Flow Sensors  (Read 605 times)
0 Members and 1 Guest are viewing this topic.
Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

This is my second project and now i have 6 Flow Sensors. (this one: http://www.seeedstudio.com/depot/g12-water-flow-sensor-p-635.html?cPath=144_151)

I have de following code:

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

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
}
// 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
}

##--------------------------------------------------------------------------

But how can i use 2 (or more) flow sensors?
I tried to 'copy' the code and replace the vars, but i always get the value of the first flow-sensor.

Can anyone help me please?

Thanks!!!! smiley





Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

you can have two interrupts directly on pin 2 and 3 (now you are using pin2 == iirq0

To extend it to multiple (>2) irq's you need to read - http://www.arduino.cc/playground/Main/PinChangeInt -

With the pinChangeinterrupt you can monitor multiple IO lines for changes. But all 8 will call the same function so your IRQ function has to find out who "pulled the trigger".

succes,
rob





Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello Rob,

Thanks for your replay.
Can you gave me an example code?

I read your linked-page, but it looks like !@&#*!@^# for me  smiley-mr-green

Thank you!
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Thanks for your replay.
Can you gave me an example code?

seen this one? - http://arduino.cc/playground/Main/PinChangeIntExample -

It is not trivial so it might take your some time to learn ...
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: