Pedro52
Published © GPL3+

Smart Water Meter

This Smart Water Meter has an inductive proximity sensor connected to an ESP32 is programmed in ARDUINO and uses the BLYNK IoT platform.

AdvancedFull instructions providedOver 1 day8,479
Smart Water Meter

Things used in this project

Hardware components

See story
×1
Common tools & test equipment
×1
Soldering iron
×1
3D printer
×1

Software apps and online services

Arduino IDE
Arduino IDE
Blynk
Blynk
Fusion 360
Autodesk Fusion 360
CURA
EasyEDA

Hand tools and fabrication machines

Drill

Story

Read more

Custom parts and enclosures

3D print files Smart Water Meter

STL files for 3D printing
Note: holes in the back plate are not part of the design and need to be drilled by hand.

Schematics

Circuit Diagram Smart Water Meter

Code

Arduino Sketsch Smart Water Meter English comments

Arduino
/*************************************************************
  This Arduino sketch is made for a Smart Water Meter and produced by Pierre Pennings, springtime 2022
  The waterflow is measured bu means of a proximity senser put on top of the existing watermeter
  In this sketch the number of liters used are counted and the mommentary waterflow in l/min
  the measured values are sent to the Blynk app every 60 seconds
  V5 is the LitCount value and V7 the momentary waterflow in Liters per Min
  A blue led provides a heartbeat signal (connected with GPIO 27)  indicating data transmission via WiFi to BLYNK
  An orange/yellow LED (connected with GPIO 25) indicates that there is a waterflow
  The device is powered by a 5V mobile phone charger
 *************************************************************/

////////// Make a free Blynk account via: https://blynk.io/ ;
// The following information is obtained via Blynk.Cloud; see the start instructions on: https://docs.blynk.io/en/getting-started/what-do-i-need-to-blynk
// copy the Template ID, Device Name and Auth Token from the Device Info tab of the Template settings

#define BLYNK_TEMPLATE_ID "Own TMPL-code"                         // put here your own template code as obtained from BLYNK
#define BLYNK_DEVICE_NAME "My Smart Watermeter"                   // put here the name of your own device 
#define BLYNK_AUTH_TOKEN "My template token code"                 // put here your TOKEN code

////////// installing the following Libraries
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

////////// Making the settings for use of your WiFi Access Point and the Blynk Authorisation Token
char auth[] = BLYNK_AUTH_TOKEN;       // variable using the above defined TOKEN code specific to your device
char ssid[] = "my WIFI";              // your own WiFi credentials
char pass[] = "my password";          // Set the password of your own WiFi, set as "" for an open netwerk

//////////Global Constants (o.a. to be used for GPIO pins)
const int Liter_count_Pin = 4;        // the Liter_count_Pin is connected with the GPIO04 pin, if the sensor does not detect metal then the Liter_count_Pin is HIGH 
const int B_LEDPin = 27;              // Blue LED connected with GPIO pin 17 with resistor of 330 Ohm in series (Heartbeat LED)
const int Or_LEDPin = 25;             // Orange LED connected with GPIO pin 16 with resistor of 330 Ohm in series
float Flowrate_factor = 288330.00;    // factor for calibrating. using 300000 means 1 liter/sec or 60 Lit/Min with a Count_Duration of 300 msec 
                                      // 300000.00 modified to 288330.00 after calibration (see tutorial)

///////////Globale Variables
int LitCount = 0;                     // Counter for keeping the total number of used Liter during the total uptime
int PastMinuteUse = 0;                // Variable for the number of used liter in the past minute
int PrevLitCount = 0;                 // variable to store the amount of used water in liter during the previous past minute
int Stopcount = 0;                    // variable for counting the number of stops of the metal plate under the sensor
float FlowLitPerSec = 0.00;           // Momentary flow in Liter/sec  
float FlowLitPerMin = 0.00;           // Momentary flow in Liters/min 
int UpTimeMin = 0;                    // keeps the time lapsed in minutes after the last reset
double UpTimeHr = 0.00;               // keeps the time lapsed in hours after the last reset
double UpTimeDay = 0.00;              // keeps the time lapsed in days after the last reset
int DayCount = 1;                     // counts the number of days since the device came on-line after the last reset (starts at 1 again after 1 year)
int TodayUse = 0;                     // counts the number of liter used after the start of the day
int PastDayUse = 0;                   // counts the number of liter used in the past 24 hours
int PrevDayLitCount = 0;              // counts the number of liter used in the previous past 24 hours
int PastYearCub = 0;                  // cummulative amount in m3 in the past year
boolean WaterFlow_state = false;      // indicates if there is waterflow or not (WaterFlow_state false -> no waterflow)
boolean Home = true;                  // indicates if there is someone at home (Home=true) or not (Home=false)
unsigned long Count_Duration = 0.00;  // variable that holds the time in microseconds between the momement of going LOW and going back to HIGH of the Liter_count_Pin
BlynkTimer timer;                     // Creates a timer object

///////////////// This function is excuted when Virtual Pin 0 (V0) changes state, indicating Home or not Home
BLYNK_WRITE(V0) {
  int value = param.asInt();          // assign incomming value of pin V0 to variable "value"
if(value == 1)                        // excute this code in case value is "1" (meaning Home is on)
  { Home = true; }                    // make boolean Home true
  else                                // excute this code in case value is "0" (meaning Home is off)
  { Home = false; }                   // make boolean Home false
  Blynk.virtualWrite(V1, value);      // Update Home state on the Blynk dashboard
}
  
//////////////////the setup functie will run once after pushing the reset button or after power-on
void setup() {
  //Serial.begin(115200);                           // data communication via the USB port to the PC started with 115200 Baud (bits/sec); uncomment to use serial monitor
  pinMode(B_LEDPin, OUTPUT);                        // set blue Ledpin as output
  pinMode(Or_LEDPin, OUTPUT);                       // set orange Ledpin as output
  pinMode(Liter_count_Pin, INPUT_PULLUP);           // set Liter_count_Pin as input with Pullup resistor (connected to Optocoupler output,active LOW ) 
  digitalWrite(B_LEDPin,LOW);                       // blue led off
  digitalWrite(Or_LEDPin,HIGH);                     // orange led on (temporarily)
                                             /*///////uncomment to make readable on seriale monitor
  Serial.print("Count_Duration = ");                // print once the headers of the data table on serial monitor
  Serial.print("   LitCount = "); 
  Serial.print("   FlowLitPerSec l/s = "); 
  Serial.println("   FlowLitPerMin = ");
                                             */
  Blynk.begin(auth, ssid, pass);                    // make the connection with BLYNK.CLOUD

/////////// settings for all timers the will initiate the aasigned functions at the given time intervals
  timer.setInterval(10000L, MEASUREWATER);              // Set the function MEASUREWATER to excute every 10 seconds
  timer.setInterval(60000L, SendPeriodicWaterUse);      // Set the function SendPeriodicWaterUse to excute every 60 seconden(60000L)
  timer.setInterval(86400000L, SendDailyUseData);       // Set the function SendDailyUseData to excute every 24 hours (86400000L)
}

//////////////////the loop function runs repeatatively until reset 
void loop()
{
  Blynk.run();
  timer.run();
}

//////////////////function MEASUREWATER takes care of measuring the Water usage data (V5, V7) en het bedienen van het Waterflow Alarm (V4)
void MEASUREWATER() {
 Count_Duration = pulseInLong(Liter_count_Pin, LOW, 9000000);   // time in uSec between going LOW and back to HIGH, return "0" if time is longer than 9 Sec
  if (Count_Duration != 0) { 
    digitalWrite(Or_LEDPin,HIGH);                               // put Orange LED on
    WaterFlow_state = true;                                     // there is waterflow
    LitCount = LitCount + 1;
    Stopcount = 0;
    FlowLitPerSec = Flowrate_factor/Count_Duration ;            // Waterflow in liters/sec  ; minimal waterflow is 0,032 lit/sec (ca 1,9 Lit/min) or 0,32 lit in 9 seconds
    FlowLitPerMin = FlowLitPerSec * 60.00;                      // Waterflow in liters/min 
    }    
   else if (Count_Duration == 0) { 
    WaterFlow_state = false;                                    // there is no waterflow
    FlowLitPerSec = 0;                                          // made 0 in case the flow is less than 0,032 lit/sec (1,9 Lit/min) at a max measuring time of 9 sec
    FlowLitPerMin = 0;                                          // dito
    if (digitalRead(Liter_count_Pin) == LOW) {                  // when the waterflow has stopped while the metal plate is under the sensor
        //Serial.println("Liter_count_Pin = LOW ");             // uncomment to make visible on serial monitor
        digitalWrite(Or_LEDPin,HIGH);                           // put Orange LED on
        if (Stopcount == 0) {                                   // in case the stop couter is 0
        LitCount = LitCount + 1;                                // count one liter
        Stopcount = Stopcount + 1;                              // increase the stopcounter by 1 
        }
    }
   }
                                              /*///////uncomment to make visible on serial monitor
   Serial.print("           "); Serial.print(Count_Duration);       // print de gemeten waarden naar de seriele monitor, aanzetten wanneer PC connected
   Serial.print("               "); Serial.print(LitCount);
   Serial.print("               "); Serial.print(FlowLitPerSec);
   Serial.print("               "); Serial.print(FlowLitPerMin);
   Serial.println();                          */  //uncomment to make visible on serial monitor

   digitalWrite(B_LEDPin,HIGH);                   // put blue LED on

   Blynk.virtualWrite(V7, FlowLitPerMin);         // send the flow in Lit/min to V7
   // Serial.println("MEASUREWATER ");            // uncomment to make visible on serial monitor

  if (!Home && WaterFlow_state ) {                // in case not Home and when there is Waterflow give WaterFlow Alarm
    Blynk.virtualWrite(V4, true);
    Blynk.logEvent("WaterAlarm", "There is waterflow and nobody is home");}        // create the logevent, needed for automation
    else 
    {Blynk.virtualWrite(V4, false); }                                              // make V4 alarm false

    digitalWrite(Or_LEDPin,LOW);                  // put Orange LED off
    digitalWrite(B_LEDPin,LOW);                   // put blue LED off
}

//////////////////function SendPeriodicWaterUse takes care of sending Water use data (V5, V6 en V10) and Uptime data (V2,V11, V12), once per minute
void SendPeriodicWaterUse() {
  digitalWrite(B_LEDPin,HIGH);                    // put blue LED on

  UpTimeMin = millis() / 60000 ;                  // calculate the uptime in minutes
  UpTimeHr = UpTimeMin / 60.00 ;                  // calculate the uptime in hours
  UpTimeDay = UpTimeHr / 24.00 ;                  // calculate the uptime in days
  
  PastMinuteUse = LitCount - PrevLitCount;        // calculate the number of liter used in the past minute
  TodayUse = TodayUse + PastMinuteUse;            // calculate the number of liter used since the start of today
  
  Blynk.virtualWrite(V5, LitCount);               // send the LiterCount value to V5
  Blynk.virtualWrite(V2, UpTimeMin);              // send the uptime to V2 in minutes
  Blynk.virtualWrite(V11, UpTimeHr);              // send the uptime to V11 in hours
  Blynk.virtualWrite(V12, UpTimeDay);             // send the uptime to V12 in days

  Blynk.virtualWrite(V10, TodayUse);              // send the number of liter used since the start of today to V10
  Blynk.virtualWrite(V6, PastMinuteUse);          // send the number of liter used in the past minute to V6
  PrevLitCount = LitCount;
  //Serial.println("SendPeriodicWaterUse ");      // uncomment to make visible on serial monitor
  digitalWrite(B_LEDPin,LOW);                     // put blue LED off
}

//////////////////functie SendDailyUseData takes care of sending the daily water usage once per 24 hours
void SendDailyUseData() {
   digitalWrite(B_LEDPin,HIGH);                                // put blue LED on
   if (DayCount < 366) {                                       // if not at year end
   PastDayUse = LitCount - PrevDayLitCount;                    // calculate the number of liter used in the past day
   
   TodayUse = 0 ;                                              // put the number of liter used today back to 0 
   PrevDayLitCount = LitCount;                                 // PrevDayLitCount gets the value of total number of liter used sofar
   }
   else {                                                      // if the DayCount = 366 then it is end of the year
   PastYearCub = LitCount/1000;                                // total amount of cubic meters of water used in the past year 
   //Serial.print("total use in past year in m3 = "); Serial.println(PastYearCub);
   Blynk.virtualWrite(V13, PastYearCub);                       // send past year usage to V13
   DayCount = 0;                                               // start of a new year
   LitCount = 0;                                               // the Liter counter is put back to 0 at the beginning of a new year
   TodayUse = 0;                                               // put the number of liter used today back to 0
   }
  Blynk.virtualWrite(V8, DayCount);                            // send the day number to V8
  Blynk.virtualWrite(V9, PastDayUse);                          // send the number of liter used in the past day to V9 ;
  
  DayCount = DayCount +1;                                      // increase the day counter with 1
  //Serial.println("SendDailyUseData ");                       // uncomment to make visible on serial monitor
  digitalWrite(B_LEDPin,LOW);                                  // put blue LED off
}

Arduino Sketch Slimme Water Meter Dutch comments

Arduino
/*************************************************************
  Deze sketch is voor een slimme watermeter ontwikkeld door Pierre Pennings in het voorjaar van 2022
  De waterflow wordt gemeten met een proximity sensor bevestigd op de watermeter
  In deze sketch worden het aantal liters geteld dat door de watermeter stroomt (waterverbruik) en de momentele stroomsnelheid (flow)
  De gemeten waardes worden elke 60 seconden verzonden naar de Blynk App
  V5 is LitCount en V7 de momentele waterflow in Liters per Min
  Een blauwe led geeft een heartbeat indicatie (verbonden met GPIO 27) ten teken dat er data overdracht is via WiFi naar BLYNK
  Een oranje/gele led geeft aan dat er waterflow is (verbonden met GPIO 25)
  Het geheel wordt gevoed met een 5V telefoon lader.
 *************************************************************/

////////// Maak een gratis Blynk account via: https://blynk.io/ ;
// de volgende informatie wordt verkregen via Blynk.Cloud; zie hiervoor de start instructies op: https://docs.blynk.io/en/getting-started/what-do-i-need-to-blynk
// kopieer de Template ID, Device Name en Auth Token van de Device Info tab van de Template settings

#define BLYNK_TEMPLATE_ID "Own TMPL-code"                         // vul hier je eigen template code in verkregen van BLYNK
#define BLYNK_DEVICE_NAME "Mijn Slimme Watermeter"                // vul hier de naam van je eigen device in    
#define BLYNK_AUTH_TOKEN "mijn template token code"               // vul hier je eigen TOKEN code in verkregen van BLYNK

////////// installeer de volgende Libraries
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

////////// maak de instellingen voor het te gebruiken WiFi Access Point en het Blynk Authorisation Token
char auth[] = BLYNK_AUTH_TOKEN;       // variabele die de hierboven ingevulde TOKEN code heeft (AuthToken) specifiek voor dit device
char ssid[] = "mijn WIFI";            // je eigen WiFi credentials
char pass[] = "mijn wachtwoord";      // Set het password van je eigen WiFi, set als "" voor een open netwerk

//////////Globale Constanten (o.a. te gebruiken GPIO pinnen)
const int Liter_count_Pin = 4;        // de Liter_count_Pin is verbonden met de GPIO04 pin, als de sensor geen metaal detecteert dan is Liter_count_Pin HIGH 
const int B_LEDPin = 27;              // Blauwe LED verbonden met GPIO pin 17 met voorschakel weerstand van 330 Ohm (Heartbeat LED)
const int Or_LEDPin = 25;             // Oranje LED verbonden met GPIO pin 16 met voorschakel weerstand van 330 Ohm
float Flowrate_factor = 288330.00;    // betekent 1 liter/sec of 60 Lit/Min bij een Count_Duration van 300 msec 
                                      // 300000.00 aangepast naar 288330.00 na calibratie (zie tutorial)

///////////Globale Variabelen
int LitCount = 0;                     // Teller die totaal aantal verbruikte Liters bijhoudt gedurende de totale uptime (nog verbeteren voor geval van stroomuitval)
int PastMinuteUse = 0;                // Teller die het aantal verbruikte Liters in de afgelopen periode van 1 minuut bijhoudt
int PrevLitCount = 0;                 // Teller die het aantal verbruikte Liters in de voorgaande periode van 1 minuut bijhoudt
int Stopcount = 0;                    // Teller die het aantal Stops van het rondraaiende schijfje onder de sensor bijhoudt: indien 1: extra liter tellen
float FlowLitPerSec = 0.00;           // Momenteel verbruik in Liters/sec  
float FlowLitPerMin = 0.00;           // Momenteel verbruik in Liters/min 
int UpTimeMin = 0;                    // geeft de verstreken tijd in minuten sinds de laatste reset
double UpTimeHr = 0.00;               // geeft de verstreken tijd in uren sinds de laatste reset
double UpTimeDay = 0.00;              // geeft de verstreken tijd in dagen sinds de laatste reset
int DayCount = 1;                     // geeft het aantal dagen sinds het device voor het eerst online kwam (start na jaar weer bij 1)
int TodayUse = 0;                     // telt het vandaag gebruikte aantal liters
int PastDayUse = 0;                   // gemeten gebruik in liters in de afgelopen 24 u
int PrevDayLitCount = 0;              // gemeten gebruik in liters in de voorgaande 24 u
int PastYearCub = 0;                  // cummulatief aantal m3 in het afgelopen jaar
boolean WaterFlow_state = false;      // geeft aan of er waterflow gedetecteerd wordt of niet (WaterFlow_state false -> geen waterflow)
boolean Home = true;                  // geeft aan of er iemand thuis is (Home=true) of niet (Home=false)
unsigned long Count_Duration = 0.00;  // hiermee wordt de tijd in microseconden gemeten tussen LOW gaan en weer HIGH worden van de Liter_count_Pin
BlynkTimer timer;                     // Creeer een timer object

///////////////// Deze functie wordt uitgevoerd elke keer dat de Virtuele Pin 0 (V0) van toestand verandert, ter indicatie Thuis of niet Thuis
BLYNK_WRITE(V0) {
  int value = param.asInt();          // geef binnenkomende waarde van pin V0 aan variable "value"
if(value == 1)                        // voer deze code uit indien de waarde 1 is d.wz. "Home" is aan
  { Home = true; }                    // maakt boolean Home true
  else                                // voer deze code uit indien de waarde 0 is d.wz. "Home" is uit
  { Home = false; }                   // maakt boolean Home false
  Blynk.virtualWrite(V1, value);      // Update Home state op het Blynk dashboard
}
  
//////////////////de setup functie wordt 1 maal doorlopen na het drukken van de reset knop of na power-on
void setup() {
  //Serial.begin(115200);                           // data communicatie via de USB poort naar PC gestart met 115200 Baud (bits/sec); uncomment om seriele monitor te gebruiken
  pinMode(B_LEDPin, OUTPUT);                        // set blauwe Ledpin als output
  pinMode(Or_LEDPin, OUTPUT);                       // set oranje Ledpin als output
  pinMode(Liter_count_Pin, INPUT_PULLUP);           // set Liter_count_Pin als input met Pullup weerstand (verbonden met Optocoupler output,active LOW ) 
  digitalWrite(B_LEDPin,LOW);                       // blauwe led uit
  digitalWrite(Or_LEDPin,HIGH);                     // oranje led tijdelijk aan
                                             /*///////uncomment om leesbaar te maken op seriele monitor
  Serial.print("Count_Duration = ");                // print eenmalig de headers van de data tabel op de seriele monitor
  Serial.print("   LitCount = "); 
  Serial.print("   FlowLitPerSec l/s = "); 
  Serial.println("   FlowLitPerMin = ");
                                             */
  Blynk.begin(auth, ssid, pass);                    // maak de verbinding met het BLYNK.CLOUD

/////////// maak de instellingen voor alle timers die moeten lopen met de bijbehorende functies die aangeroepen worden
  timer.setInterval(10000L, MEASUREWATER);              // Set de functie MEASUREWATER om elke 10 seconden te worden aangeroepen
  timer.setInterval(60000L, SendPeriodicWaterUse);      // Set de functie SendPeriodicWaterUse om elke 60 seconden te worden aangeroepen (60000L)
  timer.setInterval(86400000L, SendDailyUseData);       // Set de functie SendDailyUseData om elke 24 uur te worden aangeroepen (86400000L)
}

//////////////////de loop functie loopt bij herhaling tot de reset knop wordt gedrukt 
void loop()
{
  Blynk.run();
  timer.run();
}

//////////////////functie MEASUREWATER verzorgt het meten van Waterverbruik data (V5, V7) en het bedienen van het Waterflow Alarm (V4)
void MEASUREWATER() {
 Count_Duration = pulseInLong(Liter_count_Pin, LOW, 9000000);   // tijd in uSec tussen LOW gaan en weer HIGH worden, geeft "0" indien langer dan 9 Sec
  if (Count_Duration != 0) { 
    digitalWrite(Or_LEDPin,HIGH);                               // zet Oranje LED aan
    WaterFlow_state = true;                                     // er is waterflow
    LitCount = LitCount + 1;
    Stopcount = 0;
    FlowLitPerSec = Flowrate_factor/Count_Duration ;            // Waterflow in liters/sec  ; minimale waterflow is 0,032 lit/sec (ca 1,9 Lit/min) of wel 0,32 lit in 9 seconden
    FlowLitPerMin = FlowLitPerSec * 60.00;                      // Waterflow in liters/min 
    }    
   else if (Count_Duration == 0) { 
    WaterFlow_state = false;                                    // er is geen waterflow
    FlowLitPerSec = 0;                                          // is dus ook 0 indien de flow minder is dan 0,032 lit/sec (1,9 Lit/min) bij een max meettijd van 9 sec
    FlowLitPerMin = 0;
    if (digitalRead(Liter_count_Pin) == LOW) {
        //Serial.println("Liter_count_Pin = LOW ");             // uncomment om leesbaar te maken op seriele monitor
        digitalWrite(Or_LEDPin,HIGH);                           // zet Oranje LED aan
        if (Stopcount == 0) {
        LitCount = LitCount + 1;                                // wanneer de waterflow is gestopt en de Liter_count-Pin low is,
        Stopcount = Stopcount + 1;                              // dan is het roterende metaalplaatje onder de sensor gestopt en
        }                                                       // wordt er alsnog 1 liter geteld (eenmalig) omdat er anders nogal wat liters niet geteld zouden worden
    }
   }
                                              /*///////uncomment om leesbaar te maken op seriele monitor
   Serial.print("           "); Serial.print(Count_Duration);       // print de gemeten waarden naar de seriele monitor, aanzetten wanneer PC connected
   Serial.print("               "); Serial.print(LitCount);
   Serial.print("               "); Serial.print(FlowLitPerSec);
   Serial.print("               "); Serial.print(FlowLitPerMin);
   Serial.println();                          */  //uncomment om leesbaar te maken op seriele monitor

   digitalWrite(B_LEDPin,HIGH);                   // zet Blauwe LED aan

   Blynk.virtualWrite(V7, FlowLitPerMin);         // zend de flow in Lit/min naar V7
   // Serial.println("MEASUREWATER ");            // uncomment om leesbaar te maken op seriele monitor

  if (!Home && WaterFlow_state ) {                // indien niet Thuis en er is Waterflow geef WaterFlow Alarm
    Blynk.virtualWrite(V4, true);
    Blynk.logEvent("WaterAlarm", "Er is watergebruik en er is niemand thuis");}        // zet V4 alarm aan "There is waterflow, while nobody is Home"
    else 
    {Blynk.virtualWrite(V4, false); }                                                  // zet V4 alarm uit

    digitalWrite(Or_LEDPin,LOW);                  // zet Oranje LED uit
    digitalWrite(B_LEDPin,LOW);                   // zet Blauwe LED uit
}

//////////////////functie SendPeriodicWaterUse verzorgt het zenden van Waterverbruik data (V5, V6 en V10) en de Uptime (V2,V11, V12), een keer per minuut
void SendPeriodicWaterUse() {
  digitalWrite(B_LEDPin,HIGH);                    // zet Blauwe LED aan

  UpTimeMin = millis() / 60000 ;                  // bereken de uptime in minuten
  UpTimeHr = UpTimeMin / 60.00 ;                  // bereken de uptime in uren
  UpTimeDay = UpTimeHr / 24.00 ;                  // bereken de uptime in dagen
  
  PastMinuteUse = LitCount - PrevLitCount;        // berekend het aantal gebruikte liters in de afgelopen minuut
  TodayUse = TodayUse + PastMinuteUse;            // berekend het aantal gebruikte liters sinds de start van de dag
  
  Blynk.virtualWrite(V5, LitCount);               // zend de LiterCount value naar V5
  Blynk.virtualWrite(V2, UpTimeMin);              // zend de uptime naar V2 in minuten
  Blynk.virtualWrite(V11, UpTimeHr);              // zend de uptime naar V11 in uren
  Blynk.virtualWrite(V12, UpTimeDay);             // zend de uptime naar V12 in dagen

  Blynk.virtualWrite(V10, TodayUse);              // zend het aantal liter watergebruik sinds het begin van de dag naar V10
  Blynk.virtualWrite(V6, PastMinuteUse);          // zend het watergebruik in de afgelopen minuut naar V6
  PrevLitCount = LitCount;
  //Serial.println("SendPeriodicWaterUse ");      // uncomment om leesbaar te maken op seriele monitor
  digitalWrite(B_LEDPin,LOW);                     // zet Blauwe LED uit
}

//////////////////functie SendDailyUseData verzorgt het zenden van de dagelijkse Waterverbruik data een keer per 24 h
void SendDailyUseData() {
   digitalWrite(B_LEDPin,HIGH);                                // zet Blauwe LED aan
   if (DayCount < 366) {
   PastDayUse = LitCount - PrevDayLitCount;                    // aantal liters gebruikt in de afgelopen dag
   
   TodayUse = 0 ;                                              // zet het vandaag gebruikte aantal liter weer op 0 
   PrevDayLitCount = LitCount;                                 // PrevDayLitCount krijgt waarde van het totaal aantal liters gemeten tm afgelopen dag
   }
   else {                                                      // indien DayCount = 366 dan einde jaar
   PastYearCub = LitCount/1000;                                // totaal aantal m3 gebruikt in afgelopen jaar 
   //Serial.print("total use in past year in m3 = "); Serial.println(PastYearCub);
   Blynk.virtualWrite(V13, PastYearCub);                       // zend het jaarverbruik naar V13
   DayCount = 0;                                               // begin van een nieuw jaar
   LitCount = 0;                                               // de Liter teller op 0 aan het begin van het nieuwe jaar
   TodayUse = 0;                                               // zet het vandaag gebruikte aantal liter weer op 0 
   }
  Blynk.virtualWrite(V8, DayCount);                            // zend de dag behorend bij de metingen naar V8
  Blynk.virtualWrite(V9, PastDayUse);                          // zend het aantal liters watergebruik in de afgelopen Dag naar V9 ; voor groot gebruikers: vervang PastDayUse door DailyUseCub
  
  DayCount = DayCount +1;                                      // verhoogd de dagteller met 1
  //Serial.println("SendDailyUseData ");                       // uncomment om leesbaar te maken op seriele monitor
  digitalWrite(B_LEDPin,LOW);                                  // zet Blauwe LED uit
}

Credits

Pedro52

Pedro52

6 projects • 46 followers

Comments