Special Characters LCD Ultrasonic Sensor Widget

Guys I need your help. I’m building a fuel level sensor with the ultrasonic sensor. The code I wrote works well, but instead of the “numbers in CM” I would like to make it appear on the virtual display of special characters as a full notch and empty notch based on a maximum of 90Cm all empty notches, 0 all full notches
I enclose code to figure out where I’m wrong. I’m mistaken when I compile on line 60

I apologize for my English and bad writing code, but I’m at the beginning.

#define BLYNK_PRINT Serial
#include <LiquidCrystal.h>
//CREAZIONE DEI DUE CARATTERI SPECIALI: Carattere Tacca Piena e Tacca Vuota
byte TaccaPiena[8] = //RIQUADRO PIENO (TACCA PIENA)
{
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
}; // Array 8x5 bit per la definizione di un singolo carattere

byte TaccaVuota[8] = //RIQUADRO VUOTO (TACCA VUOTA)
{
  B11111,
  B10001,
  B10001,
  B10001,
  B10001,
  B10001,
  B10001,
  B11111
};

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define triggerPort D1
#define echoPort    D2

long r ; //variabile distanza

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

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "lxxxxxxxxx";
char pass[] = "xxxxxxxxx";

WidgetLCD lcd(V1);

void setup()
{
  // Debug console
  Serial.begin(9600);
  pinMode( triggerPort, OUTPUT );
  pinMode( echoPort, INPUT );
  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);

  
  lcd.clear(); //Use it to clear the LCD Widget
  lcd.createChar(0, TaccaPiena);
  lcd.createChar(1, TaccaVuota);
  lcd.print(0, 0, "Liv.Combustibile"); // ASSEGNAZIONE SCRITTA PRIMA RIGA use: (position X: 0-15, position Y: 0-1, "Message you want to print")
  // Please use timed events when LCD printintg in void loop to avoid sending too many commands
  // It will cause a FLOOD Error, and connection will be dropped
}

void loop() {
  lcd.clear();
  lcd.print(0, 0, "Liv.Combustibile"); // ASSEGNAZIONE SCRITTA PRIMA RIGA use: (position X: 0-15, position Y: 0-1, "Message you want to print")

  digitalWrite( triggerPort, LOW );   //porta bassa l'uscita del trigger
  digitalWrite( triggerPort, HIGH );    //invia un impulso di 10microsec su trigger
  delayMicroseconds( 10 );
  digitalWrite( triggerPort, LOW );
  long duration = pulseIn( echoPort, HIGH , 10000 ); // 10000 µS = max circa 1,7 metr1
  r = 0.034 * duration / 2;





  
  Serial.print(r);
  Serial.println("Cm");
  
  if ( r > 0 ) {
    lcd.setCursor(0, 1);
    lcd.print("                ");
    int x = map(r, 12, 90, 15, 0);
    for (int i = 0 ; i <= x ; i++ ) {
      lcd.setCursor(i, 1);
      lcd.write(byte(0));
    }
    for (int i = 15 ; i > x ; i-- ) {
      lcd.setCursor(i, 1);
      lcd.write(byte(1));
    }
    if (r >= 90) {     
      for (int i = 0 ; i < 6 ; i++) {


  
  lcd.print(0, 1, r); // ASSEGNAZIONE SCRITTA SECONDA RIGA
  Blynk.run();

  

  delay(3500);

}

The LCD widget is basic ASCII character set only, no graphics or special character bitmapping.

but you could just use the level indicator widget, or gauge widget, they do exactely what you need, and also have very nice design.

It could be an idea. What do you suggest me?

screenshot (1)
the character and type of this, according to you recognize it?

What you are showing looks like a “normal” physical 2x16 LCD… those will work fine for custom characters and rudimentary graphics… but I thought you were asking about the LCD Widget, which as far as I know will NOT display such custom characters.

As @wanek suggested, use the Level Widget instead, either with an LCD Widget:

image

or even just a Display and Level Widget:

image

Great. I like a lot the second option. Give me a hand with the code.

http://docs.blynk.cc/#widgets-displays-labeled-value

http://docs.blynk.cc/#widgets-displays-level-display

http://docs.blynk.cc/#blynk-firmware-virtual-pins-control-blynkvirtualwritevpin-value

Ok I changed the code and this is the result.


but I do not know how to read the values of the label to the contrary.
Es.
5 cm = 100%
90 cm = 0%

in practice when the blue bar is full 100% label, when the blue bar is empty label 0%

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define triggerPort D1 //pin NodeMCU
#define echoPort    D2 //pin NodeMCU

long r ; //variabile distanza

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

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxxxx";
char pass[] = "xxxxxxxx";


void setup()
{
  // Debug console
  Serial.begin(9600);
  pinMode( triggerPort, OUTPUT );
  pinMode( echoPort, INPUT );
  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
 
}

void loop() {
  
  
  digitalWrite( triggerPort, LOW );   //porta bassa l'uscita del trigger
  digitalWrite( triggerPort, HIGH );    //invia un impulso di 10microsec su trigger
  delayMicroseconds( 10 );
  digitalWrite( triggerPort, LOW );
  long duration = pulseIn( echoPort, HIGH , 10000 ); // 10000 µS = max circa 1,7 metri
  r = 0.034 * duration / 2;

  Blynk.virtualWrite(V0, r); //Virtual Pin Label
  Blynk.virtualWrite(V1, r); //Virtual Pin 

  Blynk.run();



}

It defaults to 0-100 but you can set your desired range in the Level Widget accordingly.

image

And we might as well get this other part dealt with… you shouldn’t have all those Digital and Virtual writes directly in the void Loop() as they are trying to process hundreds/thousands of times a second… use timed functions instead.

http://help.blynk.cc/getting-started-library-auth-token-code-examples/blynk-basics/how-to-display-any-sensor-data-in-blynk-app

the timer speech seems correct I just have to figure out how to apply it to the code.
Instead, I’ve set the label for the label as you told me but it does not change anything

Added the timer function to 5 seconds. How do you feel?

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define triggerPort D1 //pin NodeMCU
#define echoPort    D2 //pin NodeMCU

long r ; //variabile distanza

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

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxxxxxx";
char pass[] = "xxxxxxxx";

BlynkTimer timer;

void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V0, r); //Virtual Pin Label
  Blynk.virtualWrite(V1, r); //Virtual Pin Level H
}
void setup()
{
  // Debug console
  Serial.begin(9600);
  pinMode( triggerPort, OUTPUT );
  pinMode( echoPort, INPUT );
  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
  
  timer.setInterval(5000L, myTimerEvent);
}

void loop() {
  
  
  digitalWrite( triggerPort, LOW );   //porta bassa l'uscita del trigger
  digitalWrite( triggerPort, HIGH );    //invia un impulso di 10microsec su trigger
  delayMicroseconds( 10 );
  digitalWrite( triggerPort, LOW );
  long duration = pulseIn( echoPort, HIGH , 10000 ); // 10000 µS = max circa 1,7 metri
  r = 0.034 * duration / 2;
  
  
  

  /*
  Adessso sono disattivate
  //Notiche allerta
  if ( r > 10) {
  Blynk.notify("ALLERTA COMBUSTIBILE CALDAIA!!!  IL LIVELLO DI COMBUSTIBILE DELLA CALDAIA E' BASSO");
  Blynk.email("xxxxxxxxx@gmail.com","ALLERTA COMBUSTIBILE CALDAIA","IL LIVELLO DI COMBUSTIBILE DELLA CALDAIA E' BASSO");
}*/

  Blynk.run();
  timer.run(); // Initiates BlynkTimer
  



}

I solved it with the inverted value for the label

Blynk.virtualWrite(V0, 90-r); //Virtual Pin Label

after solving the software problems now there is a nice hardware problem. Virtually once the ultrasonic sensor is positioned when the lid is closed, the signal blinks on the grid and consequently can not read the bottom of the tank. I had thought about cutting a little grid so as to create a square so the sensor can not find any obstacles. What do you think ???

Ultrasonics will not be able to differentiate between this side or that side of a grid, so, yes, you will need clear “line of sight/sound”. Either by cutting the grid, or positioning the sensor directly on the grid with no obstructions for either of the round sections (and that way you can also lift the lid to confirm/compare visual and sensor data).

1 Like

I got this on amazon who knows if it improves the situation

Sharp Sensor

IR (Infrared) light may tend to be absorbed by many liquids, so it may not be the best option. What is wrong with using the Ultrasonic?

the problem is not so much fuel is solid non-liquid. For the ultrasonic sensor there is the eco problem as a container

1 Like

Guys do you because the ultrasonic sensor seems crazy.
With the almost empty tank I always read the same value, instead with the tank almost full law random value and from time to time reads the real value

Are you still running the ultrasonic sensor with the grate in between it and the solid fuel?