Arduino MQ135 Gas Sensor
first, the wiring
The MQ135 has 4 pins, VCC, GND, A0, D0, respectively, where VCC, GND, and A0 are required. The following diagram is a esp8266 wiring diagram. Due to the measurement of the gas value of PPM, it is related to the air temperature and humidity. So we've added a DHT22 here. DHT22 Portal
vcc->3v
Gnd->g
A0->a0
Second, MQ135 library
Download Address: https://github.com/zhao007z4/MQ135
After the download is complete, copy to the Arduino Library directory under Three, code
#define Dht_type DHT11
#define Dht_pin 2//pin d4
#define Analogpin A0
DHT DHT (Dht_pin, Dht_type);
MQ135 gassensor = MQ135 (Analogpin);
void Setup () {
Serial.begin (9600);
Dht.begin ();
}void Loop () {
Float h = dht.readhumidity ();
Read Temperature as Celsius (the default)
float T = dht.readtemperature ();
Check if any reads failed and exit early (to try again).
if (isNaN (h) | | | isNaN (t))
{
Serial.println ("Failed to read from DHT sensor!");
Delay (1000);
Return
}
Serial.print ("hum=");
Serial.print (h); This to display the Rzero value continuously, uncomment this to get PPM value
Serial.println ("%");
Serial.print ("temp=");
Serial.print (t); This to display the Rzero value continuously, uncomment this to get PPM value
Serial.println ("C");
Rzero = Gassensor.getrzero (); The Rzero value, uncomment this to get PPM value
Serial.print ("rzero=");
Serial.println (Rzero); This to display the Rzero value continuously, uncomment this to get PPM value
ppm = gassensor.getppm (); This to get the PPM value, uncomment this to get Rzero value
Serial.print ("ppm=");
SERIAL.PRINTLN (ppm); This to display the PPM value continuously, uncomment this to get Rzero value
ppmbalanced = gassensor.getcorrectedppm (t, h); This to get the PPM value, uncomment this to get Rzero value
Serial.print ("PPM corrected=");
Serial.println (ppmbalanced); This to display the PPM value continuously, uncomment this to get Rzero value
} Iv. Summary
From the MQ135 documentation, we learned that MQ135 need to warm up not less than 48 hours to work properly. Chinese Document Portal