Serial communication between nodemcu and Arduino Uno For the last days, I am trying to establish serial communication between nodemcu and Arduino Uno but I failed to do this. Currently, I am working on a Home Automation project. I receive data from nodemcu and send it to Arduino Uno, but some dummy data also receive with original data. Please help.
Nodemcu code:
#include &lt;ESP8266WiFi.h&gt;
#include &quot;Adafruit_MQTT.h&quot;
#include &quot;Adafruit_MQTT_Client.h&quot;

#define Automated   D0
#define Led         D1
#define Fan         D2

#define WLAN_SSID       &quot;JioFi2_1EAFF8&quot;
#define WLAN_PASS       &quot;Ode9c@,1S%31ja$1xANkeL&quot;

#define AIO_SERVER      &quot;io.adafruit.com&quot;
#define AIO_SERVERPORT  1883
#define AIO_USERNAME    &quot;_inishu&quot;
#define AIO_KEY        &quot;aio_HZUG00TupkcsC2dvraQM7HLHrCd4&quot;

WiFiClient client;
Adafruit_MQTT_Client mqtt(&amp;client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);

Adafruit_MQTT_Subscribe speed = Adafruit_MQTT_Subscribe(&amp;mqtt, AIO_USERNAME&quot;/feeds/Fan&quot;); 
Adafruit_MQTT_Subscribe inten = Adafruit_MQTT_Subscribe(&amp;mqtt, AIO_USERNAME &quot;/feeds/Led&quot;);
Adafruit_MQTT_Subscribe autom = Adafruit_MQTT_Subscribe(&amp;mqtt, AIO_USERNAME &quot;/feeds/Automate&quot;);

void MQTT_connect();
void datatransfer(int);


int on_off;
int sliderval1;
int sliderval2;
void setup(){
    Serial.begin(9600);
    pinMode(Automated, OUTPUT);
    pinMode(Led, OUTPUT);
    pinMode(Fan, OUTPUT);

    WiFi.begin(WLAN_SSID, WLAN_PASS);
    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
    }

    mqtt.subscribe(&amp;autom);
    mqtt.subscribe(&amp;speed);
    mqtt.subscribe(&amp;inten);
}


void loop (){
    MQTT_connect();

    Adafruit_MQTT_Subscribe *subscription;
    while ((subscription = mqtt.readSubscription(5000))){
        if (subscription == &amp;autom){
            on_off = atoi((char *)autom.lastread);
            if (on_off == 1)   digitalWrite(Automated,HIGH);
            if (on_off == 0)   digitalWrite(Automated,LOW);
        }
        
        if (subscription == &amp;speed){
            sliderval1 = atoi((char *)speed.lastread);
            analogWrite(Fan, sliderval1);
        }

        if (subscription == &amp;inten){
            sliderval2 = atoi((char *)inten.lastread);
            analogWrite(Led, sliderval2);
        }
    }
    datatransfer(on_off);
    datatransfer(sliderval1);
    datatransfer(sliderval2);
}


void MQTT_connect() {
    if (mqtt.connected()) {
         return;
    }
  
    while (mqtt.connect() != 0) {
        mqtt.disconnect();
        delay(2000);  
    }
}

void datatransfer(int value){
    Serial.println(value);
    delay(500);
} 

Arduino Uno code:
int x = A0, y = A1, z = 1;
int fan = 11, led = 10;
float temp, lux;
int autom = 1;
int inten = 0;
int speed = 0;
int fanspeed, light;

int datareceive(){
    int receiver = 0;
    while(Serial.available()==0 );
    String s = Serial.readStringUntil('\r');
    receiver = s.toInt();
    Serial.println(receiver);
    delay(1000);
    return receiver;
}
 
void setup(){
    Serial.begin(9600);
    pinMode(fan,OUTPUT);
    pinMode(led,OUTPUT);
    pinMode(x,INPUT);
    pinMode(y,INPUT);
    pinMode(z,INPUT);
}
 
void loop(){
    autom = datareceive();
    speed = datareceive();
    inten = datareceive();
    if(autom == 1){
        fanspeed = 255 - speed;
        light = 255 - inten;
        analogWrite(fan,fanspeed);
        analogWrite(led,light);
    }  
    else {
        temp = analogRead(x);
        if (temp &gt;= 52 &amp;&amp; temp &lt;= 104){
            int fanspeed = -4.90384615*temp + 510;
            analogWrite(fan, fanspeed);
        }
        else if(temp &gt; 104)  digitalWrite(fan,LOW);
        else digitalWrite(fan,HIGH);
        lux = analogRead(y);
        if (lux &gt;= 430 &amp;&amp; lux &lt;= 594){
            int light = 1.342657*lux-577.342657;
            analogWrite(led,light);
        }
        else if (lux &lt; 430) digitalWrite(led, LOW);
        else digitalWrite(led,HIGH);
    }
}
Arduino UNO is 5v logic and esp8266 is 3.3v logic.  You need a level shifter for them to be able to have bidirectional serial link.