Automatic tank refilling

hello, I wanted to share my project with automatic tank refilling, utilizzazndo an ultrasonic sensor I converted the measure as a percentage so that with wigdet gauge shows the percentage from 0% to 100% the maximum and minimum level of the tank can be set in all variables 'beginning of the code, as well as the level that you want to share the automatic refilling … hello to all

//#define BLYNK_PRINT Serial                         // attiva serial print
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <SimpleTimer.h>

char auth[] = "xxxxx"; 

SimpleTimer timer;

#define echoPin 8                                    // Echo Pin
#define trigPin 9                                    // Trigger Pin
#define valvola 22                                   // valvola rabbocco
#define led 13                                       // led
long duration, distance;                             // Duration used to calculate distance
int livellomin = 160;                                // misura minima in cm acqua x calcolo %
int livellomax = 20;                                 // misura max in cm acqua x calcolo %
int rabbocco = 50;                                   // livello rabbocco
float livello;                                       // livello acqua in percentuale %

void setup() {
  Serial.begin(9600);
  Blynk.begin(auth);
  pinMode(trigPin, OUTPUT);
  pinMode(valvola, OUTPUT);
  pinMode(led, OUTPUT);
  pinMode(echoPin, INPUT);
  timer.setInterval(100, calcolo);                   
  digitalWrite(valvola,LOW);                         
}

void calcolo()
{
  digitalWrite(trigPin, LOW); 
  delayMicroseconds(2); //2
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10); //10
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = duration/58.2;                          //calcolo in cm in base velocità suono
  livello = ((distance - livellomin)*100) / (livellomax - livellomin); //trasformo in percentuale
  //Serial.println(distance);                        //livello in cm su monitor seriale

  if (distance >= rabbocco) {                           
    digitalWrite(valvola,LOW);                     
    digitalWrite(led,HIGH);
  } else {
    digitalWrite(valvola,HIGH);
    digitalWrite(led,LOW);
  }
}

BLYNK_READ(V8)
{
  Blynk.virtualWrite(8,livello);                     // virtualpin 8 distanza
  Blynk.virtualWrite(9,led);                         // virtualpin 9 led valvola
}


void loop() {
  Blynk.run();                                       // Initiates Blynk
  timer.run();                                       // Initiates SimpleTimer
}
1 Like

I wanted to integrate the project here even over an irrigation system time zones … and how can I check blink of an event with hardware RTC? example:
time 01:30 on zone1
time 01:50 stop zone1
time 02:10 on zone 2
time 02:20 stop zone 2
these events with times are not configured directly with the app right Blynk?
What was the most correct way to do it with Blynk? thank you