Close

Getting PPM values from the sensor(1)

A project log for Wearable CO monitor

A wearable CO monitor that uses an ESP8266

rahoon-goawayRahoon GOAWAY 01/12/2019 at 11:280 Comments

I'm currently testing everything on my Arduino UNO before I start using the ESP

I'm trying to get PPM values from the sensor through the analogRead function. First I plotted a Rs/Ro to PPM graph in excel from the datasheet of the MQ9 gas sensor. Then I used the trendline function to get the formula and I've put it in the Arduino IDE so it can calculate the PPM.

void setup() {
  Serial.begin(9600);
}

void loop() {
  int input = analogRead(A0);
  float Volts = input*5/1024;
  float ratio = (100000000*Volts)/(5-Volts);
  float ratiox = pow(ratio,-2.625);
  float ppm = (3572.6*ratiox);
  Serial.print("ppm=");
  Serial.println(ppm);
  delay(500);
  
}

Unfortunately, the Arduino is having trouble with the maths and is returning 'inf' in the serial monitor, which I think stands for infinity. So I'm reading each line of maths in the serial monitor to find the problem and (hopefully) fix it.

What I'm doing here is loosely based of this video(https://www.youtube(dot)com/watch?v=fBo3Yq9LK1U), but I can't understand what's going on in the code displayed there(at 8:39), so I'm trying this.

Discussions