1o Flowsensor with Mega 2560

Hi,

I have to check 10 Flowsensors with my Arduino Mega.
I dont't know how to manage all the 10.
I tried it with one Sensor and it worked perfect.
I've read, that the Mega has 6 Interrupts.
But I think I need 10. Is there another possibility to read the Flow of the Sensor without interrupts?

Thanks

Klotzi

Which sensor?

The Mega has pin-change interrupts on every pin but they are a little more work than the simple 'external' interrupts.

Show your code. Use [ code ] tags please.

Hi, Thanks for your response. Sorry for the delay. I was a littlebit busy with the kid’s.

Here’s my code for now:

#define FLOWSENSORPIN 2
//int FLOWSENSORPIN[2] {2,3};
int PUMPE[1] = {12};
volatile uint16_t pulses = 0;
volatile uint8_t lastflowpinstate;
volatile uint32_t lastflowratetimer = 0;
volatile float flowrate;
int cocktail[10]={60,55,50,45,40,35,30,25,10,5};
int c_pumpe=0;
int phase = 0;

SIGNAL(TIMER0_COMPA_vect) {
  uint8_t x = digitalRead(FLOWSENSORPIN);
  if (x == lastflowpinstate) {
    lastflowratetimer++;
    return; // nothing changed!
  }
  if (x == HIGH) {pulses++;}  
  lastflowpinstate = x;
  flowrate = 1000.0;
  flowrate /= lastflowratetimer;  // in hertz
  lastflowratetimer = 0;
}

void useInterrupt(boolean v) {
  if (v) {
    OCR0A = 0xAF;
    TIMSK0 |= _BV(OCIE0A);
  } else {
    TIMSK0 &= ~_BV(OCIE0A);
  }
}

void setup() {
   pinMode(PUMPE[0], OUTPUT);
   Serial.begin(9600);
   Serial.print("Scheißtest");
   pinMode(FLOWSENSORPIN, INPUT);
   digitalWrite(FLOWSENSORPIN, HIGH);
   lastflowpinstate = digitalRead(FLOWSENSORPIN);
   useInterrupt(true);
}
// 460 Pulse = 100ml
// 230 Pulse = 50ml
// 184 Pulse = 40ml
// 138 Pulse = 30ml
// 115 Pulse = 25ml
// 92 Pulse = 20ml/2cl
// 46 Pulse = 10ml/1cl
// 23 Pulse = 5ml
void loop()                     // run over and over again
{ 
  if (phase<4) {
    if (pulses<(cocktail[phase]/5*23)) {
      digitalWrite(PUMPE[c_pumpe], LOW); // RELAIS anschalten
      Serial.print(pulses);
      Serial.print(" < ");
      Serial.print(cocktail[phase]/5*23);
      Serial.print(" (");
      Serial.print(cocktail[phase]);
      Serial.print("ml)");
      Serial.println();
    }
    else {digitalWrite(PUMPE[c_pumpe], HIGH);
      delay(1000);
      pulses=0;phase++;
    }
  }
}

at this moment i use only one Pump for checking, if everything works. and it does. but now i get stuck. It Pumps 10 Times (int cocktail) with a break of 1 Second. First 60ml, then 55ml and so on.
Now I want to use 10 different Pumps. 60ml through the first pump, 55ml through the second, and so on. Maybe at the same time, but it’s not important, so it can be 1 after 1.
i use the pumps with a relay board. their name is:
12V 1.6A Diaphragm pump 545
and the flowsensors like this one:
Flowsensor

Thanks for your interest and help

Klotzi

MorganS:
The Mega has pin-change interrupts on every pin but they are a little more work than the simple 'external' interrupts.

The Mega only has pin change interrupts on pins 10--15,50--53 and A8--A15

There are only 3 ports supporting pin change interrupts, which is enough for every pin on the Uno,
but not at all for the Mega.

Alright, so maybe I can solve this Problem with an Arduino Due?