Hi guys, in this post we will discuss how to establish Serial Communication between NodeMCU and Arduino[Esp8266 -12E] is explained.
Embedded Systems should be connected with each other to transfer data between them. Because all operations can’t be performed on a single system. For example, Arduino has 6 analog pins but NodeMCU has only one analog pin. So two are more microcontrollers or microprocessors can be combined to form a required embedded system. The connection can be established through any of the following protocols.
- SPI
- I2C
- UART
Serial Communication:
Serial communication is a communication process wherein data transfer occurs by transmitting data one bit at a time in sequential order over a computer bus or a communication channel. It is the most widely used approach to transfer information between data processing equipment and peripherals. Binary One represents a logic HIGH or 5 Volts, and zero represents a logic LOW or 0 Volts, used for communicating between the Arduino board and a computer or other devices. All Arduino boards have at least one serial port which is also known as a UART or USART. It communicates on digital pins 0 (RX) and 1 (TX) as well as with the computer via USB. Serial communication on pins TX/RX uses TTL logic levels (5V or 3.3V depending on the board).To establish serial communication between two devices, the devices should be connected as shown below.. Because the data sent from the device 1 should be received in the device 2 and vice versa.
CONNECTION:
1. Sending single data between Arduino and NodeMcu:
In this tutorial, the data is sent from Arduino to NodeMCU. NodeMCU requests the data from the Arduino by sending a character. Once the Arduino detects that there is an incoming data it sends the data in serial as the response. This Arduino and the NodeMCU code for the above-explained procedure is given below
ARDUINO PART:
In Arduino, we shall consider pin 5 as Rx and pin 6 as Tx. To use the GPIO pins for serial communication SoftwareSerial library can be used. Here we have created a serial port named s with pin 5 as RX and pin 6 as TX.
1 2 | #include <SoftwareSerial.h> SoftwareSerial s(5,6); // (Rx, Tx) |
To begin the serial communication between Arduino and NodeMCU with 9600 bits per second
1 2 3 | void setup() { s.begin(9600); } |
To check if there is any incoming data in the serial the following command is used
1 2 3 | if(s.available()>0) { } |
To write our data in data in serial if there is an incoming data the void loop is configured as
1 2 3 4 5 6 7 | void loop() { int data=50; if(s.available()>0) { s.write(data); } } |
ARDUINO FULL CODE
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | //Arduino code #include <SoftwareSerial.h> SoftwareSerial s(5,6); void setup() { s.begin(9600); } void loop() { int data=50; if(s.available()>0) { s.write(data); } } |
NODEMCU PART:
In NodeMCU we shall make pin 5 as Tx and pin 6 as Rx. So data sent by Arduino will be received by the NodeMCU and vice versa. So we can establish a successful Serial Communication between NodeMCU and Arduino.
1 2 | #include <SoftwareSerial.h> SoftwareSerial s(D6,D5); // (Rx, Tx) |
NodeMCU sends the control character and starts listening for the data from the Arduino. This is implemented in the NodeMCU as shown below
1 2 3 4 5 6 7 8 | void loop() { s.write("s"); if (s.available()>0) { data=s.read(); Serial.println(data); } } |
NODEMCU FULL CODE
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include <SoftwareSerial.h> SoftwareSerial s(D6,D5); int data; void setup() { s.begin(9600); Serial.begin(9600); } void loop() { s.write("s"); if (s.available()>0) { data=s.read(); Serial.println(data); } } |
2. Sending Multiple data between NodeMCU and Arduino:
To send multiple data in serial, JSON can be adapted. JSON stands for JavaScript Object Notation. JSON is a lightweight data interchange format for structuring data. JSON is based on key-value pairs. Key is always string, where value may be a integer, string or an array. An example of JSON is given below
1 2 3 4 5 | { "name":"mybtechprojects", "no_of_posts":52, "members":4 } |
To know more about json visit this post. To install Json library follow the following steps.
- Go to Sketch–>Manage Library.
- Then search for ArduinoJson library and install 5.x version, since the 6.x version is still in beta. 6.x versions have a different type of functions.
ARDUINO PART:
JsonBuffer does the memory management function. It contains two types
- DynamicJsonBuffer
- StaticJsonBuffer
DynamicJsonBuffer updates the memory automatically according to the requirement. Where StaticJsonBuffer allocates fixed memory and will not change according to the requirement. Here we have created a StaticJsonBuffer with a size 200.
1 | StaticJsonBuffer<200> jsonBuffer; |
JsonObject is where the key-value pairs are stored. The memory of the JsonObject is located in the buffer. The key-value pairs are generated as shown below
1 2 3 | JsonObject& root = jsonBuffer.createObject(); root["data1"] = 100; root["data2"] = 200; |
To print the JsonObject to the serial port the following command is used
1 | root.printTo(s); |
ARDUINO FULL CODE
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include <SoftwareSerial.h> #include <ArduinoJson.h> SoftwareSerial s(5,6); void setup() { s.begin(9600); } void loop() { StaticJsonBuffer<1000> jsonBuffer; JsonObject& root = jsonBuffer.createObject(); root["data1"] = 100; root["data2"] = 200; if(s.available()>0) { root.printTo(s); } } |
NODEMCU PART:
1 2 | StaticJsonBuffer<1000> jsonBuffer; JsonObject& root = jsonBuffer.parseObject(s); |
The above mentioned code is used to create the jsonbuffer and read the JSON string the serial port and store it in a JsonOnject.
1 2 | if (root == JsonObject::invalid()) return; |
If the JSON data parsed from the serial port is not in the valid format it should be ignored and the loop function repeats again.
NODEMCU FULL CODE
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include <SoftwareSerial.h> SoftwareSerial s(D6,D5); #include <ArduinoJson.h> void setup() { // Initialize Serial port Serial.begin(9600); s.begin(9600); while (!Serial) continue; } void loop() { StaticJsonBuffer<1000> jsonBuffer; JsonObject& root = jsonBuffer.parseObject(s); if (root == JsonObject::invalid()) return; Serial.println("JSON received and parsed"); root.prettyPrintTo(Serial); Serial.print("Data 1 "); Serial.println(""); int data1=root["data1"]; Serial.print(data1); Serial.print(" Data 2 "); int data2=root["data2"]; Serial.print(data2); Serial.println(""); Serial.println("---------------------xxxxx--------------------"); } |
3. To Send Dynamic Sensor Data from Arduino to NodeMCU
Now we shall send DHT-11 data and Gas sensor data from Arduino to NodeMCU through serial communication. To interface DHT-11 with NodeMCU and install the required libraries visit this post. Kindly refer to the connections given below,
ARDUINO PART:
Note
If the DHT-11 is not connected to the correct pin or if it does not work no data will be sent to NodeMCU. So kindly make sure to make the connections correctly as mentioned in the diagram.
Include the DHT library, define the pin to which the DHT sensor is connected, define the type of the DHT connected as shown below.
1 2 3 | #include "DHT.h" #define DHTPIN 2 #define DHTTYPE DHT11 |
Create an object for the DHT class and pass the DHTPIN and DHTTYPE as parameters for constructer and begin the dht.
1 2 | DHT dht(DHTPIN, DHTTYPE); dht.begin(); |
Use the functions of the DHT library to find the temperature, humidity and heat index.
1 2 3 4 5 6 7 8 9 10 | float h = dht.readHumidity(); // Read temperature as Celsius (the default) float t = dht.readTemperature(); // Read temperature as Fahrenheit (isFahrenheit = true) float f = dht.readTemperature(true); // Compute heat index in Fahrenheit (the default) float hif = dht.computeHeatIndex(f, h); // Compute heat index in Celsius (isFahreheit = false) float hic = dht.computeHeatIndex(t, h, false); |
The values are stored as key values pairs to the JsonObject root. The value of the gas sensor connected to the analog pin is also read and stored. Then the data is printed into the serial port.
1 2 3 4 5 6 7 8 9 | root["temp"] = t; root["hum"] = h; root["hi"] = hic; root["gasv"]= analogRead(A0); if(s.available()>0) { root.printTo(s); } |
ARDUINO FULL CODE:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #include <SoftwareSerial.h> #include <ArduinoJson.h> SoftwareSerial s(5,6); #include "DHT.h" #define DHTPIN 2 #define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE); void setup() { s.begin(115200); pinMode(A0,INPUT); dht.begin(); } StaticJsonBuffer<1000> jsonBuffer; JsonObject& root = jsonBuffer.createObject(); void loop() { float h = dht.readHumidity(); // Read temperature as Celsius (the default) float t = dht.readTemperature(); // Read temperature as Fahrenheit (isFahrenheit = true) float f = dht.readTemperature(true); // Compute heat index in Fahrenheit (the default) float hif = dht.computeHeatIndex(f, h); // Compute heat index in Celsius (isFahreheit = false) float hic = dht.computeHeatIndex(t, h, false); if (isnan(h) || isnan(t) || isnan(f)) { return; } // If the DHT-11 is not connected to correct pin or if it doesnot //work no data will be sent root["temp"] = t; root["hum"] = h; root["hi"] = hic; root["gasv"]= analogRead(A0); if(s.available()>0) { root.printTo(s); } } |
NODEMCU PART:
NODEMCU FULL CODE
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #include <SoftwareSerial.h> SoftwareSerial s(D6,D5); #include <ArduinoJson.h> void setup() { // Initialize Serial port Serial.begin(115200); s.begin(115200); while (!Serial) continue; } void loop() { StaticJsonBuffer<1000> jsonBuffer; JsonObject& root = jsonBuffer.parseObject(s); if (root == JsonObject::invalid()) { return; } //Print the data in the serial monitor Serial.println("JSON received and parsed"); root.prettyPrintTo(Serial); Serial.println(""); Serial.print("Temperature "); int data1=root["temp"]; Serial.println(data1); Serial.print("Humidity "); int data2=root["hum"]; Serial.println(data2); Serial.print("Heat-index "); int data3=root["hi"]; Serial.println(data3); Serial.print("gas sensor "); int data4=root["gasv"]; Serial.println(data4); Serial.println(""); Serial.println("---------------------xxxxx--------------------"); Serial.println(""); } |
OUTPUT:
To learn Python Basics for free kindly refer my tutorials here. And to get started with RaspberryPi microcontroller check these posts.
THANK YOU
80 Comments
Ruban
(September 28, 2018 - 6:58 am)How to send dynamic data from ARDUINO to nodemcu.
When I’m trying to send using the 1 st program, i received nothing.
Gowtham S
(October 3, 2018 - 9:18 pm)You can use the same code for dynamic data also. Thank you.
Naveen
(October 17, 2018 - 9:26 pm)Nice work
Gowtham S
(October 17, 2018 - 9:58 pm)Thank you
nanda
(November 3, 2018 - 4:27 pm)hey, i try use for program 1 to create serial communication for node mcu esp8266 and arduino nano with data from MQ 7 sensor, but the data send to node MCU looks different from data at nano serial monitor. can you help me?? whats wrong ??
Arduino program
#include
SoftwareSerial s(0,1);
int sensorValue;
void setup() {
Serial.begin(115200);
pinMode(A1,INPUT);
s.begin(115200);
//pinMode(A1,INPUT);
}
void loop() {
sensorValue = analogRead(1); // read analog input pin 0
Serial.print(sensorValue/60, DEC); // prints the value read
Serial.println(“ppm”);
if(s.available()>0)
{
s.write(sensorValue);
}
delay(1000);
}
MCU program
#include
SoftwareSerial s(D7,D6);
int data;
void setup() {
s.begin(115200);
Serial.begin(115200);
}
void loop() {
s.write(“s”);
if (s.available()>0)
{
data=s.read();
Serial.print(data);
Serial.println(“ppm”);
}
delay(1000);
}
Gowtham S
(January 4, 2019 - 9:13 pm)Hi,
Nice to hear from you. Try reading data from the analog pin if only serial port is available as shown below,
SoftwareSerial s(0,1);
int sensorValue;
void setup() {
Serial.begin(115200);
pinMode(A1,INPUT);
s.begin(115200);
//pinMode(A1,INPUT);
}
void loop() {
if(s.available()>0)
{
sensorValue = analogRead(1); // read analog input pin 0
Serial.print(sensorValue/60, DEC); // prints the value read
Serial.println(“ppm”);
s.write(sensorValue);
}
delay(1000);
}
Hendrio
(November 9, 2018 - 1:09 am)Wouldn’t you need a tension divider for this communication? Can NodeMCU withstand 5V serial?
Gowtham S
(November 9, 2018 - 7:16 am)Hi hendrio,
Good to hear from you. Serial Communication can be established directly between nodemcu and Arduino without other modules.
Thank you.
LIM
(November 13, 2018 - 2:31 pm)How can I receive and send data between Arduino and nodeMCU?
Gowtham S
(January 4, 2019 - 9:08 pm)Hi Lim,
Kindly refer the projects above
Afiq
(November 18, 2018 - 8:28 pm)// Memory pool for JSON object tree.
//
// Inside the brackets, 200 is the size of the pool in bytes.
// Don’t forget to change this value to match your JSON document.
// Use arduinojson.org/assistant to compute the capacity.
can u explain me about this . i dont understand
Gowtham S
(January 4, 2019 - 9:07 pm)Hi Afiq, It is the size of the json. If we send more data, it’s recommended to have a larger size
APOORVA RAMPAL
(November 28, 2018 - 3:05 pm)how to send data from nodemcu to arduino. when i am using this code in reverse manner. it’s printing nothing on the arduino serial monitor.
Gowtham S
(January 4, 2019 - 9:04 pm)When you interchange the code make sure you use
SoftwareSerial s(5,6);
for Arduino andSoftwareSerial s(D6,D5);
for NodeMCUMr Lim
(January 2, 2019 - 2:23 am)Hi, may i know if i using the Arduino Mega to communicate with NodeMCU If the pin from the NodeMCU can be connected to the Arduino TX0 and RX0.
Gowtham S
(January 4, 2019 - 9:02 pm)Hi Lim,
Nice to hear from you, Yes, of course, you can use the Serial port(TX0,RX0). But in these examples we are defining our own serial ports using SoftwareSerial Library.
Vitor Aguiar
(January 9, 2019 - 8:20 pm)Hi, I have been implemented this project. This is working, but sometimes I’m receiving the zero value in the variables of the root what I’m using.
How to solve this problem ? I’m using this values to print in a HTTP server using nodeMCU
Thanks !
Gowtham S
(January 22, 2019 - 5:42 pm)Hi Vitor,
Happy to hear that you have tried out this idea. Zero in the variables implies that the size of the JSON Buffer is not sufficient. So try increasing the size of the JSON buffer.
StaticJsonBuffer<200> jsonBuffer;
Try using higher values instead of 200.
Thankyou.
abenk
(January 27, 2019 - 10:41 pm)communication between arduino mega and nodemcu does not work. I have followed your stage. but it doesn’t work in my tool.
Gowtham S
(February 8, 2019 - 2:37 pm)Hi Abenk,
Make sure you have made the connections right. Once check the diagram above in this post.
Thank you.
amir
(February 5, 2019 - 1:19 pm)Hi. you have done a great task. however. I have 1 question. can I implement the same thing with distance sensor?
Gowtham S
(February 8, 2019 - 2:41 pm)Hi amir,
Nice to hear from you. Of course we can implement the same thing with ultrasonic sensor. Refer this post for connections and code here.
Ghareisa
(February 21, 2019 - 2:11 am)Hello, thank you for this amazing tutorial!
One question, in sending multiple data nodemcu part
while (!Serial) continue;
What does this part do? And is this the SoftwareSerial or the Serial Monitor?
Thanks!
Gowtham S
(April 1, 2019 - 10:01 am)Hi Ghareisa,
Thanks for your complement.
while (!Serial) continue;
is used to check if the serial port is available for communication or not.Kavkaz
(February 24, 2019 - 2:29 am)Arduino: 1.8.2 (Windows 10), Board: “NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Disabled, 4M (no SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200″
WARNING: Category ” in library ArduinoJson is not valid. Setting to ‘Uncategorized’
Build options changed, rebuilding all
C:\Users\Lenovo\Documents\Arduino\brodcemotori\SerialCommunicationEsp\SerialCommunicationEsp.ino: In function ‘void loop()’:
SerialCommunicationEsp:14: error: no matching function for call to ‘ArduinoJson::StaticJsonBuffer::parseObject(SoftwareSerial&)’
JsonObject& root = jsonBuffer.parseObject(s);
^
C:\Users\Lenovo\Documents\Arduino\brodcemotori\SerialCommunicationEsp\SerialCommunicationEsp.ino:14:46: note: candidates are:
In file included from C:\Users\Lenovo\Documents\Arduino\libraries\ArduinoJson\src/../include/ArduinoJson/DynamicJsonBuffer.hpp:9:0,
from C:\Users\Lenovo\Documents\Arduino\libraries\ArduinoJson\src/../include/ArduinoJson.h:7,
from C:\Users\Lenovo\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson.h:13,
from C:\Users\Lenovo\Documents\Arduino\brodcemotori\SerialCommunicationEsp\SerialCommunicationEsp.ino:3:
C:\Users\Lenovo\Documents\Arduino\libraries\ArduinoJson\src/../include/ArduinoJson/JsonBuffer.hpp:75:15: note: ArduinoJson::JsonObject& ArduinoJson::JsonBuffer::parseObject(char*, uint8_t)
JsonObject &parseObject(char *json, uint8_t nestingLimit = DEFAULT_LIMIT);
^
C:\Users\Lenovo\Documents\Arduino\libraries\ArduinoJson\src/../include/ArduinoJson/JsonBuffer.hpp:75:15: note: no known conversion for argument 1 from ‘SoftwareSerial’ to ‘char*’
C:\Users\Lenovo\Documents\Arduino\libraries\ArduinoJson\src/../include/ArduinoJson/JsonBuffer.hpp:78:15: note: ArduinoJson::JsonObject& ArduinoJson::JsonBuffer::parseObject(const String&, uint8_t)
JsonObject &parseObject(const String &json,
^
C:\Users\Lenovo\Documents\Arduino\libraries\ArduinoJson\src/../include/ArduinoJson/JsonBuffer.hpp:78:15: note: no known conversion for argument 1 from ‘SoftwareSerial’ to ‘const String&’
exit status 1
no matching function for call to ‘ArduinoJson::StaticJsonBuffer::parseObject(SoftwareSerial&)’
This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.
Gowtham S
(April 1, 2019 - 9:59 am)Hi Kavkaz,
Try installing 5.x versions of ArduinoJson. Because 6.x versions have different functions.
nazim
(February 24, 2019 - 9:01 am)why on sending multiple data node mcu full command got an error that is D6 is not declared in this scope
Gowtham S
(April 1, 2019 - 11:24 am)Hi nazim,
Thanks for asking. I think that you are running the NodeMCU code in Arduino. Since D6 pin is not available in Arduino.
sai nikhilesh
(March 9, 2019 - 8:28 pm)1) how did you run 2 sketches, they are differnt progrms 1 for uno and other for nodemcu
2) i need to send data to a cloud thingsspeak how do i do that?
meaning i want a code to send the value from nodemcu to cloud
Gowtham S
(April 1, 2019 - 11:11 am)Hi sai nikhilesh,
Thanks for asking. Follow the steps given below.
1) To run 2 sketches
2) To send data to thingspeak refer this. To send data to ubidots cloud refer this.
sai
(March 17, 2019 - 10:16 pm)hi!
can you help me in programming to display dynamically the distance using ultrasonic sensor. please do help.
Gowtham S
(April 1, 2019 - 10:09 am)Hi sai,
Thanks for asking. For interfacing Ultrasonic sensor refer this tutorial. You can combine it with sending dynamic data from Arduino to NodMCU already discussed here.
Prince
(March 20, 2019 - 12:22 am)How to send data from nodemcu to Arduino using Arduino JSON. I want to receive character from mobile app on nodemcu . Send this character from nodemcu to Arduino using Arduino JSON. I want to control water pump using arduino
Gowtham S
(April 1, 2019 - 10:07 am)Hi Prince,
Thanks for asking. Why can’t you directly contol motor from NodeMCU. Try using relay https://mybtechprojects.tech/interface-relay-with-nodemcu/.
IEZA
(March 30, 2019 - 1:18 pm)Hi,i follow all the instruction as above but why my serial for node mcu display nothing ? both(node mcu & arduino) usb port is connected to 5v ?
Gowtham S
(April 1, 2019 - 9:36 am)Hi IEZA,
Thanks for asking. Make sure that the connections are correct.
Muhammad Ibrahim
(March 31, 2019 - 6:36 am)I received invalid JSON Format—->
{” ” :t
}Data 1 0
Data 2 0
what is the problem the connection and the code is the same you make .so what is the problem?
Gowtham S
(April 1, 2019 - 9:52 am)Hi Ibrahim,
Thanks for asking. Have you installed the 5.x version of ArduinoJson library? Because 6.x versions are in beta. And make sure that the connections are correct since you don’t receive any data. Thankyou.
panji
(April 3, 2019 - 12:58 am)Thank you so much
Gowtham S
(April 10, 2019 - 5:51 pm)Hi panji,
Thankyou. Follow us on Facebook for more updates –>https://www.facebook.com/mybtechprojects/.
Dhruv verma
(April 5, 2019 - 12:12 pm)how to do serial communication from arduino uno to ESP8266-01?
Gowtham S
(April 10, 2019 - 5:57 pm)Hi Dhruv,
You can follow the same code given above, after flashing the NodeMCU firmware into esp8266. For flashing firmware refer here.
shreyansh
(April 5, 2019 - 10:55 pm)i have done all the steps but in serial monitor it is not showing correctly
i am working on this project (https://circuitdigest.com/microcontroller-projects/iot-electricity-energy-meter-using-esp12-arduino) and want to send data from arduino to node emu for further transmitting it to web but not able to send data from arduino to node emu please help..
Gowtham S
(April 10, 2019 - 6:00 pm)Hi shreyansh,
IoT Based Electricity Energy Meter is a good project. First, make sure that the connections are correct. Then program the Arduino first and then NodeMCU.
Jasper Smith
(April 7, 2019 - 5:46 am)Great tutorial!
However, what about sending data FROM a NodeMcu TO an Arduino with serial. I’ve been stuck for days trying to make that work. All i get is a blank serial monitor on my Arduino’s side. Could you make a tutorial on how to do that ?
Gowtham S
(April 10, 2019 - 6:02 pm)Hi Jasper Smith,
Thanks. Reusing the same code in a reverse manner should work. But make sure that you change the rx and tx pins in the codes.
Aisha
(April 14, 2019 - 10:12 pm)Hello,
thank you for this great tutorial. I followed the steps but I see nothing in the serial monitor ( i used arduino uno).
Also, If I used arduino mega, what pins shoul I change in the serial software?
Gowtham S
(April 15, 2019 - 9:57 am)Hello Aisha,
Thanks for asking. I guess that you are establishing serial communication between Arduino Uno and Arduino Mega. You can use the same code for for Arduino Uno but for Arduino Mega use the NodeMCU code but change the serial pins in NodeMCU code.
SoftwareSerial s(6,5);
or any pins instead ofSoftwareSerial s(D6,D5);
.SP_iN
(April 20, 2019 - 8:18 am)HI Sir. how can i communicate uno with nodemcu with ultrasonic sensor to the thingspeak?
Gowtham S
(May 11, 2019 - 9:52 am)Thanks for asking. First, we can directly interface the ultrasonic sensor with NodeMCU. Then we can push the data from NodeMCU to Thingspeak. Check this post for sending data to thingspeak.
shashidhara
(May 7, 2019 - 12:34 pm)Hi Gowtham, I am using Arduino UNO, with the ArduinoJson 5.13.5, I followed the steps given by you, But i too am getting nothing on the Serial Monitor
PS: Baud rate set to 9600
Gowtham S
(May 11, 2019 - 9:48 am)Hi shashidhara,
Thanks for commenting. Please check that you have used the same baud rate for NodeMCU and Arduino. Then check the connections once more and make sure that the USB port is working properly. Or try using other USB ports. Thankyou
Karipap
(May 11, 2019 - 1:49 am)It is possible use arduino uno and nodemcu upload the sensor data on thingspeak? I don’t want use nodemcu only for upload the sensor data.
Thank you.
Gowtham S
(May 11, 2019 - 9:45 am)Hi karipap,
Thanks for commenting. In NodeMCU only 1 Analog pin is available. So if we want to use only 1 analog sensor we can go for NodeMCU. If we want more analog pins, ESP32 can be used.
Chew Poh Seng
(May 16, 2019 - 12:12 pm)Please put common GROUND on 1. Sending single data between Arduino and NodeMcu diagram.
Gowtham S
(May 24, 2019 - 10:47 am)Hi, Chew Poh Seng
Thanks for your valid suggestion
Hamza
(May 25, 2019 - 10:01 pm)Hi!
I followed you code and was able to transfer data from Arduino Mega to the NodeMCU. However when I’m trying to send data from NodeMCU to the Arduino the serial monitor is blank because the code is stuck at
if (root == JsonObject::invalid())
{
return;
}
This means that the Arduino is unable to parse the incoming data or NodeMCU is unable to correctly send the data.
I also have set the following:
For Arduino: SoftwareSerial s(5,6);
For NodeMCU: SoftwareSerial s(D6,D5);
Please help as I have a big project to submit.
Thanks.
Gowtham S
(May 26, 2019 - 11:11 am)Hi Hamza,
Thanks for asking. As you say the NodeMCU is not able to send correct JSON or the Arduino is receiving correctly. So check the following
1. Check the connections (TX of NodeMCU to RX of Arduino and RX of NodeMCU to TX of Arduino).
2. Check that your code in NodeMCU sends the JSON Object
Thank you
Hamza
(May 26, 2019 - 9:13 pm)Hi!
Kindly tell how to check if NodeMCU has send JSON Object. My TX and RX pins are connected correctly (as I said the data transfer through Mega to NodeMCU is done successfully, the other way around has the issue.)
Do you have any email to which I can send the code over, so that you can take a look at it.
suraj adhikari
(June 20, 2019 - 6:11 pm)How to send the http get request from nodemcu after the response send by arduino to nodemcu has received.plz help meh I have been stucked with this for so many days.
Gowtham S
(November 21, 2019 - 8:28 am)Hi suraj,
Refer my article here for sending data to cloud.
Dre Manroe
(July 5, 2019 - 9:40 pm)Nice Work you have, thanks
shanay
(July 26, 2019 - 1:45 pm)Hi,
I am trying to send data from 3 LDR’s (connected to the A0, A1, A2 in Arduino) to an SQL database via ESP8266mod DOIT.AM nodemcu. How do I send data from 3 analog pins which are connected to the Arduino?
Further, the data will be exported from SQL to python for processing and data visualization.
thanks
Gowtham S
(November 21, 2019 - 8:26 am)Hi Shanay,
Refer third part of this tutorial, which focuses on sending multiple data from arduino to nodemcu.
Sourav Raxit
(August 29, 2019 - 9:18 pm)I have connected everything right.But i am geeting a null serial monitor…What should i change?
Gowtham S
(November 21, 2019 - 8:21 am)Hi Sourav,
Once check the baud rate for the two devices.
Norah
(September 2, 2019 - 11:08 pm)Thank you so much nice tutorial .
Gowtham S
(November 21, 2019 - 8:20 am)Hi Norah,
Thank You for reading.
Michael
(September 23, 2019 - 8:42 pm)Hello, thanks for this work. I would like to ask if you could assist me. i want to send DHT 11 sensor data between two arduino unos using ethernet shield via a LAN. I am trying to modify your code to get this, can you help?
Gowtham S
(November 21, 2019 - 8:19 am)Hi Michal,
For sending data in lan, You should be using a separate library named Arduino Ethernet library.
Angel
(September 27, 2019 - 7:21 am)Can I use your code with 5 sensors
Gowtham S
(November 21, 2019 - 8:17 am)Hi Angel,
Yes, You can. But prefer a separate power for your sensors.
Jane
(September 29, 2019 - 6:10 pm)Hey!
I followed all your codes and was able to send data from arduino uno to nodemcu when a single analog sensor is connected. However, when I try to go for 3 sensor, which are ultrasonic sensor, turbidity sensor, and pH analog sensor, I was not able to see anything on the serial monitor of nodemcu. But when I try to write Serial.print() in Arduino code, i was able to see the result, just the results cannot send to nodemcu. Can you help me to solve it?
Gowtham S
(November 21, 2019 - 8:16 am)Hi Jane,
I suggest using a separate power for you sensor. As your sensors are demanding more power, Arduino is not getting enough power for serial communication.
J. T.
(October 4, 2019 - 8:10 pm)Hi! I would like to ask if it is possible to send and receive data between Esp8266 and Arduino at the same time?
Gowtham S
(November 21, 2019 - 8:15 am)Hi J.T,
Of course. It’s possible. In fact we are also doing the same. First we send a message to Arduino to request data from NodeMCU, then only Arduino sends us the sensor data back.
Thank you.
yoga
(November 4, 2019 - 5:27 pm)i can’t use this code for arduino mega. any can help ?
Gowtham S
(November 21, 2019 - 8:09 am)Hi Yoga,
Nice to hear from you, Yes, of course, you can use the Serial port(TX0,RX0). But in these examples we are defining our own serial ports using SoftwareSerial Library.
Eril
(November 15, 2019 - 9:35 pm)Hello, I got a problem with this, I have compile to Uno and NodeMCU but i open the serial monitor with nodeMCU nothing happen but if i push button RST nodeMCU i got “⸮⸮⸮⸮⸮D⸮⸮⸮$⸮⸮Y” random string, please help me
Gowtham S
(November 21, 2019 - 8:03 am)Hi Eril,
Thanks for asking. I suggest checking the connections and the baud rate of both the Arduino and Nodemcu.