Vous êtes sur la page 1sur 1

#include <LiquidCrystal.

h>
const int rs = 3, en = 4, d4 = 5, d5 = 6, d6 = 7, d7 = 8;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const int watermeterPin = 2;
volatile int pulse_frequency;
unsigned int literperhour;
unsigned long currentTime, loopTime;
byte sensorInterrupt = 0;

void setup()
{
lcd.begin(16, 2);
lcd.print("WATERFLOWMONITOR");

pinMode(watermeterPin, INPUT);
Serial.begin(9600);
attachInterrupt(sensorInterrupt, getFlow, FALLING);

currentTime = millis();
loopTime = currentTime;
}

void loop ()
{
int s = analogRead(A0);
s=s/10;
lcd.setCursor(0,1);
Serial.println(s);
delay(2000);
lcd.print("WATER LEVEL:");
lcd.print(s);
lcd.print("% ");
delay(2000);
currentTime = millis();
if(currentTime >= (loopTime + 1000))
{
loopTime = currentTime;
literperhour = (pulse_frequency * 60 / 7.5);
pulse_frequency = 0;
Serial.print(literperhour, DEC);
Serial.println(" Liter/hour");
delay(2000);
lcd.setCursor(0,1);
lcd.print("LITRE/HOUR:");
lcd.print(literperhour);
delay(2000);
}
}
void getFlow ()
{
pulse_frequency++;
}

Vous aimerez peut-être aussi