How to send data from serial.println arduino mega to blynk

Please help.

How to display value from serial.println of the code to the blynk.

This is my code

#define A 22
#define B 23
#define C 24
#define D 25
int counter = 0;
int diam;
int akhir;
void setup() {
  pinMode(A, INPUT);
  pinMode(B, INPUT);
  pinMode(C, OUTPUT);
  pinMode(D, OUTPUT);
  Serial.begin(9600);
  akhir=digitalRead(A);}

void loop() {
    diam=digitalRead(A);
  if (diam!=akhir){
    if(digitalRead(B)!=diam){
      counter ++;
      }else{
        counter --;}
      Serial.print("Posisi :  ");
      Serial.println(counter);}

  int sensorValue = analogRead(A14);
  float volt = sensorValue*(5.00/1023.00);
  Serial.println (volt);
  if (volt>=4.01){
    digitalWrite(C, HIGH);}
    else if (volt <=3.82){
      digitalWrite(D,HIGH);}
      else {digitalWrite(C,LOW); digitalWrite(D,LOW);}
  delay(1);
  akhir=diam;}

This is my hardware.
-Arduino mega + esp8266
-Androi pie
-blynk

I want to display the value of serial.println (counter) and serial.println (volt) to blynk.

I have searched I just found the dht11 which use library to read the sensor.

I’ve edited your code so that it displays correctly. In future please format code correctly when posting, by adding three backticks at the beginning and end of the code.
Three backticks look like this:
```

You need to read this:

then modify your code accordingly.

Pete.

  1. You need to format your code as per the welcome message using 3 backticks (`)
    Edit: Thanks Pete

  2. If I understand you correctly, you just want to show the Serial.println in your Blynk app?

If so then add the following to your sketch. (Edit: After you have removed the code from void loop() and put it in a seperate function…)

Define a terminal widget:

WidgetTerminal terminal(V1);

Add this below the existing Serial.println(xxx); statement: (replace xxx with the variable you want todisplay - counter/volt)

Serial.println(counter);
terminal.println(counter);

Serial.println(volt);
terminal.println(volt);

And finally add the following to the ende of your function:

terminal.flush();
1 Like