Skip to content

Instantly share code, notes, and snippets.

@kakopappa
Created November 3, 2023 02:04
Show Gist options
  • Save kakopappa/8222c51084122bd9f6b195cb878ae070 to your computer and use it in GitHub Desktop.
Save kakopappa/8222c51084122bd9f6b195cb878ae070 to your computer and use it in GitHub Desktop.
#include <TroykaMQ.h> // https://github.com/amperka/TroykaMQ
#if defined(ESP8266)
#define SENSOR_PIN A0
#elif defined(ESP32)
#define SENSOR_PIN 34
#endif
MQ135 mq135(SENSOR_PIN);
void setup() {
Serial.begin(9600);
// before calibrating the sensor, warm it up for 60 seconds calibrate the sensor in clean air
mq135.calibrate();
// if you know the resistance of the sensor in clean air
// you can specify it manually, eg: 160 mq135.calibrate(160);
Serial.print("Ro = ");
Serial.println(mq135.getRo());
}
void loop() {
// display gas values in ppm
Serial.print(mq135.readCO2());
Serial.println("ppm");
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment