Send Data From Arduino to NodeMCU and NodeMCU to Arduino Via Serial Communication

Robotica DIY
Robotica DIY
96.5 هزار بار بازدید - 4 سال پیش - Send Data From Arduino to
Send Data From Arduino to NodeMCU and NodeMCU to Arduino Via Serial Communication
Scroll down for code.....

In this tutorial we will learn how to make serial communication between Arduino to ESP8266 & ESP8266 to Arduino. Serial communication is required when you want to transfer sensor data or any data from one device to another device, In our case it is ESP8266 NodeMCU and Arduino.  Moreover, we will transfer DHT22 Sensor data from Arduino to NodeMCU and NodeMCU to Arduino. Apart from this we will also see how to use software serial library on Arduino and Serial1 on ESP8266 NodeMCU, So that you can transfer data with another serial port, which we will be helpful. If you are doing lots of things on both Arduino and ESP8266 NodeMCU.

If you want to support my video please buy any product through my amazon affiliate link. I will receive a commission, at no extra cost to you.

LIST OF COMPONENT (affiliate links)

https://amzn.to/2Uo7M93 (NodeMCU ESP8266 12E)
http://amzn.to/2fvSRJq   (Arduino)
http://amzn.to/2vqIKJP  (DHT22)
http://amzn.to/2wxPmWz  (Breadboard)
http://amzn.to/2vJ3lvo   (Jumper wire)
http://amzn.to/2vmSK8l  (Resistor)


Music provided by NoCopyrightSounds.
Watch: Lost Sky - Vision | Dubstep | NCS - C...
Free Download / Stream: http://ncs.io/VisionID

Code for Arduino:
#include "DHT.h"
#include (SoftwareSerial.h) //instead of parenthesis () put angle bracket as YouTube description does not allow angle bracket
#define DHTPIN 2

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)

SoftwareSerial espSerial(5, 6);
DHT dht(DHTPIN, DHTTYPE);
String str;

void setup(){
Serial.begin(115200);
espSerial.begin(115200);
dht.begin();
delay(2000);
}
void loop()
{
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
Serial.print("H: ");
Serial.print(h);
Serial.print("% ");
Serial.print(" T: ");
Serial.print(t);
Serial.println("C");
str =String("coming from arduino: ")+String("H= ")+String(h)+String("T= ")+String(t);
espSerial.println(str);
delay(1000);
}

Code for ESP8266:
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
}
}

void loop() { // run over and over
if (Serial.available()) {
Serial.write(Serial.read());
}
}
4 سال پیش در تاریخ 1399/02/16 منتشر شده است.
96,500 بـار بازدید شده
... بیشتر