Arduino + NodeMcu + FireBase

currently im working on a project that integrate ardunio nodemcu and firebase together. I am using serial communication between arduino and nodemcu. But i have encounter some problems.

Im using a MQ-2 Gas Sensor to sense the input, when i test with analogRead it gave about value “200” data.
So I wrote this code in arduino.

void setup() {
  //Gas sensor
  pinMode(GasSensor, INPUT);


void loop() {
int FF = analogRead(GasSensorLv2_R) ;

if ( FF < 200 )
if ( FF > 300)

if ( condition != lastcondition )
  mySerial.write ( GasF );
  lastcondition = condition; 

And for the nodemcu part

void loop() {
if (Serial.available() > 0)
    Sensor =;

But this eventually result in the firebase keep updating “0” and “1” simultaneously. Even i increase the threhold value untill 800 it was the same. Anyone know what happened?

without the complete code it is still a guessing game, but if mySerial is as swSerial, 115200 is a BAUD rate likely not to be reliable, also you should really do an error-check on Serial.values before using the results, for debugging i suggest you send back some info to the mySerial and then onto the Serial.

Arduino logic is 5V, NodeMCU (ESP8266) logic is 3.3V. This can cause serial com problems.
Also maybe try Serial.parseInt (Arduino - ParseInt) when working with numbers on the Serial.