Test Code: We have developed an Executable Code for our IoT Based Automobile Exhaust
Monitoring Project by using ARDUINO IDE SOFTWARE. The code is provided below:
#include <Firebase.h>
#include <FirebaseArduino.h>
#include <FirebaseCloudMessaging.h>
#include <FirebaseError.h>
#include <FirebaseHttpClient.h>
#include <FirebaseObject.h>
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
// Set these to run example.
#define FIREBASE_HOST "deloitte-305cc.firebaseio.com"
#define FIREBASE_AUTH "DMfEqSDEUYjhZZ7CZsK5cfj46F0VCdtcDFlyHrzS"
#define WIFI_SSID "sritam"
#define WIFI_PASSWORD "sh!n!ng9"
void setup() {
Serial.begin(9600);
pinMode(A0,INPUT);
// connect to wifi.
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("connecting");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
Serial.println();
Serial.print("connected: ");
Serial.println(WiFi.localIP());
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
int gas_sensor = A0; //Sensor pin
float m = -0.3376; //Slope
float b = 0.7165; //Y-Intercept
float R0 = 2.82; //Sensor Resistance in fresh air by calibrating
void loop() {
float sensor_volt; //Define variable for sensor voltage
float RS_gas; //Define variable for sensor resistance
float ratio; //Define variable for ratio
float sensorValue = analogRead(gas_sensor); //Read analog values of sensor
sensor_volt = sensorValue*(5.0/1023.0); //Convert analog values to voltage
RS_gas = ((5.0*10.0)/sensor_volt)-10.0; //Get value of RS in a gas
ratio = RS_gas/R0; // Get ratio RS_gas/RS_air
double ppm_log = (log10(ratio)-b)/m; //Get ppm value in linear scale according to the the ratio
value
double ppm = pow(10, ppm_log); //Convert ppm value to log scale
Serial.print("ppm Value = ");
Serial.println(ppm);
//to print volt value
Firebase.setFloat("Volt",sensor_volt);
// append a new value to /ppm value of vehicles logs
if(0<ppm<250)
String name = Firebase.pushFloat("ppm value log of vehicles of first type",ppm);
String name1= Firebase.pushString(name, "RIGHT");
//handle error
if (Firebase.failed()) {
Serial.print("pushing /ppm value log of vehicles of first type failed:");
Serial.println(Firebase.error());
return;
} }
else if(250<ppm<500)
String name2 = Firebase.pushFloat("ppm value log of vehicles of second type", ppm);
String name3= Firebase.pushString(name2, "ALMOST RIGHT");
//handle error
if (Firebase.failed()) {
Serial.print("pushing /ppm value log of vehicles of second type failed:");
Serial.println(Firebase.error());
return;
else
{ String name4= Firebase.pushFloat("ppm value log of vehicles of third type", ppm);
String name5= Firebase.pushString(name4, "WRONG+ACTION");
// handle error
if (Firebase.failed()) {
Serial.print("pushing /ppm value log of vehicles of third type failed:");
Serial.println(Firebase.error());
return;
} }
delay(30000);