I need help... four flow meter to arduino mega.

Hi,

excuse my bad English tongue. try to take.

Problem is… I’m trying to get a four-pulse flow meter data arduino mega.
( http://www.conrad.com/ce/en/product/150391/BIO-TECH-eK-FCH-M-POM-LC-G-18-Flow-Meter-FCH-m-POM-LC-001-35-Lmin?ref=searchDetail )

But the pulses are copied to the cross and in the wrong sensors. When E1 is the flow. E2 sensors will also receive pulses even if they do not have the flow. if turn off power the E2 sensors. then the E2 pulses disappear from the sensors. The same in reverse. Where could be the problem?

Can I get a four-sensor pulses at the same time, in the right places? or whether only two sensors at a time

I hope this may be something obvious, thanks

#include <LiquidCrystal.h>
LiquidCrystal lcd(9, 8, 7, 6, 5, 4); // 9 to lcd4 // 8 to lcd 6 // 7 to lcd 11 // 6 to lcd 12 // 5 to lcd13 // 4 to lcd 14 

//E1
#define IRQ_A 5
#define IRQ_B 4
#define FlowA 18
#define FlowB 19
//E2
#define E2IRQ_A 1
#define E2IRQ_B 0
#define E2FlowA 3
#define E2FlowB 2

unsigned long oldTime  = 0;

volatile byte pulseCountIN;
volatile byte pulseCountOUT;

volatile byte pulseCountIN2;
volatile byte pulseCountOUT2;

void setup()
  {
  Serial.begin(57600);
  lcd.begin(20, 4);
  lcd.setCursor(0, 0);
  lcd.print("                    ");
  lcd.setCursor(0, 1);
  lcd.print("                    ");
  lcd.setCursor(0, 2);
  lcd.print("                    ");
  lcd.setCursor(0, 3);
  lcd.print("                    ");
  lcd.clear();
  
  
  lcd.setCursor(0, 0);
  lcd.print("4 PULSE");
  delay(5000);
  lcd.clear();
  
  pulseCountIN   = 0; //E1 IN 
  pulseCountOUT  = 0; //E1 OUT
  pulseCountIN2  = 0; //E2 IN
  pulseCountOUT2 = 0; //E2 OUT
  
  
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  
  digitalWrite(12, HIGH); // POWER E1 Sensor
  digitalWrite(13, HIGH);  // POWER E2 sensor
  
  pinMode(FlowA, INPUT);
  pinMode(FlowB, INPUT);
  digitalWrite(FlowA, HIGH);
  digitalWrite(FlowB, HIGH);
  pinMode(E2FlowA, INPUT);
  pinMode(E2FlowB, INPUT);
  digitalWrite(E2FlowA, HIGH); 
  digitalWrite(E2FlowB, HIGH);
  
  
  attachInterrupt(IRQ_A, CounterIN, FALLING);
  attachInterrupt(IRQ_B, CounterOUT, FALLING);
  attachInterrupt(E2IRQ_A, E2CounterIN, FALLING);
  attachInterrupt(E2IRQ_B, E2CounterOUT, FALLING);
  } 



void loop() 
  {
  unsigned long now = millis();
  if((now - oldTime > 1000))
  {
  unsigned long duration = now - oldTime;
  oldTime = now; 
  
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("E1:");
  lcd.setCursor(0,1);
  lcd.print("IN:  ");
  lcd.print(pulseCountIN, DEC); //virtaus meno
  lcd.setCursor(0,2);
  lcd.print("OUT: ");
  lcd.print(pulseCountOUT, DEC); //virtaus lapuu
  lcd.setCursor(10,0);
  lcd.print("E2:");
  lcd.setCursor(10,1);
  lcd.print("IN2:  ");
  lcd.print(pulseCountIN2, DEC);
  lcd.setCursor(10,2);
  lcd.print("OUT2: ");
  lcd.print(pulseCountOUT2, DEC);
  
  pulseCountIN = 0;
  pulseCountOUT = 0;
  pulseCountIN2 = 0;
  pulseCountOUT2 = 0;
  }
  }
  
  //E1 IN
void CounterIN()
{
  pulseCountIN++;
}
  //É1 OUT
void CounterOUT()
{
  pulseCountOUT++;
}  
  //E2 IN
void E2CounterIN()
{
  pulseCountIN2++;
}
  //E2 OUT
void E2CounterOUT()
{  
  pulseCountOUT2++;
}

I use the same flow meters in one of my projects but guessing from your sketch I think you just use the internal pull-ups. They are too weak, I used external pull-ups (2k) and that works perfectly. If that doesn't help, please provide a wiring diagram, to let us see how you connected everything.

I'll try 2k resistance. If it do not work then I need to draw some sort of wiring diagram. thank you very much.

I was just wondering what happens when I put the resistor voltage. Wiring is a long flow sensors and voltage drops. (Currently 4.65 volt)

changes in the sensor NPN --> PNP. Should I change digitalWrite(FlowA, HIGH); or LOW ?

changes in the sensor NPN --> PNP. Should I change digitalWrite(FlowA, HIGH); or LOW ?

What does that mean? Did you modify the meter?

I was just wondering what happens when I put the resistor voltage. Wiring is a long flow sensors and voltage drops. (Currently 4.65 volt)

How do you power your setup? By just USB?

Great . pull-ups (2k) works. pull ups (2K ohm) to modify the flow sensor, PNP. a small change to the code also. I use a USB power source.

#include <LiquidCrystal.h>
LiquidCrystal lcd(9, 8, 7, 6, 5, 4); // 9 to lcd4 // 8 to lcd 6 // 7 to lcd 11 // 6 to lcd 12 // 5 to lcd13 // 4 to lcd 14 

//E1
#define IRQ_A 5
#define IRQ_B 4
#define FlowA 18
#define FlowB 19
//E2
#define E2IRQ_A 1
#define E2IRQ_B 0
#define E2FlowA 3
#define E2FlowB 2

unsigned long oldTime  = 0;

volatile byte pulseCountIN;
volatile byte pulseCountOUT;

volatile byte pulseCountIN2;
volatile byte pulseCountOUT2;

void setup()
  {
  Serial.begin(57600);
  lcd.begin(20, 4);
  lcd.setCursor(0, 0);
  lcd.print("                    ");
  lcd.setCursor(0, 1);
  lcd.print("                    ");
  lcd.setCursor(0, 2);
  lcd.print("                    ");
  lcd.setCursor(0, 3);
  lcd.print("                    ");
  lcd.clear();
  
  
  lcd.setCursor(0, 0);
  lcd.print("4 PULSE");
  delay(5000);
  lcd.clear();
  
  pulseCountIN   = 0; //E1 IN 
  pulseCountOUT  = 0; //E1 OUT
  pulseCountIN2  = 0; //E2 IN
  pulseCountOUT2 = 0; //E2 OUT
  
  
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  
  digitalWrite(12, HIGH); // POWER E1 Sensor
  digitalWrite(13, HIGH);  // POWER E2 sensor
  
  pinMode(FlowA, INPUT);
  pinMode(FlowB, INPUT);
  
  pinMode(E2FlowA, INPUT);
  pinMode(E2FlowB, INPUT);

  attachInterrupt(IRQ_A, CounterIN, CHANGE);
  attachInterrupt(IRQ_B, CounterOUT, CHANGE);
  attachInterrupt(E2IRQ_A, E2CounterIN, CHANGE);
  attachInterrupt(E2IRQ_B, E2CounterOUT, CHANGE);
  } 


// main code here, to run repeatedly: 
void loop() 
  {
  unsigned long now = millis();
  if((now - oldTime > 1000))
  {
  unsigned long duration = now - oldTime;
  oldTime = now; 
  
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("E1:");
  lcd.setCursor(0,1);
  lcd.print("IN:  ");
  lcd.print(pulseCountIN, DEC); //virtaus meno
  lcd.setCursor(0,2);
  lcd.print("OUT: ");
  lcd.print(pulseCountOUT, DEC); //virtaus lapuu
  lcd.setCursor(10,0);
  lcd.print("E2:");
  lcd.setCursor(10,1);
  lcd.print("IN2:  ");
  lcd.print(pulseCountIN2, DEC);
  lcd.setCursor(10,2);
  lcd.print("OUT2: ");
  lcd.print(pulseCountOUT2, DEC);
  
  Serial.println("      ");
  Serial.println("E1");
  Serial.print("IN:  ");
  Serial.println(pulseCountIN, DEC); //virtaus meno
  Serial.print("OUT: ");
  Serial.println(pulseCountOUT, DEC); //virtaus lapuu
  Serial.println("      ");
  Serial.println("E2");
  Serial.print("IN2:  ");
  Serial.println(pulseCountIN2, DEC);
  Serial.print("OUT2: ");
  Serial.println(pulseCountOUT2, DEC);
  Serial.println("      ");
  
  pulseCountIN = 0;
  pulseCountOUT = 0;
  pulseCountIN2 = 0;
  pulseCountOUT2 = 0;
  }
  }
  
  //E1 IN
void CounterIN()
{
  if (digitalRead(FlowA) == LOW)
  {
  pulseCountIN++;
  }
  if (digitalRead(FlowA) == HIGH)
  {
  }
}
  //É1 OUT
void CounterOUT()
{
  if (digitalRead(FlowB) == LOW)
  {
  pulseCountOUT++;
  }
  if (digitalRead(FlowB) == HIGH)
  {
  pulseCountOUT++;
  }
}  
  //E2 IN
void E2CounterIN()
{
  if (digitalRead(E2FlowA) == LOW)
  {
  pulseCountIN2++;
  }
  if (digitalRead(E2FlowA) == HIGH)
  {
  }
}
  //E2 OUT
void E2CounterOUT()
{  
  if (digitalRead(E2FlowB) == LOW)
  {
  pulseCountOUT2++;
  }
  if (digitalRead(E2FlowB) == HIGH)
  {
  }  
}

The situation improved considerably with resistors. I came across the following problem. the E1 sensor pulses were as follows E1 IN 0 pulses and E1 OUT 5 pulses. this after E2 sensors follows E2 in 6 pulses and E2 out 5 pulses. also shows the E1 OUT some pulses. ( ← WRONG ) but when the E1 sensor pulses were as follows E1 IN 2 pulses and E1 OUT 3 pulses. this after E2 sensors follows E2 in 6 pulses and E2 out 5 pulses. E1 OUT without pulses. ( ← OK )

how accurate must be for all four sensor pull-up resistor ? because resistors are:
E1 in 2,0K (two series-connected 0,98 )
E1 out 2,3K ( two parallel-connected 4,6 )
E2 out 2,3K ( two parallel-connected 4,6 )
E2 out 2,3K ( two parallel-connected 4,6 )

probably the best would be that everything would be the same 2K or 2,3K…

sensors must act like this:

  1. E1 only
  2. E2 only
  3. E1 and E2

a defect is found and corrected…

  //E1 OUT
void CounterOUT()
{
  if (digitalRead(FlowB) == LOW)
  {
  pulseCountOUT++;
  }
  if (digitalRead(FlowB) == HIGH)
  {
  pulseCountOUT++;       
  }
}

if (digitalRead(FlowB) == HIGH)
{
pulseCountOUT++; <— big error makes a lot of sad time… erase off this line
}

  attachInterrupt(IRQ_B, CounterOUT, CHANGE);

and

void CounterOUT()
{
  if (digitalRead(FlowB) == LOW)
  {
  pulseCountOUT++;
  }
  if (digitalRead(FlowB) == HIGH)
  {
  pulseCountOUT++;
  }
}

Why do you define the interrupt to react on changes and then check for low and high states? Especially given you eliminate the second part of the handler as you noted in your last post.