How can I convert AnalogRead to something useful?

No experience myself but a little google resulted in:

The datasheet is not the most clear one I've seen. This is what I understand:

  • The MQ7 is not easiest sensor
  • it is temperature and humdity sensitive (but in a first experiment this may be ignored)
  • you need to calibrate it before it can be used.
  • the reference is 100 PPM (but it uses a 10K for RL)
  • you should read a value at the end of the 1.4Volt modus when it peaks. (point b page 3)

That all said I come to something like:

The formula Rs\RL = (Vc-VRL) / VRL can be rewritten to Rs = RL * (Vc-VRL) / VRL
Vc = 5 Volts (I assume)

bringing this into the formula:

float Vrl = 5.0 * analogRead(A1) / 1023;
float Rs = 20K * ( 5.0 - Vrl) / Vrl;

So now you have a formula to make the reference measurement Ro.

If you make a measurement Rs then you can calculate the ratio Rs/Ro which can be looked up the diagram in the datasheet. To do this automagically you need to create a lookup table. The Rs/R0 varies from 0.05 - 1.5. As floats cannot be used as an index for a lookup table you better multiply them with 20 giving the values 1..30. The table is filled with PPM values.

This results in code something like below. (not complete, only indicative code, no guarantees, all disclaimers apply :slight_smile:

float Ro = xxx.yyy;

void setup()
{
}

void loop()
{
  waitForTheRightMoment();  // to be elabotated.
 
  float Vrl = 5.0 * analogRead(A1) / 1023;
  float Rs = 20K * ( 5.0 - Vrl) / Vrl;
  int ratio = 20 * Rs/Ro;
  ratio = constrain(ratio, 0, 30);
  Serial.print ( "CO :");
  Serial.println(LUT[ratio]);

}

Should help you forwards
rob

-- update --