Blynk 2.0 can't read and send the data from Rx and Tx (Serial Communication)

I am using Arduino Uno to read data from the sensor and transfer the data to my esp8266 by using Rx and Tx pin, there is no problem with serial communication. But I got problems reading and sending data from Blynk 2.0 for the data stream. Plus, I’m newbie to Blynk. Thank you in advance.

#define BLYNK_TEMPLATE_ID "xxx"
#define BLYNK_TEMPLATE_NAME "xxx"
#define BLYNK_AUTH_TOKEN "xxx"

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

//arduino-nodemcu data transfer lib
#include<SoftwareSerial.h>
#include<ArduinoJson.h>

// wifi details
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "xxx";
char pass[] = "xxx";

//D2=Rx & D1=Tx
SoftwareSerial arduino(D2,D1);

bool RED_status = true;
bool GREEN_status = true;
bool PIR1_status = true;
bool PIR2_status = true;


BLYNK_WRITE(V1){
  digitalWrite(RED_status, param.asInt());
}

void send_data() {
 StaticJsonBuffer<1000> jsonBuffer;
 JsonObject& data = jsonBuffer.parseObject(arduino);

 if (data == JsonObject:: invalid ()){
  Serial.println("Invalid JSON Object");
  jsonBuffer.clear();
  return;
 }

 Serial.println("JSON object received");
 Serial.print("RED status: ");
 bool RED_status= data["RED_status"];
 Serial.print(RED_status);
 Serial.print(" ,Motion status: ");
 bool PIR1_status= data["PIR1_status"];
 Serial.println(PIR1_status);
 
 Serial.print("GREEN status: ");
 bool GREEN_status= data["GREEN_status"];
 Serial.print(GREEN_status);
 Serial.print(" ,Motion status: ");
 bool PIR2_status= data["PIR2_status"];
 Serial.println(PIR2_status);

 Serial.print("Light status: ");
 double sensorValue= data["Light_status"];
 Serial.println(sensorValue);
 Blynk.virtualWrite(V0, sensorValue);
 Serial.println("----------------------------------------------");
}

void setup() {

  // initialize Serial Port
  Serial.begin(9600);
  arduino.begin(9600);
  while(!Serial) continue;
  Blynk.begin(auth,ssid,pass, "blynk.cloud",8080);
}

void loop(){
 send_data(); 
 Blynk.run(); 
}

You need to transfer the data using the D1 and D2 pins, because that’s what you’ve told your sketch to use…

But using this hardware setup is total madness.
You should either use the ESP8266 based board (presumably a NodeMCU?) to do everything, or use an ESP32 if you need more analog ports than the NodeMCU has.

Pete.

1 Like