Robotica DIY
Published © LGPL

Send Data From Arduino to NodeMCU and NodeMCU to Arduino...

We will transfer DHT22 Sensor data from Arduino to NodeMCU and NodeMCU to Arduino.

IntermediateFull instructions provided1 hour128,735
Send Data From Arduino to NodeMCU and NodeMCU to Arduino...

Story

Read more

Code

Code snippet #1

Plain text
#include "DHT.h"
#include <SoftwareSerial.h>
#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 snippet #2

Plain text
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());
}
}

Code snippet #3

Plain text
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());
}
}

Code snippet #4

Plain text
#include "DHT.h"
#include <SoftwareSerial.h>
#define DHTPIN 4

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

DHT dht(DHTPIN, DHTTYPE);
String str;

void setup(){
Serial.begin(115200);
Serial1.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 ESP8266: ")+String("H= ")+String(h)+String("T= ")+String(t);
Serial1.println(str);
delay(1000);
}

Github

https://github.com/adafruit/DHT-sensor-library

Github

https://github.com/adafruit/Adafruit_Sensor

Credits

Robotica DIY

Robotica DIY

16 projects • 18 followers
Robotica DIY is for those who want to learn themselves. You will get projects on Arduino, Raspberry pi & NodeMcu ESP8266.

Comments