0

Im working in a project where i have to deal with multiple sensor data.

  1. BME 280
  2. WindSpeed Sensor
  3. Water level Sensor x 10
  4. Soil moisture x 5
  5. Soil pH sensor x 2

i have found this code for both arduino uno and nodemcu esp8266

//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);
}
}


//for nodeMCU
#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);
  }
}

In this code here send 1 value from arduino uno to nodeMCU... but if i want to send 10 values(float temperature,humidity,pressure,waterlevel,windSpeed,windDirection) from mega to nodeMCU using serial, how to do that using serail.

0

As i know nodemcu still not work as a slave device . Maybe this support will be available in the future but if you test it and it work . This how to do it Let's assume you have tow dat to send cast them to string , concatenated characters of string_data1+string_data2 then send theme via uart communication to the nodemcu . Now in the nodemcu take the string and decoding [split] string to string 1 and string 2 and cast theme again to any var type you want. If this method seems so hard to you or your level in coding is still under development use some library exist that can do the work for you i recommend. The easytransfer library by madsci1016 in github enter link description here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.