MQ-7 support

Moderators: grovkillen, TD-er, Stuntteam

Post Reply
Message
Author
Rampler
Normal user
Posts: 40
Joined: 31 Dec 2016, 07:13

MQ-7 support

#1 Post by Rampler » 27 Dec 2019, 15:26

Hi together,
has anybody writen already a plugin for the mq-7 sensor ?

According to MQ-7 datasheet, sensor has to run through high- and low-heating cycles in order to get proper measurements. During low temperature phase, CO is absorbed on the plate, producing meaningful data. During high temperature phase, absorbed CO and other compounds evaporate from the sensor plate, cleaning it for the next measurement.

So in general operation is simple:

1. Apply 5V for 60 seconds, don't use these readings for CO measurement.

2. Apply 1.4V for 90 seconds, use these readings for CO measurement.

3. Go to step 1.

Shardan
Normal user
Posts: 1156
Joined: 03 Sep 2016, 23:27
Location: Bielefeld / Germany

Re: MQ-7 support

#2 Post by Shardan » 27 Dec 2019, 21:26

A plugin is not really necessary for MQ-7, as far as i can see from the datasheet.
Timing can be done with the internal timer commands of ESP.
Use a timer for 5V-heating, setting a GPIO to switch to 5V via a transistor.
At the end of 5V-heating start a timer for measuring period.
The value could be read via analog input.
To avoid values while 5V-heating is on, push the value from the measurement
period into a dummy value at the end of measurint time.
Then the first timer can be restartet to heat up again.

I recommend to use a voltage divider as load resistance. The sensor needs 5V for
measurement, the output value varies from 0,4V (0 ppm CO) to about 3,5V at 150 ppm CO.
The ESP itself can take up to 1V at analog input, some boards like the WeMos have a voltage
divider built in, they can take up to 3V usually.

Please keep in mind that the sensor output is not really linear.
At CO-values up to 150 ppm it's nearly linear, above 150 ppm the curve flattens out.
I recommend to use the range up to 150 ppm as that is already a quite dangerous value.

Another point: the output isn't zero at 0 ppm CO, it needs a formula or a calculation in
rules to get rid of the zero offset.

Values derived from datasheet at
https://cdn.sparkfun.com/datasheets/Sen ... Manual.pdf
Regards
Shardan

Rampler
Normal user
Posts: 40
Joined: 31 Dec 2016, 07:13

Re: MQ-7 support

#3 Post by Rampler » 27 Dec 2019, 21:54

Thank you for the detailed statements made. It is very useful.

Rampler
Normal user
Posts: 40
Joined: 31 Dec 2016, 07:13

Re: MQ-7 support

#4 Post by Rampler » 28 Dec 2019, 13:06

Nevertheless a formula for vdc to ppm would be nice.
Today i will give it a try with pwm for 1.4 V and a npn transistor. For the intervalls i will use the timerset commands.
Is it even possible to get reasonably realistic values for co?

User avatar
grovkillen
Core team member
Posts: 3584
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: MQ-7 support

#5 Post by grovkillen » 28 Dec 2019, 15:11

The formula is up to you to create, it's a specific field that you can use for that.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

Shardan
Normal user
Posts: 1156
Joined: 03 Sep 2016, 23:27
Location: Bielefeld / Germany

Re: MQ-7 support

#6 Post by Shardan » 28 Dec 2019, 16:58

The AD input of ESP's works from 0..1 V, dividing this into values from 0..1023.
So 0,5V will give an output of 512 from the AD.

Further info in my "Basics" at ESPEasy Wiki:
https://letscontrolit.com/wiki/index.ph ... Converters

I'll try to make up an example. Please keep in mind that this is not tested,
it's just based on the datasheet, it definitely will need fine tuning.

This assumes you're using a bare ESP.
Testboards like WeMos or nodeMCU often have a built-in voltage divider
raising the range to 0...3 V. In this case another circuit with other resistor
values is necessary.

As datasheet says they use 4,7KOhm for the external resistor.
For connecting to ESP I'd use a voltage divider 3,3KOhm/1,2KOhm.
This should give about 0,93V for the AD input at 150ppm CO.

0,93V * 1023 steps gives an outpout from the AD of 951.
Now we have to take care of the zero offset. Due to the diagrams
in the datasheet the sensor gives about 0,4V at 0 ppm CO, the voltage divider
cuts this down to about 0,1V

0,1V * 1023 steps gives an output of about 102.

So first step of formula is subtracting 102 from the given Value from the AD.

Now, for 150 ppm CO we have a raw value of 849.

849 corresponds with 150 ppm CO so we can calculate a factor.

150 / 849 = 0,177.

So at last the formula is:
CO value = (<AD output> - <Zero Offset> ) * 0,177

Some hints:

Heating period:
I won't use PWM for the low voltage as it might cause some problems.
Try easier this way:
5V --> Sensor Heating --> 100 Ohm Resistor --> Ground.
Then use the NPN or a small FET to short circuit the 100 Ohm Resistor.
No PWM, just a GPIO: GPIO on = Heating, Resistor short circuited and
GPIO off: Resistor reduces heating voltage, measuring period.

Calibrating zero offset:
At very first: Let the sensor heating periods work for at least 48 hours to "burn in" the sensor.
Put the circuit into free air or open Windows for some minutes, to make sure the air is clean.
After some measuring periods the raw output from the AD gives the zero value.
Put the value into the formula shown above.

Calibration:
Basically a calibration is possible, but i assume it is out of reach for most DIYer.
It would need a small clima chamber and a defined test gas, that's a bit much.
The way shown above gives a value back that most likely isn't very exact, it relies
on a lot of datasheet data and such that may vary in practice.
Anyways it's the thing we can do with home equipment.

Another point: The zero offset may vary over time, driven by temperature
and/or aging. So a recalibration now and then might be usefull.

I'd prefer calculating in rules, this might be a bit much for the formula field.
Suggestion: Use rules and a dummy variable for storing interim values.
This on top gives the advantage of more control over the values if something goes wrong.
Regards
Shardan

Rampler
Normal user
Posts: 40
Joined: 31 Dec 2016, 07:13

Re: MQ-7 support

#7 Post by Rampler » 29 Dec 2019, 13:05

Unfortunately, instead of an MQ-7 sensor, an mq-9 was delivered, but anyway I built something together.
I think the MQ-7 is much more accurate for CO measurements. In addition, the data sheet of the MQ-9 sensor is not sufficient in my opinion.
The formula is only valid for the MQ-7 sensor. So far, it doesn't look bad in the first draft:
Rules:

Code: Select all

on System#Boot do
  timerSet,1,5
endon

on Rules#Timer=1 do 
 gpio,5,1
 timerSet,2,60
endon

on Rules#Timer=2 do 
 gpio,5,0 
 timerSet,3,45  
endon

on Rules#Timer=3 do 
 publish /ESP-Test/CO, [co#ppm] 
 timerSet,1,45 
endon

on button#calibrate=1 do
gpio,5,1
timerSet,2,0
timerSet,3,0
timerSet,1,172800  // Calibrate 48 h 172800
endon
Unbenannt.JPG
Unbenannt.JPG (51.08 KiB) Viewed 3486 times
I have already ordered a new MQ-7 Sensor, in the maenwhile a play with MQ-9. I am not sure, when to read the co value, in the middle of the 90 seconds intervall ?

http://www.sensorica.ru/pdf/MQ-9.pdf
dddd.JPG
dddd.JPG (32.13 KiB) Viewed 3486 times
Attachments
co.JPG
co.JPG (37.79 KiB) Viewed 3486 times

Shardan
Normal user
Posts: 1156
Joined: 03 Sep 2016, 23:27
Location: Bielefeld / Germany

Re: MQ-7 support

#8 Post by Shardan » 29 Dec 2019, 13:34

Hello again.

First, the circuit looks good to me.

I've copied the signal diagram from the MQ-9 datasheet:
.
MQ-9_Signal.jpg
MQ-9_Signal.jpg (39.97 KiB) Viewed 3481 times
.
The upper line is the heating/measuring voltage, the lower one is the output signal.
Looking at this diagram I think taking the value at the end of the measurement period
should work best as it seems the signal needs a while to settle down.
So in my opinion the flow should be roughly like this:
- High voltage for heating (x seconds)
- Low voltage for measurement (y seconds)
- take value
- repeat
Regards
Shardan

Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests