How can I transfer data from Arduino mega 2560 to ESP8266

Hello, I need some help with my transferring sensor data using Robodyn Arduino mega with esp8266 built-in.

Arduino Code DIP Switch 3/4ON

#include <BH1750FVI.h>
BH1750FVI LightSensor(BH1750FVI::k_DevModeContLowRes);

#include <OneWire.h>
#include <DallasTemperature.h>
#define temppin 22
OneWire oneWire(temppin);
DallasTemperature tempsensor(&oneWire);
DeviceAddress airtemp = { 0x28, 0xAA, 0x5A, 0x3C, 0x4A, 0x14, 0x01, 0x2D };
DeviceAddress soiltemp = { 0x28, 0xDE, 0x57, 0x97, 0x10, 0x20, 0x01, 0xBF };

int humidPin = 0; 
String msg;
-------------------------------------------------------------------------------------------------------
void setup()
{
Serial.begin(115200);
Serial3.begin(115200);
}
 
void loop(){
  uint16_t lightval = LightSensor.GetLightIntensity();
 
  tempsensor.requestTemperatures();
  air = tempsensor.getTempC(airtemp);
  soil = tempsensor.getTempC(soiltemp);
  
  int sensorValue = analogRead(A0);
  humid = analogRead(humidPin);

  msg = "";
  msg += "Coming from arduino";
  msg += light;
  msg += ",";
  msg += air;
  msg += ",";
  msg += soil;
  msg += ",";
  msg += humid;

  Serial3.println(msg);

ESP8266 CODE DIP SWITCH 5/6/7 ON

void setup() {
  Serial.begin(115200);
  while(!Serial){
    
  }
}

void loop() {
  if(Serial.available()){
Serial.write(Serial.read());
    }

}

After making them connected (DIP SWITCH 1/2/3/4 ON) I got nothing in the serial monitor.

you print nothing to Serial or the code is incomplete

Juraj:
you print nothing to Serial or the code is incomplete

I have printed a string to it. I test it by changing Serial3.print(msg) to Serial.print(msg); then I got sensor data in Mega serial monitor

in your post the end of the sketch is missing

Juraj:
in your post the end of the sketch is missing

#include <BH1750FVI.h>
BH1750FVI LightSensor(BH1750FVI::k_DevModeContLowRes);

#include <OneWire.h>
#include <DallasTemperature.h>
#define temppin 22
OneWire oneWire(temppin);
DallasTemperature tempsensor(&oneWire);
DeviceAddress airtemp = { 0x28, 0xAA, 0x5A, 0x3C, 0x4A, 0x14, 0x01, 0x2D };
DeviceAddress soiltemp = { 0x28, 0xDE, 0x57, 0x97, 0x10, 0x20, 0x01, 0xBF };
int air = 0;
int soil = 0;
int humidPin = 0; 
int humid = 0;

String msg;

void setup()
{
Serial.begin(115200);
Serial3.begin(115200);
LightSensor.begin();
tempsensor.begin();
delay(1000);
}
 
void loop(){
  //LIGHT
  uint16_t lightval = LightSensor.GetLightIntensity();
  //TEMP
  tempsensor.requestTemperatures();
  air = tempsensor.getTempC(airtemp);
  soil = tempsensor.getTempC(soiltemp);
  //humid
  int sensorValue = analogRead(A0);
  humid = analogRead(humidPin);
  
  msg = "";
  msg += "Coming from arduino";
  msg += light;
  msg += ",";
  msg += air;
  msg += ",";
  msg += soil;
  msg += ",";
  msg += humid;
  //Serial.println(msg);
  Serial3.println(msg);
  delay(15000);
}

ESP8266

void setup() {
  Serial.begin(115200);
  while(!Serial){
    
  }
}

void loop() {
  if(Serial.available()){
Serial.write(Serial.read());
    }

}

This is all the code :slight_smile:

so you send a message to esp8266 on Serial3 and esp8266 echos it, but the ATmega doesn't copy Serial3 input to Serial