How i can send my data from nodemcu to arduino via serial?

I m basically taking values from mq6 sensor in nodemcu but i want to send those values to arduino too so that i can glow led and buzzer.. Problem : i m not able to send values and i tried some ways but its taking values but cannot store that value at arduino end.

NODEMCU:

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



char auth[] = "Q8vjsI42USrQ_GUYjD-wQKNWOadtF_8t";
char ssid[] = "JioFiber-4";
char pass[] = "Tithi@6884";

 
int mq6 = A0; 
int d = 0; 
void setup() 
{
  Serial.begin(9600);
  Serial1.begin(9600);   
  pinMode(mq6, INPUT);
  Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);

}
 
void loop() 
{

  Blynk.run();
  d = analogRead(mq6);
  Serial.println();
  Serial.print(d);
  Blynk.virtualWrite(V0, d);
  Serial1.println(String(d));
  if(d > 500){
    Blynk.logEvent("warning_leakage","Temp above 30 degree");
  }      
}

ARDUINO :

void setup() {
  //Serial Begin at 9600 Baud 
  Serial.begin(9600);
  Serial1.begin(9600);
}

void loop() {
  String d = Serial.write(Serial1);
  Serial.println(d);
  delay(0.00001);
}

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

Why not connect your LED and buzzer to the NodeMCU?

delay(0.00001)

What is the point on that?

store in String named "d" the result of the operation to SEND the RAM-adress of object "Serial1"

This doesn't make any sense
You wrote

This means your arduino code has to receive the data

modeMCU ----->----->-------"value of d"----->----->---Arduino

as d is an integer-value easiest way would be to
code for the arduino

void setup() {
  //Serial Begin at 9600 Baud 
  Serial.begin(9600);
  Serial1.begin(9600);
}

void loop() {
  int d = Serial1.parseInt();
  Serial.println(d);
  // a value of 100 means 
  // freeze microcontroller for 100 milliseconds 
  delay(100); 
}

both codes are very rudimentary
How about improving your code to show a senseful value instead of just the raw ADC-reading?

its saying serial1 was not declared in this scope
i have a doubt that i should make use of Serial or Serial1 for communication ?

i was just testing something else by mistake i forgot to change it.

You have not said which Arduino board you have

have a look at nodemcu-details-specifications which states
UART Pins NodeMCU/ESP8266 has 2 UART interfaces (UART0 and UART1) which provide asynchronous communication (RS232 and RS485), and can communicate at up to 4.5 Mbps. UART0 (TXD0, RXD0, RST0 & CTS0 pins) can be used for communication. However, UART1 (TXD1 pin) features only data transmit signal so, it is usually used for printing log.
you can therefore use hardware Serial port 1 pin TXD1 17 if just transmitting from the NodeMCU to an Arduino

if you require two way communication have a look at EspSoftwareSerial
the ESP8266 uses 3.3V logic - if connecting to a 5V logic Arduino use a potential divider on the Arduuino Tx to ESP8266 Rx line

Hi @tanishqc ,

the above communication was only medium effective.
You should post some more detail information:

1.) what exact type of arduino board are you using?

2.) what is the purpose of the arduino-board?
receiving some data is not a self-purpose I. assume that you want to do something with the received data in the arduino. So what is the final purpose of having the data inside the Arduino?

  • displaying the data on a display connected to the arduino?
  • using the arduino-IDE-serial-monitor to check the data?

best regards Stefan

UNO Rev 3

i need only one way communication i.e from nodemcu to arduino uno and i need to store the data which is being transmitted at arduino side so that i can use it for buzzer via using if conditions.

I am using Arduino Uno R3 board and in simple words i want to transfer my readings from nodemcu to my arduino so that i can use it for buzzer (alarm warning).

here is example code using a NodeMCU ESP8266 hardware serial1 pin D4 TXD1 17

// ESP8266 example using HardwareSerial library to transmit using Serial port 1 pins TXD1 17 (no RXD1) 

#define SERIAL_BAUD 38400

HardwareSerial* refSer;

void setup() {
  //Initialize serial port 0
  Serial.begin(115200);
  delay(2000);
  Serial.println("\nESP8266 HardwareSerial transmit test port 1 pin TXD1 17");
  //Initialize serial port 1
  refSer = new HardwareSerial(1);
  refSer->begin(SERIAL_BAUD, SERIAL_8N1);
}

void loop() {
  while (refSer->available() > 0) {
    uint8_t byteFromSerial = refSer->read();
    Serial.write(byteFromSerial);
  }
  while (Serial.available() > 0) {
    uint8_t byteFromSerial1 = Serial.read();
    Serial.write(byteFromSerial1);
    refSer->write(byteFromSerial1);
  }
}

just tested the above code connected to a UNO running SoftwareSerial RX is pin 2 worked OK transmitting from NodeMCU to UNO

could give some more explanation in detail that would be helpful for me to understand.

Serial.begin(9600); on both sides of the serial connection between nodeMCU and Arduino-Uno

Anyway: If your nodeMCU has a free IO-pin you can make the buzzer buzz with the nodeMCU-IO-pin.

Why do you need to add the Arduino-Uno? Does the Arduino-Uno do more things than buzzing the buzzer?

Are all IO-pins on your nodeMCU connected to LEDs, sensors, displays etc?
best regards Stefan

i need to use IO pins for leds and etc so thats why i want to make it buzz from arduino side

what did you code on the arduino side may i know? It would be helpful for me

this was the UNO code

/* Software serial multple serial test

 on the UNO circuit is:
 * RX is digital pin 2 (connect to TX of other device)
 * TX is digital pin 3 (connect to RX of other device)

// Note: UNO uses 5V logic 
//   - if connecting the 3.3V logic use a voltage divider 2.2K to ground 1K to UNO Tx

 Note uses interrupts on pin:
 Not all pins on the Mega and Mega 2560 support change interrupts,
 so only the following can be used for RX:
 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69

 Not all pins on the Leonardo and Micro support change interrupts,
 so only the following can be used for RX:
 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).

 */
#include <SoftwareSerial.h>

const byte rxPin = 2;
const byte txPin = 3;

// Set up a new SoftwareSerial object
SoftwareSerial mySerial (rxPin, txPin);

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  Serial.println();
  Serial.println("SoftwareSerial test");
  // set the data rate for the SoftwareSerial port
  mySerial.begin(38400);
  mySerial.println("Hello, world?");
}

void loop() { // run over and over
  if (mySerial.available()) {
    Serial.write(mySerial.read());
  }
  if (Serial.available()) {
    mySerial.write(Serial.read());
  }
}

NodeCMU pin D4 (17 GPIO2 TXD1) for pinout see nodemcu-pinout-and-esp-12e-pinout) connected directly to UNO pin 2

@StefanL38


Here you have it I have mentioned the key details and what do i want...