The solution requires own webserver

Arduino Water Well Monitor - Try online here!!!


The water level monitor allows you to:
  • Capture the water level from the lid level. Bottom distance can be up to 4 meters.
  • By calculating, the water level can be determined from the bottom and the volume in liters can be determined at a known well width (radius). Based on height, it can be represented in meters or centimeters.
  • Measured data is sent to a MySQL database that archives it with a timestamp.
  • Data is represented in real-time table, which is refreshed via AJAX, without real-time refresher are also plotted in graphs. The latest data in the graphs will appear after refresh.
  • Graphs show the course of the water height for: last 2 hours, last 24 hours, last 7 days, 30 days.
  • Database data is automatically deleted after 60+ days.
  • The system also includes alarm representations of last value, maximum, minimum value in 24 hours, 7 days, 30 days.
  • Used Hardware:
  • Arduino Uno/MegaArduino Uno R3
  • Ethernet shield W5100Ethernet Shield Wiznet W5100
  • or Ethernet module W5500Ethernet Module Wiznet W5500
  • Ultrasonic distance sensor - HC-SR04HC SR 04
  • The system can be used for additional measurements as well as other distances, such as: Snow Height, Object Distance etc.
  • Can also be applied to ESP8266, ESP32, Raspberry, Micro: bit, etc.
  •   
  • With Arduine, data over Ethernet is sent over the HTTP protocol. With ESP boards, it is also possible to create an encrypted HTTPS connection for sending data.
  •   
  • The ability to implement IoT over Sigfox.
  •    System Screenshots:
    HC-SR04 lib: Github

    Arduino + Ethernet Wiznet W5100

    #include <avr\wdt.h>
    #include <SPI.h>
    #include <Ethernet.h>
    #include <NewPing.h>
    #define pinTrigger    3
    #define pinEcho       4
    #define maxVzdialenost 450
    NewPing sonar(pinTrigger, pinEcho, maxVzdialenost);
    byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
    char server[] = "www.arduino.php5.sk";
    IPAddress ip(192, 168, 1, 101);
    EthernetClient client;
    void setup() {
      Serial.begin(9600);
      if (Ethernet.begin(mac) == 0) {
        Serial.println("Failed to configure Ethernet using DHCP");
        Ethernet.begin(mac, ip);
      }
      wdt_enable(WDTO_8S);
    }
    
    void loop() {
      wdt_reset();
      int vzdialenost = sonar.ping_cm();
      delay(50);
      if (vzdialenost > 0) {
        vzdialenost = 0;
        for (int i = 0; i < 5; i++) {
          vzdialenost += sonar.ping_cm();
          delay(50);
        }
        vzdialenost = vzdialenost / 5;
        Serial.print("Vzdialenost medzi senzorom a predmetom je: ");
        Serial.print(vzdialenost);
        Serial.println(" cm.");
        if (client.connect(server, 80)) {
          String hodnota = String(vzdialenost);
          Serial.println("Pripojenie uspesne na webserver, vykonavam request... ");
          client.print("GET /studna/data.php?hodnota=");
          client.print(hodnota);
          client.println(" HTTP/1.1");
          client.println("Host: www.arduino.php5.sk");
          client.println("Connection: close");
          client.println();
          Serial.println("Data uspesne odoslane na web");
          client.stop();
        } else {
          Serial.println("Pripojenie zlyhalo...");
        }
      }
      else {
        Serial.println("Vzdialenost medzi predmetom a senzorom je mimo rozsah.");
        wdt_reset();
        delay(500);
      }
      for (int i = 0; i <= 300; i++) {
        delay(1000);
        wdt_reset();
      }
    }
    

    ESP8266:

    #include <ESP8266WiFi.h>
    #include <NewPing.h>
    #define pinTrigger    5 //D1
    #define pinEcho       4 //D2
    #define maxVzdialenost 450
    NewPing sonar(pinTrigger, pinEcho, maxVzdialenost);
    
    
    const char * ssid = "wifi_meno"; //meno wifi siete
    const char * password = "wifi_heslo"; //heslo na wifi siet
    const char * host = "www.arduino.php5.sk"; //bez https a bez www
    
    const int httpPort = 80;
    WiFiClient client;
    void setup() {
      Serial.begin(115200);
      WiFi.begin(ssid, password); //pripoj sa na wifi siet s heslom
      while (WiFi.status() != WL_CONNECTED) {
        delay(1000);
        Serial.print(".");
      }
      Serial.println("");
      Serial.println("Wifi pripojene s IP:");
      Serial.println(WiFi.localIP());
    }
    
    void loop() {
      if (WiFi.status() != WL_CONNECTED) {
        WiFi.begin(ssid, password); //pripoj sa na wifi siet s heslom
      }
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
      }
      int vzdialenost = sonar.ping_cm();
      delay(50);
      if (vzdialenost > 0) {
        vzdialenost = 0;
        for (int i = 0; i < 5; i++) {
          vzdialenost += sonar.ping_cm();
          delay(50);
        }
        vzdialenost = vzdialenost / 5;
        Serial.print("Vzdialenost medzi senzorom a predmetom je: ");
        Serial.print(vzdialenost);
        Serial.println(" cm.");
        if (client.connect(host, httpPort)) {
          String hodnota = String(vzdialenost);
          Serial.println("Pripojenie uspesne na webserver, vykonavam request... ");
          String url = "/studna/data.php?hodnota=" + hodnota;
          client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "User-Agent: NodeMCU\r\n" + "Connection: close\r\n\r\n");
          Serial.println("Hodnoty do databazy uspesne odoslane");
          client.stop();
        } else {
          Serial.println("Pripojenie zlyhalo...");
        }
      }
      else {
        Serial.println("Vzdialenost medzi predmetom a senzorom je mimo rozsah.");
        delay(500);
      }
      for (int i = 0; i <= 300; i++) {
        delay(1000);
      }
    }
    

    ESP32

    #include <WiFi.h>
    #include <NewPing.h>
    #define pinTrigger    5 //D1
    #define pinEcho       4 //D2
    #define maxVzdialenost 450
    NewPing sonar(pinTrigger, pinEcho, maxVzdialenost);
    
    
    const char * ssid = "wifi_meno"; //meno wifi siete
    const char * password = "wifi_heslo"; //heslo na wifi siet
    const char * host = "www.arduino.php5.sk"; //bez https a bez www
    
    const int httpPort = 80;
    WiFiClient client;
    void setup() {
      Serial.begin(115200);
      WiFi.begin(ssid, password); //pripoj sa na wifi siet s heslom
      while (WiFi.status() != WL_CONNECTED) {
        delay(1000);
        Serial.print(".");
      }
      Serial.println("");
      Serial.println("Wifi pripojene s IP:");
      Serial.println(WiFi.localIP());
    }
    
    void loop() {
      if (WiFi.status() != WL_CONNECTED) {
        WiFi.begin(ssid, password); //pripoj sa na wifi siet s heslom
      }
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
      }
      int vzdialenost = sonar.ping_cm();
      delay(50);
      if (vzdialenost > 0) {
        vzdialenost = 0;
        for (int i = 0; i < 5; i++) {
          vzdialenost += sonar.ping_cm();
          delay(50);
        }
        vzdialenost = vzdialenost / 5;
        Serial.print("Vzdialenost medzi senzorom a predmetom je: ");
        Serial.print(vzdialenost);
        Serial.println(" cm.");
        if (client.connect(host, httpPort)) {
          String hodnota = String(vzdialenost);
          Serial.println("Pripojenie uspesne na webserver, vykonavam request... ");
          String url = "/studna/data.php?hodnota=" + hodnota;
          client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "User-Agent: NodeMCU\r\n" + "Connection: close\r\n\r\n");
          Serial.println("Hodnoty do databazy uspesne odoslane");
          client.stop();
        } else {
          Serial.println("Pripojenie zlyhalo...");
        }
      }
      else {
        Serial.println("Vzdialenost medzi predmetom a senzorom je mimo rozsah.");
        delay(500);
      }
      for (int i = 0; i <= 300; i++) {
        delay(1000);
      }
    }
    

    GSM:

    #include <GSM.h<
    #include <NewPing.h<
    #define pinTrigger    3
    #define pinEcho       4
    #define maxVzdialenost 450
    NewPing sonar(pinTrigger, pinEcho, maxVzdialenost);
    // PIN Number
    #define PINNUMBER ""
    
    // APN data
    #define GPRS_APN       "GPRS_APN" // replace your GPRS APN
    #define GPRS_LOGIN     "login"    // replace with your GPRS login
    #define GPRS_PASSWORD  "password" // replace with your GPRS password
    
    GSMClient client;
    GPRS gprs;
    GSM gsmAccess;
    char server[] = "www.arduino.php5.sk";
    int port = 80; // port 80 is the default for HTTP
    
    void setup() {
      // initialize serial communications and wait for port to open:
      Serial.begin(9600);
      Serial.println("Starting Arduino web client.");
    
      boolean notConnected = true;
    
      // After starting the modem with GSM.begin()
      // attach the shield to the GPRS network with the APN, login and password
      while (notConnected) {
        if ((gsmAccess.begin(PINNUMBER) == GSM_READY) &
            (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) {
          notConnected = false;
        } else {
          Serial.println("Not connected");
          delay(1000);
        }
      }
    }
    
    void loop() {
      int vzdialenost = sonar.ping_cm();
      delay(50);
      if (vzdialenost > 0) {
        vzdialenost = 0;
        for (int i = 0; i < 5; i++) {
          vzdialenost += sonar.ping_cm();
          delay(50);
        }
        vzdialenost = vzdialenost / 5;
        Serial.print("Vzdialenost medzi senzorom a predmetom je: ");
        Serial.print(vzdialenost);
        Serial.println(" cm.");
      if (client.connect(server, 80)) {
        String hodnota = String(vzdialenost);
        Serial.println("Pripojenie uspesne na webserver, vykonavam request... ");
        client.print("GET /studna/data.php?hodnota=");
        client.print(hodnota);
        client.println(" HTTP/1.1");
        client.println("Host: www.arduino.php5.sk");
        client.println("Connection: close");
        client.println();
        Serial.println("Data uspesne odoslane na web");
        client.stop();
      } else {
        Serial.println("Pripojenie zlyhalo...");
      }
    }