I wanna add a constant cost output on my connected display, but i'm not very sure how to write a short sketch that will help to keep up with the cost output.
In other words.... My project is meant to obtain the cost of the water passing through it...
I have the price of 1L of flowing water but i wan't to know how to enable a counter that will help to get the price of water as each litre passes though...
This is the code of the following:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
int X;
int Y;
float TIME = 0;
float FREQUENCY = 0;
float WATER = 0;
float TOTAL = 0;
float LS = 0;
float COST = 0.04;
float RS = 1;
const int input = A0;
void setup()
{
Serial.begin(9600);
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("WATER FLOW METER");
lcd.setCursor(0, 1);
lcd.print("** STEVE DE SA *");
delay(1000);
pinMode(input, INPUT);
}
void loop()
{
X = pulseIn(input, HIGH);
Y = pulseIn(input, LOW);
TIME = X + Y;
FREQUENCY = 1000000 / TIME;
WATER = FREQUENCY / 7.5;
LS = WATER / 60;
if (FREQUENCY >= 0)
{
if (isinf(FREQUENCY))
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("TOTAL: ");
lcd.print(TOTAL);
lcd.print(" L");
lcd.setCursor(0, 1);
lcd.print("COST : ");
lcd.print(" INR");
}
else
{
TOTAL = TOTAL + LS;
Serial.println(FREQUENCY);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("TOTAL: ");
lcd.print(TOTAL);
lcd.print(" L");
lcd.setCursor(0, 1);
lcd.print("COST : ");
lcd.print(COST);
lcd.print(" INR");
}
}
delay(1000);
}
Please help me out with adding the counter so as to find the cost of water constantly flowing:)
Your help will be highly appreciated as I need this project addition urgently!