Yes, change the sensor. I have spent a lot of time trying to get reliable reading from MQ-135 but at the end just moved on to MH-Z14A. Much more reliable sensor and works out of the box

What calculation are you using on the Photon?

Did you adjust the formula to cater for 4095 @ 3.3V readings while the Arduino gives you 1023 @ 5V?

What’s the output impedance of the sensor? You might want to add an impedance converter circuit which can also do the 5V to 3.3V adjustment.

Or you go with @alexsh1

@alexsh1 We’re talking about MQ135 for less than $2 and MH-Z14A for minimum $35. Sure the sensor itself looks very promising, but expensive for my use case & design.

@ScruffR Calculation on the photon is almost the same except for the fact that the PPM calculated with the same method as Arduino, gets divided by “4”. Sorry I mentioned this as “Zero” in my first post in this thread.

**On Arduino:**

```
float co2_ppm = gasSensor.getPPM();
```

returns 0.22

**On Photon:**

MQ135 Library at Particle Web IDE has given an example code and from that:

```
float co2_ppm = gasSensor.getPPM();
float ppm = co2_ppm / 4;
```

returns 150

Here co2_ppm gets divided by “4”, probably for the fact that 1023*4 = 4092

getPPM() function is same for both platforms and as follows:

```
float MQ135::getPPM() {
return PARA * pow((getResistance()/RZERO), -PARB);
}
float MQ135::getResistance() {
int val = analogRead(_pin);
return ((1023./(float)val) * 5. - 1.)*RLOAD;
}
```

I didn’t calculate much… Just looking at the numbers in the getResistance() function included in MQ135.cpp

I did change the number 1023 to 4095. Also I assumed the number 5 in that is 5volts and changed it to 3.3.

```
float MQ135::getResistance() {
int val = analogRead(_pin);
return ((4095./(float)val) * 3.3 - 1.)*RLOAD;
}
```

RAW returns 1060

PPM returns 35

Output impedance of the sensor… I calculated the resistance between MQ135’s Analog Out Pin and Ground while the sensor is removed from the circuit and it showed 1K Ohm. Is this how we measure output impedance? Is this what you mean? Just to be sure, i tried these too…

```
float MQ135::getResistance() {
int val = analogRead(_pin);
return ((4095./(float)val) * 3.3 - 1.)*1; // Changed RLOAD(Resistance Load) to 1 as the output impedance measured 1KOhm
}
```

And I didn’t divide PPM from this by 4…

RAW returns 1100

PPM returns 41

Still PPM values of 35 & 41 is no where close to the PPM value of 0.22 returned by Arduino…

Since I’ve changed “1023 to 4095” and “5 to 3.3”, I don’t need to divide this PPM by 4, right? And, if at all I do, it approximates to 9-10…

How exactly do I add an impedance converter circuit that can do the 5V to 3.3V adjustment. Can you refer any closest possible example to do this for my use case?

It’s your call surely, but you get what you pay for. I’m sure there are other cheaper sensors than MH-Z14

There is another thread you could have a look at.

MQ135 CO2 PPM Calculation

And this discussion also continued here

Connecting 5V devices to Photon?

Hi,

I want to know how a and b coefficients you? Since its not clearly explained I stuck in this power regression. I tried plotting graph also but I’m not getting those coefficient values for Co2.

how this values got CO2Curve[2] = {113.7105289, -3.019713765};??

I’m not clearly getting from that website.