BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Blynk can't display data from serial monitor

For my project, I need to create a mobile based automatic pH concentration and meter.
I tried uploading the code before and the serial monitor displays the right output. Then, I proceed to add some coding to connect them with Blynk app. But, the lcd widget in Blynk app can’t display the pH meter (the readings from the serial monitor). May I know where did it went wrong?

The components that I used in my project is:
Hardware: ESP32, pH sensor probe

#define SensorPin V5 
#define BLYNK_PRINT Serial
#include <stdlib.h>
#include <SoftwareSerial.h>
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEsp32.h>

char auth[] = "T-DU0SRXD3AB3HaqSmsQgN9GByytJYyU";
char ssid[] = "jaydina@unifi";
char pass[] = "2BIXI7fo1L";

WidgetLCD lcd(V5);

SoftwareSerial nodemcu(2,3);
unsigned long int avgValue;  
float b;
int buf[10],temp;
 
int f;
float val; 
char buff2[10];
String valueString = "";
String Value = "";  

void setup()
{
  pinMode(13,OUTPUT);  
  Serial.begin(9600);  
  nodemcu.begin(9600); 
  Blynk.begin(auth, ssid, pass);
  lcd.clear(); 
  lcd.print(3, 0, "pH meter is"); 
  lcd.print(6, 1, Value);
}

void loop()
{
  Blynk.run();
  for(int i=0;i<10;i++)       //Get 10 sample value from the sensor for smooth the value
  { 
    buf[i]=analogRead(SensorPin);
    delay(10);
  }
  for(int i=0;i<9;i++)        //sort the analog from small to large
  {
    for(int j=i+1;j<10;j++)
    {
      if(buf[i]>buf[j])
      {
        temp=buf[i];
        buf[i]=buf[j];
        buf[j]=temp;
      }
    }
  }
  avgValue=0;
  for(int i=2;i<8;i++)                      //take the average value of 6 center sample
    avgValue+=buf[i];
  float phValue=(float)avgValue*5.0/1024/6; //convert the analog into millivolt
  phValue=3.5*phValue;                      //convert the millivolt into pH value
  Value =  dtostrf(phValue, 4, 2, buff2);  //4 is mininum width, 6 is precision
  valueString = valueString + Value +","; 
  Serial.println(valueString);
  nodemcu.println(valueString);
  valueString = "";
  delay(1000); 

@miyahh please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

I’d suggest that you go back to your original code, then take a look at the sketch builder examples for ESP32 here:
https://examples.blynk.cc/?board=ESP32&shield=ESP32%20WiFi&example=GettingStarted%2FBlynkBlink

When you add the Blynk related libraruies and code into your sketch try to structure these additions in an organised way, starting you code with the Blynk libraries like this:

// Libraries needed for Blynk...
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

// Your other libraries in here...


Credentials needed for Blynk...
char auth[] = "YourAuthToken";
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";

// Your variable declarations in here...

You also need to read this, and restructure your code accordingly…

You don’t need to use SoftwareSerial in your sketch, and data isn’t written to Blynk using nodemcu.println(valueString);
You’ve declared an object called lcd to represent the Blynk LCD widget:

WidgetLCD lcd(V5);

You then write to this object with:

lcd.print(x position, y position,valueString);

However, for this type of project I’d probably use a Labelled Value widget and write to it directly with:

Blynk.virtualWrite(V5, valueString);

Pete.