#include <MQ2.h>
//change this with the pin that you use
int pin_1 = A0;
int pin_2 = A1;
int pin_3 = A2;
int lpg_1, co_1, smoke_1;
int lpg_2, co_2, smoke_2;
int lpg_3, co_3, smoke_3;
MQ2 mq2_1(pin_1);
MQ2 mq2_2(pin_2);
MQ2 mq2_3(pin_3);
void setup()
{
Serial.begin(9600);
mq2_1.begin();
mq2_2.begin();
mq2_3.begin();
}
void loop()
{
/*read the values from the sensor, it returns
*an array which contains 3 values.
* 1 = LPG in ppm
* 2 = CO in ppm
* 3 = SMOKE in ppm
*/
//float* values_1= mq2_1.read(true); //set it false if you don't want to print the values in the Serial
//lpg = values[0];
lpg_1 = mq2_1.readLPG();
lpg_2 = mq2_2.readLPG();
lpg_3 = mq2_3.readLPG();
//co = values[1];
co_1 = mq2_1.readCO();
co_2 = mq2_2.readCO();
co_3 = mq2_3.readCO();
//smoke = values[2];
smoke_1 = mq2_1.readSmoke();
smoke_2 = mq2_2.readSmoke();
smoke_3 = mq2_3.readSmoke();
if (lpg_1 > 10)
{
Serial.println(" Gas Leak Detected on Sensor 1");
Serial.println(" ");
}
if (lpg_2 > 10)
{
Serial.println(" Gas Leak Detected on Sensor 2");
Serial.println(" ");
}
if (lpg_3 > 10)
{
Serial.println(" Gas Leak Detected on Sensor 3");
Serial.println(" ");
}
delay(1000);
}