Serial Communication Arduino-ESP32

Hi, I need some help. I am currently trying to display the parameters to the widget in Blynk. My current project is that my arduino is used to operate the sensors, i.e. ultrasonic sensors and etc. From arduino, i am using the serial communication to transfer the data from the arduino serial monitor to the esp32 module. The serial communication for distance is successful in the arduino IDE. Next step is to transfer the data to be displayed in Blynk through the esp32. I am able to make the device online.

However, the widget does not show what my serial monitor is displaying (distance measurement). This is the problem that i need clarification of. Below is my code.

#define BLYNK_TEMPLATE_ID "TMPL6J8E4vJUB"
#define BLYNK_TEMPLATE_NAME "Test1"
#define BLYNK_AUTH_TOKEN "xxxx"

#define BLYNK_PRINT Serial

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

#define RXp2 16
#define TXp2 17

char ssid[] = "iPhone";  
char pass[] = "Abc12345"; 

BlynkTimer timer;

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

  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
}
void loop() {
    Blynk.run();
    timer.run();

    if (Serial2.available()){
      String distanceStr = Serial2.readStringUntil('\n');
      int distance = distanceStr.toInt();

      Serial.println("Distance: ");
      Serial.println(distance);

      Blynk.virtualWrite(V1, distance);
  }

  delay(1000);
}

Why?
Why aren’t you attaching your sensors directly to the ESP32?

Also, it’s not clear if the screenshot of the serial monitor that you posted is from your Arduino or your ESP32.
BTW, posting screenshots of serial monitor output isn’t helpful. You’d be far better copying and pasting the serial monitor text and pasting it with triple backticks, the same way that you’ve posted your code. Including the full serial output from boot-up is also more useful than what you included in the screenshot.

You should also read this…

Pete.

Pete.

Because it is a group work in which i am in charge of the online monitoring system. The project is to develop an autonomous marine boat, whereby the one in charge of the autonomous navigation chose to operate sensors such as ultrasonic, magnetometer, motor driver and gps module which is operated by Arduino Mega. For my part, I have to display the parameters from the sensors in which i chose Blynk platform. Therefore, I am currently doing a testing on a single sensor which is connected to the Arduino Mega, then used serial communication to transfer the data from Arduino Mega to ESP32 serial. The screenshot provided was the serial monitor of ESP32 in Arduino IDE. the serial communication succeed.

the problem is now, when i want to display the parameters on Blynk, for which i would like to display the parameters from the serial monitor of the ESP32 like in the picture i have sent. I would like to know if it is possible or not, and can you verify my coding?

FikV.

Not quite sure why they’d use 13 year old technology for a task like that.

Possible - yes, ideal - no.

Did you read the link I provided?

How is your V1 datastream configured, and are the widgets 8n your screenshot attached to datastream V1?

Pete.