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)
{
}
}