Skip to main content
Bumped by Community user
added 110 characters in body
Source Link
Juraj
  • 18.3k
  • 4
  • 32
  • 50

#include <SoftwareSerial.h> SoftwareSerial my (D6,D7); //(Rx,Tx) String msg;

void setup() { Serial.begin(115200); my.begin(9600); }

void gas() {

Serial.println(msg); if (msg == "0") { Serial.println("Gas Leakage !!"); } if(msg == "1") { delay(1); } }

void loop() {

#include <SoftwareSerial.h>
SoftwareSerial my (D6,D7); //(Rx,Tx)
String msg;

void setup() {
Serial.begin(115200);
my.begin(9600);
}

void gas()
{
  
  Serial.println(msg);
  if (msg == "0")
  {
    Serial.println("Gas Leakage !!");
  }
  if(msg == "1") {
    delay(1);
  } 
}
 
void loop() {
  
  msg = my.readStringUntil('\n');
  gas(); 
}

msg = my.readStringUntil('\n'); gas(); } //I am using software serial to exchange data from Arduino UNO to NodeMCU, i am receiving the data correctly but the "if statement condition" is not working with it. how can i make the if statement work?

#include <SoftwareSerial.h> SoftwareSerial my (D6,D7); //(Rx,Tx) String msg;

void setup() { Serial.begin(115200); my.begin(9600); }

void gas() {

Serial.println(msg); if (msg == "0") { Serial.println("Gas Leakage !!"); } if(msg == "1") { delay(1); } }

void loop() {

msg = my.readStringUntil('\n'); gas(); } //I am using software serial to exchange data from Arduino UNO to NodeMCU, i am receiving the data correctly but the "if statement condition" is not working with it. how can i make the if statement work?

#include <SoftwareSerial.h>
SoftwareSerial my (D6,D7); //(Rx,Tx)
String msg;

void setup() {
Serial.begin(115200);
my.begin(9600);
}

void gas()
{
  
  Serial.println(msg);
  if (msg == "0")
  {
    Serial.println("Gas Leakage !!");
  }
  if(msg == "1") {
    delay(1);
  } 
}
 
void loop() {
  
  msg = my.readStringUntil('\n');
  gas(); 
}

//I am using software serial to exchange data from Arduino UNO to NodeMCU, i am receiving the data correctly but the "if statement condition" is not working with it. how can i make the if statement work?

Source Link

Serial Communication, if statement not working

#include <SoftwareSerial.h> SoftwareSerial my (D6,D7); //(Rx,Tx) String msg;

void setup() { Serial.begin(115200); my.begin(9600); }

void gas() {

Serial.println(msg); if (msg == "0") { Serial.println("Gas Leakage !!"); } if(msg == "1") { delay(1); } }

void loop() {

msg = my.readStringUntil('\n'); gas(); } //I am using software serial to exchange data from Arduino UNO to NodeMCU, i am receiving the data correctly but the "if statement condition" is not working with it. how can i make the if statement work?