Water Flow Sensor Problem

hi everyone,

i have a problem to read 3 different water flow sensors. i did something wrong in my program but i don´t know where is the mistake. may someone can help me

volatile int flow_frequency1;
volatile int flow_frequency2;
volatile int flow_frequency3;
unsigned int l_min1;
unsigned int l_min2;
unsigned int l_min3;
unsigned char flowmeter1 = 2;
unsigned char flowmeter2 = 3;
unsigned char flowmeter3 = 4;
unsigned long currentTime;
unsigned long cloopTime;

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);

void flow ()
{
flow_frequency1++;
flow_frequency2++;
flow_frequency3++;
}

void setup()
{
pinMode (flowmeter1, INPUT);
pinMode (flowmeter2, INPUT);
pinMode (flowmeter3, INPUT);
Serial.begin (9600);
attachInterrupt (0, flow, RISING);

sei();
currentTime = millis();
cloopTime = currentTime;

lcd.init();
lcd.backlight();

}

void loop()
{
currentTime = millis();
if (currentTime >= (cloopTime + 500))
{
cloopTime = currentTime;
l_min1 = (flow_frequency1 / 7.5 );
l_min2 = (flow_frequency2 / 7.5 );
l_min3 = (flow_frequency3 / 7.5 );
flow_frequency1 = 0;
flow_frequency2 = 0;
flow_frequency3 = 0;
Serial.print (l_min1, DEC);
Serial.print (" L/min");
Serial.print (l_min2, DEC);
Serial.print (" L/min");
Serial.print (l_min3, DEC);
Serial.print (" L/min");

lcd.setCursor (0,0);
lcd.print (" Jacob GmbH ");
lcd.setCursor (0,1);
lcd.print (" Temp 1: ");
lcd.print (l_min1);
lcd.print (" L/min");
lcd.setCursor (0,2);
lcd.print (" Temp 2: ");
lcd.print (l_min2);
lcd.print (" L/min");
lcd.setCursor (0,3);
lcd.print (" Temp 3: ");
lcd.print (l_min3);
lcd.print (" L/min");
delay (5000);
lcd.clear ();
}

}

only the first sensor is working.
thanks for the help

so you mean it should be like this?

void flow  ()
{
  flow_frequency1++;
    }
void flow2  ()
{
  flow_frequency2++;
    }
void flow3  ()
{
  flow_frequency3++;
    }
   


void setup() 
{
  pinMode (flowmeter1, INPUT);
  pinMode (flowmeter2, INPUT);
  pinMode (flowmeter3, INPUT);
  Serial.begin (9600);
  attachInterrupt (0, flow, RISING);
  attachInterrupt (0, flow2, RISING);
  attachInterrupt (0, flow3, RISING);

im sorry i just started to write programs

yes its an UNO.
i totaly have no idea how i can solve that. I will google the pin change function.

Thanks for your help :slight_smile:

ok i don´t have a glue how it works.

i cant help myself -.-

thank you for the link, i hope it will help me :slight_smile:

Also, when you use a LCD, like you are using, display the constant values ONE time at the beginning. Then check each variable you are displaying to see if is different from the last time you displayed it. If different, display a blank where the variable will go, then display the variable and save the new value for the next display time. Use the LCD cursor control to position the cursor to the beginning of the the display field.

LCD display takes a long time to do.

Paul

When you review the Gammon tutorial and become more familiar with interrupts you may want to use a library for pin change interrupts rather than write your own at the timer level.

I would take a look at Nico Hood's PinChangeInterrupt library available through the library manager. The syntax is analogous to the external interrupts so its easy and familiar.

attachInterrupt(digitalPinToInterrupt(pin), ISR, mode);
attachPCINT(digitalPinToPCINT(pin), ISR, mode);