Problem connecting to firebase using nodemcu esp8266 and gas sensor

hi.... i want to send data from sensor to firebase... I am using esp8266 to connect to wifi ... There is no error when i compile the code and I am connected to the internet using esp8266. The data reading from gas sensor also visible in the serial monitor.. However there is no data in my firebase.. The firebase are connected but there is no data added. This is my first time doing an Iot project using arduino ide so im not quite sure about what im doing

This is my code for wifi and firebase connection

#include "ThingSpeak.h"
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
#include <ArduinoJson.h>
#include <ESP8266HTTPClient.h>
#define FIREBASE_HOST " "
#define FIREBASE_AUTH " "

//--------Wi-Fi Details -----//
char ssid[] = " ";  //SSID
char pass[] = " "; //Password
//--------------------------------------//


unsigned long Channel_ID = ; // Channel ID
const char * myWriteAPIKey = " "; // Write API Key
const int Field_Number_1 = 1;
const int Field_Number_2 = 2;
String value = "";
String val1, val2;
int value_1 = 0, value_2 = 0;
WiFiClient  client;

void setup()
{
  Serial.begin(9600);
  WiFi.mode(WIFI_STA);
  ThingSpeak.begin(client);
  internet();
  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}

void loop()
{
  internet();
  if (Serial.available() > 0)
  {
    delay(100);
    while (Serial.available() > 0)
    {
      value = Serial.readString();
      if (value[0] == '*')
      {
        if (value[5] == '#')
        {
          value_1 = ((value[1] - 0x30) * 10 + (value[2] - 0x30));
          value_2 = ((value[3] - 0x30) * 10 + (value[4] - 0x30));
        }
      }
    }
  }
  upload();
  val1 = String(value_1); 
  val2 = String(value_2);
  
  Serial.print ("CARBON MONOXIDE: "); Serial.print (val1);
  String firebaseCo = String (val1) + String ("ppm"); 
  Serial.print ("ppm ; SMOKE: "); Serial.print (val2); Serial.println ("ppm");
  String firebaseSmoke = String (val2) + String ("ppm"); 
  delay (5000);
  
  Firebase.pushString ("CARBON MONOXIDE", firebaseCo); 
  Firebase.pushString ("SMOKE", firebaseSmoke);
}

void internet()
{
  if (WiFi.status() != WL_CONNECTED)
  {
    while (WiFi.status() != WL_CONNECTED)j
    {
      WiFi.begin(ssid, pass);
      delay(5000);
    }
    }
}

void upload()
{
  ThingSpeak.writeField(Channel_ID, Field_Number_1, value_1, myWriteAPIKey);
  delay(15000);
  ThingSpeak.writeField(Channel_ID, Field_Number_2, value_2, myWriteAPIKey);
  delay(15000);
  value = "";

}

This is my arduino code

#include <SoftwareSerial.h>
SoftwareSerial mySerial(2,3);

#define load_Res 10    
#define air_factor 9.83 

int buzzer = 13;
int mq2 = A0;
int mq9 = A1;
float R0 = 0.91; 
float m = -0.4678;
float b = 1.31; 
float SmokeCurve[3] ={2.3,0.53,-0.44};
float Res=0; 
float ppm, result;

void setup() { 
  Serial.begin(9600); 
  mySerial.begin(9600);
  pinMode(buzzer, OUTPUT);
  pinMode(mq2, INPUT);
  pinMode(mq9, INPUT);
  Res = SensorCalibration(); 
} 

void loop() { 

 float sensor_volt; 
 float RS_gas; 
 float ratio; 

 float sensorValue = analogRead(A1); 
 sensor_volt = (sensorValue / 1024) * 5.0; 
 RS_gas = (5.0 - sensor_volt) / sensor_volt; 
 ratio = RS_gas / R0;  
 double ppm_log = (log10(ratio)-b)/m; //Get ppm value in linear scale according to the the ratio value  
 float ppm = pow(10, ppm_log); //Convert ppm value to log scale 
  
 Serial.println("CO (ppm) = "); 
 Serial.println(ppm);
 mySerial.println(ppm);

 if(ppm>1000)
   {
      digitalWrite(buzzer, HIGH);
      delay(2000);
   }
   else
   digitalWrite(buzzer, LOW);
   delay(1000);
   
   float res=resistance(5,50);
   res/=Res;
   result=pow(10,(((log(res)-SmokeCurve[1])/SmokeCurve[2]) + SmokeCurve[0]));
   Serial.println("SMOKE (ppm) ="); 
   Serial.println(result);
   mySerial.println(result);
   Serial.print("\n"); 
   if(result>1000)
   {
      digitalWrite(buzzer, HIGH);
      delay(2000);
   }
   else
   digitalWrite(buzzer, LOW);
   delay(1000);
}

float resistance(int samples, int interval)
{
   int i;
   float res=0; 
   for (i=0;i<samples;i++) 
   {
      int adc_value=analogRead(mq2);
      res+=((float)load_Res*(1023-adc_value)/adc_value);
      delay(interval);
   }
   res/=samples;
   return res;
}
 
 
float SensorCalibration()
{
  int i;
  float val=0;    
  val=resistance(50,500);                
  val = val/air_factor;  
  return val; 
}

Please help me solve this cuz i dont know where i did wrong

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.