Interfacing MQ-3 Gas Sensor with evive

MQ-2-Gas-Sensor-2
About This Tutorial
In this tutorial, you will learn how MQ3 gas sensor works, how to interface the sensor with evive and how to calculate the PPM value for different gases.
Tutorial Info

Components Required

Introduction

Gas sensors are designed to measure the concentration of gases in the environment. MQ3 gas sensor is suitable for detecting H2, LPG, CH4, CO, Alcohol, Smoke or Propane. Due to its high sensitivity and fast response time, measurement can be taken as soon as possible.

evive Notes Icon
Note: The sensor value only reflects the approximated trend of gas concentration in a permissible error range, it DOES NOT represent the exact gas concentration. The detection of certain components in the air usually requires a more precise and costly instrument, which cannot be done with a single gas sensor.

MQ series sensor uses a small heater inside with an electrochemical sensor in order to measure a different kind of gases combination. They can be calibrated, but, in order to do that, a known concentration of measured gas or gases is needed. In our case, we will test it, as it comes from the producer without any additional calibration. The MQ3 Gas sensor has a built-in variable resistor that changes its value according to the concentration of gas. If the concentration is High, the resistance decreases,  if the concentration is low, the resistance increases. Besides the built-in resistor, it is necessary to include load resistor, Load resistor serve to adjust sensor sensitivity and accuracy, it’s value can range from 2k ohm to 47 k ohm higher the value, the more sensitive sensor becomes.

Pin description

MQ3 Gas sensor has 4 pins

  • VCC
  • GND
  • AOUT  (Analog Output pin)
  • DOUT  (Digital Output pin)

Circuit diagram

 

  • Connect “VCC” of the MQ3 gas sensor with “VCC” of evive 
  • Connect “GND” of MQ3 gas sensor with “GND” of evive
  • Connect “Aout ” pin of MQ3 gas sensor with ” A0″ pin of evive

 

Equations

MQ3 Gas Sensor Sensitivity Characteristics:

Gas Sensor MQ3

 

The graph tells us the concentration of a gas in part per million (ppm) according to the resistance ratio of the sensor (RS/R0).

  1. RS is the resistance of the sensor that changes depending on the concentration of gas.
  2. R0 is the resistance of the sensor at a known concentration without the presence of other gases, or in the fresh air.

For air, RS/R0 = 60 for MQ3 gas sensor.

evive Notes Icon
Note: According to the graph, we can see that the minimum concentration we can test is 0.1ppm and the maximum is 10ppm. Values between 0.1 to 10ppm will be more accurate for the sensor.

Calculation of R0 for the Sensor

RS = [(Vin x RL) / Vout] - RL
  1. Vin is 5V in our case.
  2. RL is 10 kOhm
  3. Vout is the analog voltage reading from the sensor

We can simplify the above formula by omitting RL:

RS = (Vin - Vout) / Vout

From the graph, we can see that the resistance ratio in fresh air is a constant:

RS / R0 = 60 

To calculate R0 we will need to find the value of the RS in the fresh air using the above formula. This will be done by taking the analog average readings from the sensor and converting it to voltage. Then we will use the RS formula to find R0.

R0 = RS / 60

Calculating PPM for a particular gas

Let’s analyze the graph:

  1. The scale of the graph is log-log. This means that in a linear scale, the behavior of the gas concentration with respect to the resistance ratio is exponential.
  2. The data for gas concentration only ranges from 0.1 to 10 ppm.
  3. Even though the relation between resistance ratio and gas concentration may seem linear, in reality, it is not.

First of all, we will treat the lines as if they were linear. This way we can use one formula that linearly relates the ratio and the concentration. By doing so, we can find the concentration of a gas at any ratio value even outside of the graph’s boundaries. The formula we will be using is the equation for a line, but for a log-log scale. The formula for a line is:

  y = mx + b  

Where:

y: X value 
x: X value 
m: Slope of the line 
b: Y intercept  

For a log-log scale, the formula looks like this:  

  log(y) = m*log(x) + b  
evive Notes Icon
Note: the log is base 10.

Okay, let’s find the slope. To do so, we need to choose 2 points from the graph.

In our case, we chose the points (0.1,51) and (10,14) from the LPG line. The formula to calculate m is the following:

m = [log(y) - log(y0)] / [log(x) - log(x0)]

If we apply the logarithmic quotient rule we get the following:

m = log(y/y0) / log(x/x0)

Now we substitute the values for x, x0, y, and y0:

m = log(14/51) / log(10/0.1)
m = -0.33

Now that we have m, we can calculate the y-intercept. To do so, we need to choose one point from the graph (once again from the LPG line). In our case, we chose (6,16)

log(y) = m*log(x) + b
b = log(y) - m*log(x)
b = log(16) - (-0.33)*log(6)
b = 2.426

Now that we have m and b, we can find the gas concentration for any ratio with the following formula:

log(x) = [log(y) - b] / m

However, in order to get the real value of the gas concentration according to the log-log plot we need to find the inverse log of x:

x = 10 ^ {[log(y) - b] / m}

In the table given below, you can find the value of m and b for different gases.

GasValue at 0.1Value at 10Value at 6mb
Alcohol2.30.120.16-0.7548965471.996459667
Benzine4.10.70.9-0.4518536611.625635649
Methane514041-0.0621024411.842498924
Hexane511013-0.4164700812.654453691
LPG511416-0.3304603022.426482727
CO511.620-0.8849186214.574317431

PictoBlox (Scratch Program)

evive Notes Icon
Note: We will write the code in Stage Mode.

There are two steps to calculate PPM for the gas:

  1. First, we will calculate the value of R0. To calculate R0 we need to find out the value of Rs in the fresh air, this will be done by taking analog average readings from the sensor and converting it into the corresponding voltage value, then we will use above formula to calculate R0, wait until we get the stable value of R0. Make this script in the PictoBlox to get the value of R0.
    Calculating R0 value
    Download the program from here: Gas Sensor Calculating R0 value for MQ3 Sensor
    Run the code and find a stable value of R0. Usually, it takes 5-10 min to get a stable value.
    evive Alert
    Alert: Do not disconnect the device in-between.

    After 10 minutes the value is stabilized to 0.0507.
    Calculating R0 value

  2. After that, we will use the above-calculated value of R0 to find out the concentration of gases in ppm. If the ppm is higher than 5, then the Pin 13 LED will glow.
    evive Notes Icon
    Note: You have to replace the value of R0 in the program with the value you have got in the previous program.

    Calculating PPM
    Download the program from here: Gas Sensor Calculating PPM for MQ2 Sensor and LPG Gas

Calculating PPM

evive Notes Icon
Note: If you want to detect other gases, change the value of b and m in the program according to the sensor from the table.

Share this Tutorial
Share on facebook
Facebook
Share on twitter
Twitter
Share on google
Google+
Share on pinterest
Pinterest
Share on reddit
Reddit
Share on print
Print
Related Projects & Tutorials
Smartphone Controlled Robot
Smartphone-Controlled Mobile Robot

In this project, you will learn how mobile robot works and how to make a robot which will be controlled using Smartphone via Bluetooth communication.

evive-brain
Interfacing evive with PictoBlox
This tutorial discusses how to interface evive with PictoBlox, the evive palette, the two modes for writing scripts in PictoBlox, and how to upload a script to evive.
PictoBlox blocks Scratch how to
Getting Started with PictoBlox
PictoBlox is a programming software based on Scratch, where you can make interactive games, animations or program robots and projects with evive, Arduino, etc..
All articles loaded
No more articles to load
Featured Projects
DIY Mini Safe Locker Using Servo
DIY Mini Safe Locker Using Servo

Make your own DIY mini-safe locker using components from the evive Starter Kit and control it using evive’s slide switch!

All articles loaded
No more articles to load

Leave a Reply

Close Menu
×

Cart