Water Level Horizontal Sensor Esp8266

Hello, i`m having some dificult put this working on Blynk, i dont understatend how configure the widgets i want use the Level V widget. How i define Pin.

#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp8266.h>
BlynkTimer timer;

char auth[]="....";
char ssid[]="....";
char pass[]="....";
int flagB=0;
int flagT=0;

void Buttonstate()
{
  int isBS = digitalRead(5);
  int isTS = digitalRead(4);
 
  if (isBS==1 && flagB==0){
    Serial.println("water level above the Bottom sensor");
    Blynk.virtualWrite(V1,1);
    Blynk.virtualWrite(V2,50);
    flagB=1;
  }
  else if (isBS==0 && flagB==1)
  {
  
    Serial.println("Lower than Bottom sensor");
    Blynk.notify("Lower than Bottom sensor");
    Blynk.virtualWrite(V1,0);
    Blynk.virtualWrite(V2,0);
    flagB=0;
  }

  
 if (isTS==1 && flagT==0){
    Serial.println("Water level above the Top sensor");
    Blynk.notify("Water level above the Top sensor");
    Blynk.virtualWrite(V0,1);
    Blynk.virtualWrite(V2,100);
    flagT=1;
  }
  else if (isTS==0 && flagT==1)
  {
  
    Serial.println("Lower than Top sensor");
    Blynk.virtualWrite(V0,0);
    Blynk.virtualWrite(V2,50);
    flagT=0;
  }
  
}

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);

pinMode(5, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);

  
Blynk.begin(auth, ssid, pass);
Blynk.virtualWrite(V0,0);
Blynk.virtualWrite(V1,0);
Blynk.virtualWrite(V2,0);
      

timer.setInterval(2000L,Buttonstate);

delay(1000);
}

void loop() {
  // put your main code here, to run repeatedly:
  Blynk.run();
  timer.run();
}

There is no pin definition statement needed in the code, simply do a Blynk.virtualWrite to the virtual pin that you’ve assigned to your Level V widget.

But, as far I can see from you current code and hardware setup the Level V widget isn’t going to tell you very much. Your sensors only tell you if the level is above or below the sensors at the top and bottom of the water level range.
If you wanted to have a Level vV widget that has say 10 steps from bottom to top to indicate the water level then you’d either need to have 10 sensors rather than 2, or use something like an ultrasonic measurement sensor to measure the distance to the surface of the water.

Pete.

Hello, thanks for the reply I want use 5 sensors, I’m following the of the guy in this video. Caixa de água, I managed to copy the code, but in the end give me a error.

Blockquote

exit status 1 ‘blinkLedWidget’ was not declared in this scope

Blockquote

/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************

  This sketch shows how to write values to Virtual Pins

  NOTE:
  BlynkTimer provides SimpleTimer functionality:
    http://playground.arduino.cc/Code/SimpleTimer

  App project setup:
    Value Display widget attached to Virtual Pin V5
 *************************************************************/

int sensor1 = 27;
int sensor2 = 26;
int sensor3 = 25;
int sensor4 = 33;
int sensor5 = 32;
int nivel, diferente;
int lersensor1, lersensor2, lersensor3, lersensor4, lersensor5;
int ant_sensor1, ant_sensor2, ant_sensor3, ant_sensor4, ant_sensor5;
String nivel_display; //Sobe ou Desce


#define BLYNK_PRINT Serial


#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <Blynk.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "F31oHir6Q4qt-xnKaJjUfKQ2Kndcz3jK";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Vodafone-26EFC3";
char pass[] = "74aYpEqGU8";
  
 WidgetLED led1(V16);
 WidgetLED led2(V15);
 WidgetLED led3(V14);
 WidgetLED led4(V13);
 WidgetLED led5(V12);

WidgetTerminal terminal(V3);
  
BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEvent()
{
 //    Serial.printIn (nivel);
//   Blynk.virtualWrite(V1, nivel);
}

void setup()
{
  // Debug console
  Serial.begin(9600);
  pinMode(sensor1, INPUT);
  pinMode(sensor2, INPUT);
  pinMode(sensor3, INPUT);
  pinMode(sensor4, INPUT);
  pinMode(sensor5, INPUT);



// digitalWrite (sensor1, HIGH);
// digitalWrite (sensor2, HIGH);
// digitalWrite (sensor3, HIGH);
// digitalWrite (sensor4, HIGH);
// digitalWrite (sensor5, HIGH);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

  // Clear the terminal content

  terminal.clear();
  terminal.println(F("Monitorização do Nivel de Água"));
  
  terminal.println(F("------------------------------"));

  terminal.println(F("Digite 'status' e receba os valores dos sensores"));

  terminal.flush();
  
  // Setup a function to be called every second
  timer.setInterval(1000L, myTimerEvent);
  nivel_display = "Desconhecido";
  timer.setInterval(1000L, blinkLedWidget);
}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
} 

You need to use triple backticks at the beginning and end of your code, not whatever characters you have used.

Please edit your code using the pencil icon at the bottom of the post and correct this problem.
Triple backticks look like this:
```

Pete.

This is calling the “void myTimerEvent” every second or 1000 millis.

So this

is trying to call a “blinkLedWidget” every second and there is none.

Thanks for your answer, In my case I only want the gauge widget, grafh, terminal, and notification when the level is lower of 20%. How I make to configure the gauge widget, the terminal is working. Thanks for the patience with me.

Today put all working with two sensors and Blynk working now try to change to work with 5.

When you have your 5 sensors connected, you will use your myTimerEvent() to read the state of each of the sensors in turn.
If I was writing this code I’d tart with the top sensor. If this is activated then there is no point in reading the other sensors, as you know that they too will be activated.
I assume you’ll assign a value of 5 to a water level variable if sensor 5 is activated. If sensor 5 is not activated you then move on to reading sensor 4, and if that is activated then you’ll assign a value of 4 and so on ?
Once you have the water level value the you’ll write this to the Level H widget’s virtual pin in Blynk.

Pete.

:wink: On the other hand if you check the next one down you could program a warning that a sensor is malfunctioning if there was a discrepancy. (Might if saved the 737 Max8)

1 Like

True, but as a newbie programmer with a project that (probably) won’t kill 346 people if one of the sensors goes faulty, then that’s an ‘icing on the cake’ type of feature.

A nice way to handle it might be to read each sensor and increment a counter by 1 for each sensor that is activated. The number you get should always match the number that you get doing it the other way, and if not then there’s a problem. Makes writing the ‘if’ statements a bit easier :crazy_face:

Pete.

Like this???

Serial.println("Reservatorio Cheio");
}
 
if ((sensor1 == 1) && (sensor2 == 1) && (sensor3 == 1) && (sensor4 == 1) && (sensor5 == 0)) {
Serial.println("Nivel de 100 a 75%");
}
 
if ((sensor1 == 1) && (sensor2 == 1) && (sensor3 == 1) && (sensor4 == 0) && (sensor5 == 0)) {
Serial.println("Nivel de 75 a 50%");
}
 
if ((sensor1 == 1) && (sensor2 == 1) && (sensor3 == 0) && (sensor4 == 0) && (sensor5 == 0)) {
Serial.println("Nivel de 50 a 25%");
}
 
if ((sensor1 == 1) && (sensor2 == 0) && (sensor3 == 0) && (sensor4 == 0) && (sensor5 == 0)) {
Serial.println("Nivel Critico");
}
 
if ((sensor1 == 0) && (sensor2 == 0) && (sensor3 == 0) && (sensor4 == 0) && (sensor5 == 0)) {
Serial.println("Reservatorio Vazio");
}```

this perhaps?

1 Like

Thanks in the tomorrow I gonna try.

Hello finally i have time and is working, next step, change time to read every 10 minuts, and understand about deepsleep.

#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp8266.h>
BlynkTimer timer;
char ssid[] = "Vodafone-26EFC3";
char pass[] = "74aYpEqGU8";
char auth[] = "P_DWvYmD01_tfa2xZGBIu2nylZlAV_ee";

int sensor1=0;
int sensor2=0;
int sensor3=0;
int sensor4=0;
int sensor5=0;

void reservatorio1()
{
  int sensor1 = digitalRead(5);
  int sensor2 = digitalRead(4);
  int sensor3 = digitalRead(14);
  int sensor4 = digitalRead(12);
  int sensor5 = digitalRead(13);

if (sensor5 == 1) 
{ 
Serial.println("Nivel de 100%");
Blynk.virtualWrite(V0,1);
Blynk.virtualWrite(V2,100);
} 
else if (sensor5 == 0 && sensor4 == 1) 
{ 
Serial.println("Nivel 80%");
Blynk.virtualWrite(V0,0);
Blynk.virtualWrite(V2,80);
} 
else if (sensor4 == 0 && sensor3 == 1) 
{ 
Serial.println("Nivel de 60%");
Blynk.virtualWrite(V0,0);
Blynk.virtualWrite(V2,60);
} 
else if (sensor3 == 0 && sensor2 == 1) 
{ 
Serial.println("Nivel de 40%");
Blynk.virtualWrite(V0,0);
Blynk.virtualWrite(V2,40);
} 
else if (sensor2 == 0 && sensor1 == 1)    
{
Serial.println("Nivel de 20%");
Blynk.notify("Nivel Baixo");
Blynk.virtualWrite(V0,0);
Blynk.virtualWrite(V2,20);
} 
if (sensor1 == 0) 
{ 
Serial.println("Nivel Crítico");
Blynk.notify("Crítico");
Blynk.virtualWrite(V1,0);
Blynk.virtualWrite(V2,0);
}
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);

pinMode(5, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(14, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
pinMode(13, INPUT_PULLUP);

  
Blynk.begin(auth, ssid, pass);
Blynk.virtualWrite(V0,0);
Blynk.virtualWrite(V1,0);
Blynk.virtualWrite(V2,0);
      
{
timer.setInterval(2000L,reservatorio1);
}

delay(1000);
}
void loop()

{
  // put your main code here, to run repeatedly:
  Blynk.run();
  timer.run();
}

Why the delay for 1 second at the end of your setup?

Video
https://youtu.be/2I-q7pXyHiQ
I now that the code is not perfect, and needing some clean and organized.

If you’re going to use deep sleep then you will need to totally restructure your code.
You need to break all of the regular Blynk rules, don’t use timers, and put everything in your void setup.

Here’s a good example of how to structure your Blynk code for deep sleep…

Pete.

Hello I find this in a articule made by you peteknight
And I gonna work with that.

The program flow should be something like this:

Try to connect to Wi-Fi a set number of times, with a short delay between each.
If not connected to Wi-Fi then go to sleep.
If connected to Wi-Fi then try to connect to Blynk.
If not connected to Blynk then go to sleep.
If connected to Blynk then take temperature readings.
Upload temperature readings to Blynk.
Go to sleep.