See in blink what I see in my physical lcd

Hi, I have a code running ok, running on an Arduino Nano, an LCD 0802a and an Ultrasonic sensor Hc-sr04.
I want to see on my phone with blynk what I currently see on LCD 0802a.
What widget should I use?
Value Display?
Labeled Value?
LCD?

I have tried with Blynk.virtualWrite but I have not managed to use my variables already with loaded data to be able to show them

Help please!

Do you have a connection interface? WiFi or Ethernet? Or want to use USB?

You can use any of those.

Can you share with us what you have tried?

Hi ldb, thank you for answering me, I forgot to clarify that I am connected to blynk by wifi and everything works ok, I did simple tests that have nothing to do with my code and it works very well, for example, turning on and off led and other tests.

But I can not make the variables that I already have with data send them that I see in my physical LCD, show them in one of the widgets.

It will be hard to help without your code

Ok post my code:


// Coneccion wifi + BLYNK
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#define BLYNK_PRINT Serial
#define BLYNK_DEBUG
char auth[] = "xxxxxxxxxxxxxxxxxx";
char ssid[] = "xxxxxxxxxxxxxxxxxx";
char pass[] = "xxxxxxxxxxxxxxxxxx";


 // formateo la coneccion AT con el ESP8266
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX
#define ESP8266_BAUD 57600
ESP8266 wifi(&EspSerial);


// DISPLAY 0802a
#include <LiquidCrystal.h>
const int rs = 4, en = 5, db4 = 6, db5 = 7, db6 = 8, db7 = 9;
LiquidCrystal lcd(rs, en, db4, db5, db6, db7);
#define COLS 8 
#define ROWS 2 

// SENSOR DE AGUA
const int PinTrig = 10;
const int PinEcho = 11;
const float VelSon = 34000.0;
const int numLecturas = 10; //lo baje a 10 para pruebas ponerlo a 100.
const float distancia100 = 10;
const float distanciaVacio = 148;
float lecturas[numLecturas]; // Array para almacenar lecturas
int lecturaActual = 0; // Lectura por la que vamos
float total = 0; // Total de las que llevamos
float media = 0; // Media de las medidas
bool primeraMedia = false; // Para saber que ya hemos calculado por lo menos una

void setup()
{
  // Iniciamos el monitor serie para mostrar el resultado
  Serial.begin(57600);
  delay(10);
  
  // Set ESP8266 baud rate para la WIFI
  EspSerial.begin(ESP8266_BAUD);
  delay(10);
  
  // Ponemos el pin Trig en modo salida
  pinMode(PinTrig, OUTPUT);
  // Ponemos el pin Echo en modo entrada
  pinMode(PinEcho, INPUT);

  // Inicializamos el array
  for (int i = 0; i < numLecturas; i++)
  {
    lecturas[i] = 0;
  }

  // Configuramos las filas y las columnas del LCD en este caso 8 columnas y 2 filas
  lcd.begin(COLS, ROWS);
  
  // Mandamos al Blynk
  Blynk.begin(auth, wifi, ssid, pass);
  
}
void loop()
{
  // Eliminamos la última medida
  total = total - lecturas[lecturaActual];

  iniciarTrigger();

  // La función pulseIn obtiene el tiempo que tarda en cambiar entre estados, en este caso a HIGH
  unsigned long tiempo = pulseIn(PinEcho, HIGH);

  // Obtenemos la distancia en cm, hay que convertir el tiempo en segudos ya que está en microsegundos
  // por eso se multiplica por 0.000001
  float distancia = tiempo * 0.000001 * VelSon / 2.0;

  // Almacenamos la distancia en el array
  lecturas[lecturaActual] = distancia;

  // Añadimos la lectura al total
  total = total + lecturas[lecturaActual];

  // Avanzamos a la siguiente posición del array
  lecturaActual = lecturaActual + 1;

  // Comprobamos si hemos llegado al final del array
  if (lecturaActual >= numLecturas)
  {
    primeraMedia = true;
    lecturaActual = 0;
  }

  // Calculamos la media
  media = total / numLecturas;

  // Solo mostramos si hemos calculado por lo menos una media
  if (primeraMedia)
  {
    float distanciaLleno = distanciaVacio - media;
    float cantidadLiquido = distanciaLleno * 100 / distancia100;
    int porcentaje = (int) (distanciaLleno * 100 / distanciaVacio);

    // Mostramos en la pantalla LCD
    lcd.clear();
    
    // Cantidada de líquido
    lcd.setCursor(0, 0);
    // Formatie de ml a Litros
    //lcd.print(String (cantidadLiquido) + " ml");
    lcd.print(String (int (cantidadLiquido)) + " Lit");
    
    // Porcentaje
    lcd.setCursor(0, 1);
    lcd.print(String(porcentaje) + " % Car");


   // Mostramos en el Monitor
    Serial.print(media);
    Serial.println(" cm");
    Serial.print(cantidadLiquido);
    Serial.println(" ml");
  }
  else
  {
    lcd.setCursor(0, 0);
    lcd.print("Calc: " + String(lecturaActual));
  }
  delay(500);
  Blynk.run();
  
}

//////////////////////////////////////////////////////////////////////
// Método que inicia la secuencia del Trigger para comenzar a medir //
void iniciarTrigger()
{
  // Ponemos el Triiger en estado bajo y esperamos 2 ms
  digitalWrite(PinTrig, LOW);
  delayMicroseconds(2);

  // Ponemos el pin Trigger a estado alto y esperamos 10 ms
  digitalWrite(PinTrig, HIGH);
  delayMicroseconds(10);

  // Comenzamos poniendo el pin Trigger en estado bajo
  digitalWrite(PinTrig, LOW);
}

On your code you’re not sending data to Blynk.

I would suggest to create a timer and send data to Blynk, this example has it all: Push Data Example

An you send it as you print to LCD, for example: Blynk.virtualWrite(VX, String(lecturaActual)); or Blynk.virtualWrite(VX, String(porcentaje) + " % Car");

did yo run your app without any disconnection?
I think your loop will flood server.
:wink:

Actually won’t, it’s not sending data to Blynk

Well it was what I had tried without understanding the code, but now I could do it and put only this and it works into de void loop:



// Mostramos en los label value del blynk
    Blynk.virtualWrite(V2, String(cantidadLiquido));
    Blynk.virtualWrite(V3, String(porcentaje));

But is it okay or am I doing something wrong, even though it works for me?

@Blynk_Coeur now he will :smile:

@Gaston_Fernando_Mart as mentioned before you should put those routines inside a timer otherwise the board will send several data too frequent causing disconnections check this link http://docs.blynk.cc/#troubleshooting-flood-error

1 Like

yes :smile:

jajaja, ok now part of my new code:

//Preparo Variables labels del blynk
BlynkTimer timer;
void myTimerEvent()
{
  if (primeraMedia)
  {
    float distanciaLleno = distanciaVacio - media;
    float cantidadLiquido = distanciaLleno * 100 / distancia100;
    int porcentaje = (int) (distanciaLleno * 100 / distanciaVacio);  
    Blynk.virtualWrite(V2, String(cantidadLiquido));
    Blynk.virtualWrite(V3, String(porcentaje) + " % Car");
  }
  else
  {
    Blynk.virtualWrite(V2,"Calc: " + String(lecturaActual));
  }
}

But in my old code, in the void () loop I still have a delay (500); and I do not know how to change it because I will also be penalized with high delay.
My code into void loop ir big ( is part of view my lcd fisic).

ok there send all the code out of the void loop();
remove the delay and place everything inside:
BlynkTimer timer;
void myTimerEvent ()
It works correctly and the void loop was clean.

Thank you very much! to Alexis_Cabrera and ldb.:smiley:

2 Likes