0% found this document useful (0 votes)
30 views

Test Code

This code develops an executable program for an IoT-based automobile exhaust monitoring project using the Arduino IDE software. The code connects to WiFi, initializes the gas sensor on analog pin A0, calculates the ppm level based on sensor readings, and pushes the voltage and ppm values to a Firebase database, categorizing the results as right, almost right, or wrong based on thresholds. It then delays 30 seconds before repeating the process.

Uploaded by

Esha Pal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Test Code

This code develops an executable program for an IoT-based automobile exhaust monitoring project using the Arduino IDE software. The code connects to WiFi, initializes the gas sensor on analog pin A0, calculates the ppm level based on sensor readings, and pushes the voltage and ppm values to a Firebase database, categorizing the results as right, almost right, or wrong based on thresholds. It then delays 30 seconds before repeating the process.

Uploaded by

Esha Pal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

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);

You might also like