 # Gas sensor MQ9

Hi again i’m trying to understand the (readings from the) gas sensor MQ9. I have been reading the code on Seedsstudio to try(!) and better understand the possibilities of this sensor.

As i bought the sensor, i thought i could read the ppm of the three separate gasses. It seems that’s not he case (noob here, so please correct me if i am wrong). As i read the code (seeds) i have to calibrate in my own clean environment and than use these calculated figures on the voltage output (=sensorvalue) of the sensor. Thus get a calculated output of the three gasses.

If so… how can i determine which of the gasses is high CO, LPG or CH4 ? The fact that it seems to use voltage and a calculated gas-separator indicates that such is not possible. If so, this sensor only reports the ppm of the sum of these three gasses.

Am i right thus far?

I started up the provided python code. The code immediately started with results:

(‘sensor_value =’, 83, ’ density =’, 0.0)
(‘sensor_value =’, 82, ’ density =’, 0.0)
(‘sensor_value =’, 84, ’ density =’, 0.0)
(‘sensor_value =’, 77, ’ density =’, 0.0)
(‘sensor_value =’, 84, ’ density =’, 0.0)
(‘sensor_value =’, 81, ’ density =’, 0.0)
(‘sensor_value =’, 86, ’ density =’, 0.0)
(‘sensor_value =’, 83, ’ density =’, 0.0)

The sensor value seems to hang around 84 but the density is always ‘o.o’. I guess this is not normal? What am i doing wrong?

Many thanks for the help!

Scoobs

Hi,
Looks like the code has a bug and the reason you are getting density as 0 is because it density here is the sensor_value/1024. If you just change it to `sensor_value/1024.0` you’ll get better values.

Looking at the example code that Seeed has given: http://www.seeedstudio.com/wiki/Grove_-_Gas_Sensor(MQ9) , you first have to do approximation to get the value of R0 and then feed that in another program to get the ratio of the gas. You’ll have to write 2 similar programs like the ones mentioned in Seeed’s wiki in Python to make the sensor give out good values.

-Karan

hello I made the changes you suggested how do I use this to chart in PPM?

Hey Juan,
If you have got to the point where you are able to get the Rs/R0 ratio, then I think you’ll have to find the equation of the line manually in that graph shown on the datasheet here: http://www.seeedstudio.com/wiki/Grove_-_Gas_Sensor(MQ9)and feed the ratio in the equation to get the ppm value. There is not a lot of information mentioned on the Grove sensors page other than that.

-Karan

Hi Karen!

Thank you for your quick response… I have a couple of quick questions…

1. How can I get the RS/RO values <---- Do I use the manufactures data sheets?
2. Once I have those values how do I use them with the the ‘sensor_value’ and density?

There is no info on seeedstudio or on this website on how to obtain these or convert them to Parts Per Million…
I have also looked in your forums and blogs…

So I am able to get the sensor_value = XX and density = X.XXXXXXXXX I was able to find the data sheets for the sensor it is not directly found from the link you posted but thank you for pointing me in the right direction. The link for the sensor is here:
http://www.seeedstudio.com/wiki/Grove_-_Gas_Sensor(MQ9)
and
http://www.seeedstudio.com/wiki/images/f/f2/MQ-9.pdf

I can use the data sheet for the equation necessary for estimates and regression. I am using Excel in my case, entering the data curve with as many points as I can and graphing it in Excel. I add a trend line and choose a potential equation. Now that I have the equation… how do I use sensor_value = XX and density = X.XXXXXXXXX??? If you or anyone could point me in the right direction I would really appreciate it. Hey Juan,
Once you are able to read the sensor value, then follow the example 2 here http://www.seeedstudio.com/wiki/Grove_-_Gas_Sensor(MQ9) to find out the RS/R0 ratio:

``````sensor_volt=(float)sensorValue/1024*5.0;
RS_gas = (5.0-sensor_volt)/sensor_volt;
ratio = RS_gas/R0;  // ratio = RS/R0;
``````

use the first example on that page to find out R0.

Now feed this ratio to the equation you got from the excel sheet to get the output.

Do let us know how it goes.

-Karan

Hey Karen I will give it a try and get back to you thank you soo much…

Hi Karen… or anyone else whom might be able to help.

I am stuck the code in the link above is written for Arduino and I am using a grovepi+ with a Raspberry PI3 to read the MQ-9. I can not get the value of “R0” to feed it into the statement:

`ratio = RS_gas/R0 # <–Replace the name "R0" with the value of R0 in the demo of First Test`

is there a python script I could use to get the “R0” value? or can I use the statement:

`density = (float)(sensor_value / 1024.0)`

in some way?

The following is the python code I am trying based off of the Arduino code:

``````#!/usr/bin/env python
# -*- coding: latin-1 -*-

import sys
sys.path.append(&#039;/home/pi/GrovePi/Software/Python/&#039;)
import os
import time
import math
import decimal
import grovepi
from grovepi import *
import random

# Connections
MQ9_gas_sensor = 1

# Initializing variables
grovepi.pinMode(MQ9_gas_sensor,&quot;INPUT&quot;)

count = 0
while True:
try:
#Get a average data by testing 100 times
while(count &lt; 100):
count = count +1
print (&quot;Calibrating...&quot;), count,(&quot;%&quot;), (&quot;  Sensor Value =&quot;), sensor_value

sensor_value=(float)(sensor_value/100.0)
sensor_volt=(float)(sensor_value/1024.0)*5.0
RS_air=(float)(5.0-sensor_volt)/sensor_volt #omit *RL
R0 = (float)(RS_air/9.9)
print(&quot;sensor volt =&quot;), sensor_volt,(&quot;V&quot;)
print(&quot;R0 =&quot;), R0
time.sleep(1)
except (IOError,TypeError) as e:
print &quot;Error&quot; + str(e)
except KeyboardInterrupt:
break
exit()
``````

The result is…

``````
...
Calibrating... 99 % Sensor Value = 18
Calibrating... 100 % Sensor Value = 13
sensor volt = 0.000634765625 V
R0 = 795.547785548
sensor volt = 6.34765625e-06 V
R0 = 79564.7785548
sensor volt = 6.34765625e-08 V
R0 = 7956487.85548
sensor volt = 6.34765625e-10 V
R0 = 795648795.548
sensor volt = 6.34765625e-12 V
R0 = 79564879564.8
sensor volt = 6.34765625e-14 V
R0 = 7.95648795649e+12
sensor volt = 6.34765625e-16 V
R0 = 7.95648795649e+14
sensor volt = 6.34765625e-18 V
R0 = 7.95648795649e+16
sensor volt = 6.34765625e-20 V
R0 = 7.95648795649e+18

...

``````

I am not sure if this is correct?

Hey Juan,
Looks like you are trying to save 100 values and average them to get RS_air. You are not summing the 100 values. You should add them and then divide by 100 to get an average value.

Can you try that out.

-Karan

Thank you Karen,
The R0 values I am getting are inconsistent. I might just start using controleverything.com Sensors. They have python code that will give you the PPM for Carbon Monoxide…