// Start By the Name Of Allaha
#include <Keypad.h>
const int ROW_NUM = 4;
const int COLUMN_NUM = 4;
#include <LiquidCrystal_I2C.h> // LiquidCrystal_I2C library
LiquidCrystal_I2C lcd(0x27, 16, 2);
char keys[ROW_NUM][COLUMN_NUM] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
byte pin_rows[ROW_NUM] = { 11, 10, 9, 8 };
byte pin_column[COLUMN_NUM] = { 7, 6, 5, 4 };
Keypad keypad = Keypad(makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM);
int sensorInterrupt = 0;
int sensorPin = 2;
int solenoidValve =12;
const int Pump =13;
float SetPoint = 40.0; String code = " ";
float calibrationFactor = 6.90;
volatile byte pulseCount = 0;
float flowRate = 0.0;
float flow_per_Minute = 0.0;
float filled_Liter = 0.0;
float total_Litres = 0.000, volume = 0.000;
unsigned long oldTime;
void setup() {
//Serial.begin(9600);
total_Litres = 0.0;
pinMode(Pump, OUTPUT);
lcd.begin(20, 4);
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Set Volume:");
pinMode(solenoidValve, OUTPUT);
digitalWrite(solenoidValve, HIGH);
pinMode(sensorPin, INPUT);
digitalWrite(sensorPin, HIGH);
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
}
void loop() {
char key = keypad.getKey();
//lcd.clear();
if (key) {
code += key;
lcd.setCursor(0, 1);
lcd.print(code);
delay(100);
}
if (key == '#') {
total_Litres = 0.0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Set Volume:");
code = "";
}
if (key == '*') {
if (code.toInt() <= 150.00) {
volume = code.toInt();
} else {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Set Volume:");
}
code = "";
}
if (total_Litres < volume) {
digitalWrite(Pump, HIGH);
if ((millis() - oldTime) > 1000) {
detachInterrupt(sensorInterrupt);
flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
oldTime = millis();
flow_per_Minute = (flowRate);
filled_Liter = (flowRate / 60);
total_Litres += filled_Liter;
/*Serial.print("Flow rate :");
Serial.print(flow_per_Minute);
Serial.print("L/M");
Serial.print("\t");*/
//lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Speed :");
lcd.print(flow_per_Minute);
lcd.print(" L/M");
/*Serial.print("Output Liquid Quantity:");
Serial.print(total_Litres);
Serial.println("Lt");
Serial.print("\t");*/
lcd.setCursor(0, 1);
lcd.print("Filled:");
lcd.print(total_Litres);
lcd.print(" Lt");
if (total_Litres > 40) {
SetSolinoidValve();
}
pulseCount = 0;
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
}
} else {
digitalWrite(Pump, LOW);
volume = 0;
}
}
void pulseCounter() {
pulseCount++;
}
void SetSolinoidValve() {
digitalWrite(solenoidValve, LOW);
}