Here i attached a more clear view of the coding without the comment or any codes that does not affect anything
/************************Hardware Related Macros************************************/
#include <LiquidCrystal.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "xxxxxxxxxxxxx";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxx";
char pass[] = "xxxxxxxx";
const int calibrationLed = 13; //when the calibration start , LED pin 13 will light up , off when finish calibrating
const int MQ_PIN=A0; //define which analog input channel you are going to use
int RL_VALUE=5; //define the load resistance on the board, in kilo ohms
float RO_CLEAN_AIR_FACTOR=9.83;
//RO_CLEAR_AIR_FACTOR=(Sensor resistance in clean air)/RO,
//which is derived from the chart in datasheet
/***********************Software Related Macros************************************/
int CALIBARAION_SAMPLE_TIMES=50; //define how many samples you are going to take in the calibration phase
int CALIBRATION_SAMPLE_INTERVAL=500; //define the time interal(in milisecond) between each samples in the
//cablibration phase
int READ_SAMPLE_INTERVAL=50; //define how many samples you are going to take in normal operation
int READ_SAMPLE_TIMES=5; //define the time interal(in milisecond) between each samples in
//normal operation
/**********************Application Related Macros**********************************/
#define GAS_LPG 0
/*****************************Globals***********************************************/
float LPGCurve[3] = {2.3,0.21,-0.47}; //two points are taken from the curve.
//with these two points, a line is formed which is "approximately equivalent"
//to the original curve.
//data format:{ x, y, slope}; point1: (lg200, 0.21), point2: (lg10000, -0.59)
float Ro = 10; //Ro is initialized to 10 kilo ohms
const int rs = 11, en = 12, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7); //LCD pins
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
lcd.begin(16,2);
pinMode(10, OUTPUT);
pinMode(calibrationLed,OUTPUT);
digitalWrite(calibrationLed,HIGH);
lcd.print("Calibrating..."); //LCD display
Ro = MQCalibration(MQ_PIN); //Calibrating the sensor. Please make sure the sensor is in clean air
digitalWrite(calibrationLed,LOW);
lcd.print("done!"); //LCD display
lcd.setCursor(0,1);
lcd.print("Ro= ");
lcd.print(Ro);
lcd.print("kohm");
delay(3000);
}
void loop()
{
long iPPM_LPG = 0;
iPPM_LPG = MQGetGasPercentage(MQRead(MQ_PIN)/Ro,GAS_LPG);
Blynk.run();
if(iPPM_LPG > 50 )
{ digitalWrite(10,HIGH);
Blynk.notify("It is Over Flow!");
}
else
{digitalWrite(10,LOW);
Blynk.notify("It is Normal!");}
lcd.clear();
lcd.setCursor( 0 , 0 );
lcd.print("Concentration of gas ");
lcd.setCursor( 0 , 1 );
lcd.print("LPG: ");
lcd.print(iPPM_LPG);
lcd.print(" ppm");
delay(200);
}
float MQResistanceCalculation(int raw_adc)
{
return ( ((float)RL_VALUE*(1023-raw_adc)/raw_adc));
}
float MQCalibration(int mq_pin)
{
int i;
float val=0;
for (i=0;i<CALIBARAION_SAMPLE_TIMES;i++) { //take multiple samples
val += MQResistanceCalculation(analogRead(mq_pin));
delay(CALIBRATION_SAMPLE_INTERVAL);
}
val = val/CALIBARAION_SAMPLE_TIMES; //calculate the average value
val = val/RO_CLEAN_AIR_FACTOR; //divided by RO_CLEAN_AIR_FACTOR yields the Ro
return val; //according to the chart in the datasheet
}
float MQRead(int mq_pin)
{
int i;
float rs=0;
for (i=0;i<READ_SAMPLE_TIMES;i++) {
rs += MQResistanceCalculation(analogRead(mq_pin));
delay(READ_SAMPLE_INTERVAL);
}
rs = rs/READ_SAMPLE_TIMES;
return rs;
}
long MQGetGasPercentage(float rs_ro_ratio, int gas_id)
{
if ( gas_id == GAS_LPG ) {
return MQGetPercentage(rs_ro_ratio,LPGCurve);
}
return 0;
}
long MQGetPercentage(float rs_ro_ratio, float *pcurve)
{
return (pow(10,( ((log(rs_ro_ratio)-pcurve[1])/pcurve[2]) + pcurve[0])));
}