Thanks for help binooetomo, but I can't get this to work properly. Actually, nothing work properly here right now. This works like a charmike a charm: WaterFlowGauge/WaterFlowGauge.pde at master · practicalarduino/WaterFlowGauge · GitHub
I have also tried to modify my first sketch to work, but nothing happends after compiling, uploading and opening the serial monitor.
I am so far here:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
byte sensorInterruptA = 0;
byte sensorInterruptB = 1;
byte sensorPinA = 2;
byte sensorPinB = 3;
float calibrationFactor = 4.5;
volatile byte pulseCount;
float flowRate;
unsigned int flowRateA;
unsigned int turFuel;
unsigned int returFuel;
unsigned long oldTime;
void setup()
{
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print(" ");
Serial.begin(9600);
pinMode(sensorPinA, INPUT);
pinMode(sensorPinB, INPUT);
digitalWrite(sensorPinA, HIGH);
digitalWrite(sensorPinB, HIGH);
pulseCount = 0;
pulseCount = 0;
flowRate = 0.0;
sensorInterruptA = 0;
sensorInterruptB = 0;
oldTime = 0;
attachInterrupt(sensorInterruptA, pulseCounter, FALLING);
attachInterrupt(sensorInterruptB, pulseCounter, FALLING);
}
//hovedprogrammet i loop.
void loop()
{
if((millis() - oldTime > 1000))
{
detachInterrupt(sensorInterruptA);
detachInterrupt(sensorInterruptB);
oldTime =millis();
flowRate = (sensorInterruptA - sensorInterruptB) / 8500;
flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
flowRateA = (flowRate / 60) * 1000;
unsigned int frac;
Serial.print(int(flowRateA));
Serial.print(".");
frac = (flowRateA - int(flowRateA)) * 10;
Serial.print(frac, DEC) ;
Serial.print(" ");
Serial.print(flowRateA);
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(0, 0);
lcd.print("Flow: ");
if(int(flowRate) < 10)
{
lcd.print(" ");
}
lcd.print((int)flowRate);
lcd.print('.');
lcd.print(frac, DEC) ;
lcd.print(" L");
lcd.print("/min");
pulseCount = 0;
attachInterrupt(sensorInterruptA, pulseCounter, FALLING);
attachInterrupt(sensorInterruptB, pulseCounter, FALLING);
}
}
void pulseCounter()
{
pulseCount++;
}
Regards, Fredrik