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() {
Serial.begin(9600);
mySerial.begin(115200);
//Gas sensor
pinMode(GasSensor, INPUT);
}
void loop() {
int FF = analogRead(GasSensorLv2_R) ;
if ( FF < 200 )
{
GasF=0;
condition=0;
}
if ( FF > 300)
{
GasF=1;
condition=1;
}
if ( condition != lastcondition )
{
mySerial.write ( GasF );
delay(200);
lastcondition = condition;
}
}
And for the nodemcu part
void loop() {
if (Serial.available() > 0)
{
Sensor = Serial.read();
Firebase.setInt("Sensor",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?