How to change Blynk widget box "value display" from 0 and 1 sensor value to wordings like "rain" or "not rain"

Hi all,
How are you guys doing? I’m DIni am working on my school project. I am new to this Blynk IoT architecture. I want to do a rain detector that can be checked from smart phone using Blynk application. Right now I manage to make it work and get the output display on the Blynk app using widget box “value display”. It display output 0 and 1 only. However, I want the app to display “ITS RAINING” and “NOT RAINING”.

Can you please advise me on how to change the Blynk apps output 0 and 1 to wordings like above?

Thank you,
Dini

• Hardware model : NODEMCU ESP8266 with WIFI
• Smartphone : IOS
• Blynk server
• Blynk Library version : 0.6.1.


#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>


LiquidCrystal_I2C lcd(0X27,16,2);
// PIN D1 TO D3
int RAINSENSOR = D3;
int sensorData;

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

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

BlynkTimer timer; // Announcing the timer

void myTimerEvent()
{
      sensorData = digitalRead(D3);
      Blynk.virtualWrite(V5, sensorData);
}

void setup()
{
  pinMode(RAINSENSOR, INPUT);
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000L, myTimerEvent);
}

void loop()
{
    Blynk.run();
    
    lcd.begin();
    if (0 == digitalRead(RAINSENSOR)) 
    {
      lcd.print("ITS RAINING!!! ");
    } else
    {
     lcd.print("NOT RAINING");
    }
    
    timer.run(); // running timer every second
}

If I am not wrong you have V5 virtual pin preset for that purpose? If yes then your myTimerEvent() should be revised as follows:

void myTimerEvent()
{
      sensorData = digitalRead(D3);
      if (sensorData == 0) Blynk.virtualWrite(V5, "ITS RAINING");
      else Blynk.virtualWrite(V5, "NOT RAINING");
}
1 Like

Hi dunghnguyen,
I’ve done the changes according to your suggestion. However it display like this below image. When I run the app, when there is no rain, it just display “NO…” and when there is a rain, it display “ITS…”;

How to make it display full wording? Appreciate your advise.

Thank you,
Dini

Maybe resize the widget?

Pete.

Hi Pete,
I had tried to change the text size to the smallest text size. It seems you are right, however I need to make the display box bigger so that it can display the full wording. Can you guide me how to do that?

Thank you in advance,
Dini

Your screenshot is Edit mode. Yes you could adjust it … just tap and hold till its edge appeared then tap / hold on the edge to resize as you want. Hope this helps.

Yes, a long press on the widget will bring-up the “handles” that allow you to resize it. This is what it looks like on iOS:

image

Pete.

Oh… don’t get me started on the great fonticide issue, where we “used” to have actual auto scaling fonts that just FIT!

3 Likes

Thank you dunghnguyen and pete I managed to follow your guidance and instructions and work as I want it to be. Thank you again.

2 Likes