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

**URL:** <https://forum.arduino.cc/t/how-i-can-send-my-data-from-nodemcu-to-arduino-via-serial/1070152>\
**Category:** Programming\
**Created:** [December 27, 2022, 6:41pm UTC](https://forum.arduino.cc/t/how-i-can-send-my-data-from-nodemcu-to-arduino-via-serial/1070152 "2022-12-27T18:41:31Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![tanishqc](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@tanishqc](https://forum.arduino.cc/u/tanishqc)\
**Post date:** [December 27, 2022, 6:41pm UTC](https://forum.arduino.cc/t/how-i-can-send-my-data-from-nodemcu-to-arduino-via-serial/1070152/1 "2022-12-27T18:41:31Z")

</div>

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:

```cpp
#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 :

```cpp
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);
}

```

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [December 27, 2022, 6:43pm UTC](https://forum.arduino.cc/t/how-i-can-send-my-data-from-nodemcu-to-arduino-via-serial/1070152/2 "2022-12-27T18:43:51Z")

</div>

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)&nbsp;to make it easier to read and copy for examination

> [@How to get the best out of this forum](https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966):
>
> See also [FAQ - Arduino Forum](https://forum.arduino.cc/faq) for general rules on forum behaviour and etiquette. Hello, Welcome to the Arduino Forum. This guide explains how to get the best out of this forum. Please read and follow the instructions below. Being new here you might think this is having rules for the sake of rules, but that is not the case. If you don’t follow the guidelines all that happens is there is a long exchange of posts while we try to get you to tell us what we need in order to help you, which is fru…

---

<div class="post-metadata">

**Author:** ![ryancasler](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ryancasler/32/1109959_2.png) [@ryancasler](https://forum.arduino.cc/u/ryancasler)\
**Post date:** [December 27, 2022, 6:45pm UTC](https://forum.arduino.cc/t/how-i-can-send-my-data-from-nodemcu-to-arduino-via-serial/1070152/3 "2022-12-27T18:45:25Z")

</div>

Why not connect your LED and buzzer to the NodeMCU?

---

<div class="post-metadata">

**Author:** ![Proietti](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/proietti/32/1129187_2.png) [@Proietti](https://forum.arduino.cc/u/Proietti)\
**Post date:** [December 27, 2022, 8:27pm UTC](https://forum.arduino.cc/t/how-i-can-send-my-data-from-nodemcu-to-arduino-via-serial/1070152/4 "2022-12-27T20:27:40Z")

</div>

```cpp
delay(0.00001)

```

What is the point on that?

---

<div class="post-metadata">

**Author:** ![StefanL38](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/stefanl38/32/713548_2.png) [@StefanL38](https://forum.arduino.cc/u/StefanL38)\
**Post date:** [December 27, 2022, 8:41pm UTC](https://forum.arduino.cc/t/how-i-can-send-my-data-from-nodemcu-to-arduino-via-serial/1070152/5 "2022-12-27T20:41:31Z")

</div>

> [@tanishqc](#):
>
> but i want to send those values to arduino too

> [@tanishqc](#):
>
> `String d = Serial.write(Serial1);`

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

> [@tanishqc](#):
>
> i want to send those values to arduino too

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

```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?

---

<div class="post-metadata">

**Author:** ![tanishqc](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@tanishqc](https://forum.arduino.cc/u/tanishqc)\
**Post date:** [December 28, 2022, 5:04am UTC](https://forum.arduino.cc/t/how-i-can-send-my-data-from-nodemcu-to-arduino-via-serial/1070152/6 "2022-12-28T05:04:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tanishqc](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@tanishqc](https://forum.arduino.cc/u/tanishqc)\
**Post date:** [December 28, 2022, 5:08am UTC](https://forum.arduino.cc/t/how-i-can-send-my-data-from-nodemcu-to-arduino-via-serial/1070152/7 "2022-12-28T05:08:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [December 28, 2022, 6:08am UTC](https://forum.arduino.cc/t/how-i-can-send-my-data-from-nodemcu-to-arduino-via-serial/1070152/8 "2022-12-28T06:08:31Z")

</div>

You have not said which Arduino board you have

---

<div class="post-metadata">

**Author:** ![horace](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/horace/32/1014299_2.png) [@horace](https://forum.arduino.cc/u/horace)\
**Post date:** [December 28, 2022, 7:01am UTC](https://forum.arduino.cc/t/how-i-can-send-my-data-from-nodemcu-to-arduino-via-serial/1070152/9 "2022-12-28T07:01:04Z")

</div>

have a look at [nodemcu-details-specifications](https://www.make-it.ca/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](https://github.com/plerup/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

---

<div class="post-metadata">

**Author:** ![StefanL38](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/stefanl38/32/713548_2.png) [@StefanL38](https://forum.arduino.cc/u/StefanL38)\
**Post date:** [December 28, 2022, 7:54am UTC](https://forum.arduino.cc/t/how-i-can-send-my-data-from-nodemcu-to-arduino-via-serial/1070152/10 "2022-12-28T07:54:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tanishqc](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@tanishqc](https://forum.arduino.cc/u/tanishqc)\
**Post date:** [December 28, 2022, 12:23pm UTC](https://forum.arduino.cc/t/how-i-can-send-my-data-from-nodemcu-to-arduino-via-serial/1070152/11 "2022-12-28T12:23:06Z")

</div>

UNO Rev 3

---

<div class="post-metadata">

**Author:** ![tanishqc](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@tanishqc](https://forum.arduino.cc/u/tanishqc)\
**Post date:** [December 28, 2022, 12:25pm UTC](https://forum.arduino.cc/t/how-i-can-send-my-data-from-nodemcu-to-arduino-via-serial/1070152/12 "2022-12-28T12:25:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tanishqc](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@tanishqc](https://forum.arduino.cc/u/tanishqc)\
**Post date:** [December 28, 2022, 12:28pm UTC](https://forum.arduino.cc/t/how-i-can-send-my-data-from-nodemcu-to-arduino-via-serial/1070152/13 "2022-12-28T12:28:06Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![horace](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/horace/32/1014299_2.png) [@horace](https://forum.arduino.cc/u/horace)\
**Post date:** [December 28, 2022, 12:30pm UTC](https://forum.arduino.cc/t/how-i-can-send-my-data-from-nodemcu-to-arduino-via-serial/1070152/14 "2022-12-28T12:30:55Z")

</div>

> [@tanishqc](#):
>
> i need only one way communication i.e from nodemcu to arduino uno

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

```cpp
// 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

---

<div class="post-metadata">

**Author:** ![tanishqc](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@tanishqc](https://forum.arduino.cc/u/tanishqc)\
**Post date:** [December 28, 2022, 12:37pm UTC](https://forum.arduino.cc/t/how-i-can-send-my-data-from-nodemcu-to-arduino-via-serial/1070152/15 "2022-12-28T12:37:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![StefanL38](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/stefanl38/32/713548_2.png) [@StefanL38](https://forum.arduino.cc/u/StefanL38)\
**Post date:** [December 28, 2022, 12:42pm UTC](https://forum.arduino.cc/t/how-i-can-send-my-data-from-nodemcu-to-arduino-via-serial/1070152/16 "2022-12-28T12:42:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tanishqc](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@tanishqc](https://forum.arduino.cc/u/tanishqc)\
**Post date:** [December 28, 2022, 12:44pm UTC](https://forum.arduino.cc/t/how-i-can-send-my-data-from-nodemcu-to-arduino-via-serial/1070152/17 "2022-12-28T12:44:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tanishqc](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@tanishqc](https://forum.arduino.cc/u/tanishqc)\
**Post date:** [December 28, 2022, 12:50pm UTC](https://forum.arduino.cc/t/how-i-can-send-my-data-from-nodemcu-to-arduino-via-serial/1070152/18 "2022-12-28T12:50:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![horace](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/horace/32/1014299_2.png) [@horace](https://forum.arduino.cc/u/horace)\
**Post date:** [December 28, 2022, 12:51pm UTC](https://forum.arduino.cc/t/how-i-can-send-my-data-from-nodemcu-to-arduino-via-serial/1070152/19 "2022-12-28T12:51:18Z")

</div>

this was the UNO code

```cpp
/* 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](https://circuitsgeek.com/guides-and-how-to/nodemcu-pinout-and-esp-12e-pinout-pin-description-peripherals/)) connected directly to UNO pin 2

---

<div class="post-metadata">

**Author:** ![tanishqc](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@tanishqc](https://forum.arduino.cc/u/tanishqc)\
**Post date:** [December 28, 2022, 1:06pm UTC](https://forum.arduino.cc/t/how-i-can-send-my-data-from-nodemcu-to-arduino-via-serial/1070152/20 "2022-12-28T13:06:23Z")

</div>

@StefanL38

 ![IMG20221228190711-min](https://europe1.discourse-cdn.com/arduino/original/4X/9/0/4/904901985eeb7209e3e1e72e0151dca1a159f586.jpeg)  
Here you have it I have mentioned the key details and what do i want...

[Next page](https://forum.arduino.cc/t/how-i-can-send-my-data-from-nodemcu-to-arduino-via-serial/1070152.md?page=2)
