Methane (CH4) sensors for grow chambers and tanks, Interfacing with embedded CPUs, ADC conversions ppm

Methane (CH4) sensors for grow chambers and tanksMethane is part of the Methane/Ozone cycle.  When CH4 (methane) is created from microbes decomposing organic material and releasing CH4, CO2 and H2O into the air.  Methane rises into the air and mixes with hydroxides created from Ozone mixing with water vapor.  Methane is monitored in CELSS along with CO2 for monitoring decomposition.  Below is a link for CELSS description.

Description of CELSS

Methane Sensor Circuit

The sensor works like an old style vacuum tube.  There is a heater that uses about 1 watt of power.  Heat from the heater acts like a bridge between two electrodes.  The variation in methane content in the air varies the current through the sensor.  The current is log rhythmically proportional to the ppm of CH4 in the air. 

 

Ozone Sensor

The sensor is stacked on the top of a 100K resistor with a 5 volt regulated power supply.  It takes roughly 24 hours for the sensor to stabilize.  Usable readings can be measured in 2 or 3 minutes. 

 

Connections to PIC18F4550

There is no much filter done on the signal input.  The resistive bridge between the 100K resistor and methane sensor directly enters into the ADC.  The reference voltage for the ADC is default to +5 volts.  That means 5 volts is divided into 1024 measurement levels.    

 

 

Methane Sensor ADC to ppm Conversion

All data is collected using a 10 bit ADC (Analog to Digital Converter)   This gives 1024 levels of voltage measurement.  All samples are averaged using 40 readings.  See software routines at the bottom of this posting.

To use the charts we need to calculate the ratio of Rs/Ro.  Or in other words, we need to solve for Rs.  Find the ratio of Rs/Ro and look it up on the provided sensor graph.  Rs is the resistance value of the sensor at any given time.  This is calculated by taking the measured voltage across the sensor and dividing it by the current.  See the equations below…

For automating the calculation using the provided graph, we need to find the slope of the curve and make it into an equation (y = mx +b).  In this case the sensor works log rhythmically.  This means the slope changes every decade by a factor of 10.  Hence we use log base 10.  The y = mx + b can be converted into a log rhythmic version of the linear version.  See the conversion equation at the bottom of the set of equations above.  The ppm of Methane is a sum of two exponential calculations.

 

Methane Sensor Curves

The relationship between ppm of CH4 and the resistance ratio Rs/Ro.  Rs/Ro is the amount of CH4 when Rs = Ro, or 1.  The amount of CH4 is 1000 ppm.  See the graph below.  The graph is constructed for 25% Relative Humidity.  The Rs/Ro needs to be shifted if the sensor is used.

 

Methane Software and Routines

The last step to make an automated methane sensor is constructing routines that can be called in an RTOS.  Below are callable routines in C.  The routines call each other.  You need to call one routine to read the methane value and the CPU goes out an gets the measurements, averages  and converts the ADC value into ppm.  See routines below.

//************************************************************
// Created Nov. 30, 2012
//This routines converts the raw data from the ADC into data for CH4.  The units is returned in ppm.
//There are a lot of log funtions to slow the RTOS.
//************************************************************
int16 ScaleToMethane(int16 AveragedADCReading)
 {
 float VRecycled1,VRecycled2;

// Find the Vin across the bottom 100K resistor
 VRecycled1 = (AveragedADCReading * 5.0)/1024.0;

 VRecycled2 = 5.0 * ( 1.0 – (AveragedADCReading/1024.0));   // Voltage over the sensor

 VRecycled1 = (5.0 * AveragedADCReading/1024.0)/100000.0;  //  Current through sensor

 VRecycled1 = VRecycled2/VRecycled1;   // E/I = R

// Ratio the resistance with Ro/Rs
 VRecycled1 = VRecycled1/100000.0;   // Rs is the optimal resistance at normal temperature.

//  Next is the mapping to the CH4 plot graph

 VRecycled1 = 1000 * pow(VRecycled1,-2.884);  //  This converts the ADV average for the resistance over the ssnesor into ppm of CH4 or Methane.

 return((int16)(VRecycled1));   //Return the value
 }

 //*************************************************************
// Created Nov. 6, 2012
//  This routine reads an ADC and averages 16 samples into one and returns the number.
// There is no scaling or any signal condition excepct for a low pass averaging filter.
//  The input selection is for ADC 1, 2 and 3.  The numbers 0, 1 and 2 are used for selecting the ADC.
//*************************************************************

int16 GetADCValue(int selection)
 {
 int16 ReturnedADC, Summer; 
 int f;
     set_adc_channel(selection);
     Summer=0;
     for (f=0; f < 40; f++)
      {
     delay_us(10);
     Summer = Summer + read_adc(); // Read adc channel 0
      }
     ReturnedADC = Summer/40;
 if (selection == 1)
  {
  return(ScaleToMethane(ReturnedADC));  // Convert into Methane ppm from raw data.
  }
 if (selection == 2)
  {
  return(ScaleToOzone(ReturnedADC));  // Convert into Methane ppm from raw data.
  } 
 }

 

//********************************************************************
// Created Nov 6, 2012
// This inits all of the ADC convereters for input.
//  There is no output from this funtion.
//********************************************************************
void SetupADC(void)
 {
 setup_adc_ports(AN0_TO_AN2);  //Set up AD0, AD1 and AD2 for ADC inputs.
    setup_adc(ADC_CLOCK_INTERNAL);
 }

One Response to “Methane (CH4) sensors for grow chambers and tanks, Interfacing with embedded CPUs, ADC conversions ppm”

  1. baieswar says:

    Can you please let us know how exactly did you derive the formula,
    Log(F(x))=m*Log(X)+b m=Log[10000/1000]/Log[0.45/1]=-2.884 from the graph given in MQ-.

    We are using the MQ-7 gas sensor for which the graph seems to be different than the one you have pasted above. We could not find any formula to calculate the Rs/R0 (we have formula for Rs but there is no much information about deriving R0 ) value in the user guide of MQ-7.

    Please help us in forming the formula for measuring the Corbon Monoxide and mithane in PPM from the graph given in MQ-7′s user guide.

Leave a Reply