Hi,
I’m learning to program using Particle Photon.
I have a MQ135 Gas sensor.
I use the example code from the library I imported, but the readings I get are around 4-8 PPM, where it should be around 400 PPM.
When I breathe on the sensor, I can see a change in the values so the sensor does read something,
The sensor is connected directly to A0, VIN, GND.
I have tried to leave it plugged in for the night.
Attached is the
include "MQ135/MQ135.h"
int number = 0;
int state = 0;
MQ135 gasSensor = MQ135(0);
int led = D7;
float rzero = gasSensor.getRZero();
int ppm = gasSensor.getPPM();
// SETUP
void setup() {
}
// LOOP
void loop() {
float rzero = gasSensor.getRZero();
digitalWrite(led,HIGH); // turn the ledPin on
delay(100); // stop the program for some time
digitalWrite(led, LOW); // turn the ledPin off
delay(100); // stop the program for some time
int co2_ppm = gasSensor.getPPM();
int ppm = co2_ppm / 4;
Spark.variable("ppm", &ppm, INT);
Particle.publish("PPM", String(ppm));
delay(10000);
}
That’s not how you use Particle.variable() - the variable only gets set up once in setup().
Have you allowed for enough time for the sensor to heat up?
How have you got the sensor wired?
That library was not ported properly! It still uses the Arduino conversion with 1023 @ 5V where for Photon it would be 4095 @ 3.3V.
I left the sensor plugged in overnight, so it should have pre heated. I also tried to adjust the potentiometer on the back of it. However I am still not getting anything close to 400 ppm.
How do I go about and change the Arduino conversion to 4095 @3.3v?
Since you forked the lib, you can add some Serial.print() statements to get the raw analog reading and also some of the sub-results in the calculation.
When I use the original Git library, my readings are around 4-5ppm
My sketch looks like this now:
include "MQ135/MQ135.h"
int number = 0;
int state = 0;
MQ135 gasSensor = MQ135(0);
int led = D7;
float rzero = gasSensor.getRZero();
int ppm = gasSensor.getPPM();
// SETUP
void setup() {
Particle.variable("ppm", ppm);
}
// LOOP
void loop() {
float rzero = gasSensor.getRZero();
digitalWrite(led,HIGH); // turn the ledPin on
delay(100); // stop the program for some time
digitalWrite(led, LOW); // turn the ledPin off
delay(100); // stop the program for some time
int co2_ppm = gasSensor.getPPM();
int ppm = co2_ppm / 4;
Particle.publish("ppm", String(ppm));
delay(10000);
}
Should I add it to one of the files from Github, or directly in my sketch?
Have you had success with the MQ-135 and the library in the web IDE? I am a little bit nurvous, that there is a mistake in the library, makes me wonder if there is more than one. I am struggling to find a set of sample code for the photon, that works out of the box like for the DHT sensor or audiosensors.
I have no such sensor, so I can’t check.
But the library isn’t really that complicated. Most functions are one- or two-liners.
Pulling the relevant ones directly into your project file and adding the debug statements would be what I’d do.
There are also other threads in this forum dealing with this sensor - just have a search.