7 years, 7 months ago.

how to give digital output using mq7 sensor

i'm currently working on mq7 sensor (carbon monoxide sensor). i'd try the coding as shown below. the coding successfully detect the carbon monoxide gas by turning the led ON. however, i want to read the value of carbon monoxide that have been detected. can i know which part of coding i should change?

/media/uploads/liyanaKafli/capture2.jpg

EDITING TIP: You can copy and paste your code here as text and enclose it within <<code>> and <</code>> markers as below (each marker on its own separate line). Then it's going to be shown as code in a frame.

<<code>>
#include "mbed.h"

DigitalOut led1(LED1);

int main()
{
    while (1) {
        led1 = !led1;
        wait(0.5);
    }
}
<</code>>
posted by Zoltan Hudak 10 Apr 2017

#include "mbed.h"
#include "MQ7.h"

DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
MQ7 sensor(p21, p22); // ALR, HSW

int main() {
    
    while(1) {
        led1 = 0;
        led2 = 0;
        led3 = 0;
        
        // Purge the device for 60 sec
        sensor.setHeat(1.0f); // supply full 5V to module
        led1 = 1; // Turn on only LED1 during Purge phase
        for (int i = 0; i < 60; i++){
            wait(1); // wait 60 seconds
        }
        
        // Purge complete
        // Sense the device for 90 sec 
        sensor.setHeat(0.28f); // supply 1.4V to module
        led1 = 0; 
        led2 = 1; // Turn on only LED2 during Sense phase
        for (int i = 0; i < 90; i++){
            if (sensor.getAlarm() == 1)
                led3 = 1; // Turn on LED3 if CO gas levels reached
            wait(1); 
        }
        // Sense complete, start over
        wait(0.5);
    }
}

thank you Zoltan Hudak

posted by Khalid Isa 11 Apr 2017

1 Answer

7 years, 7 months ago.

Hello Nur,
If you have similar MQ-7 gas sensor module as described here then, considering the available outputs, it's impossible to read the level of carbon monoxide concentration by modifying only the software. Most likely there is an analog comparator IC (for instance LM393) installed on the board producing only a binary ALR (Alarm) signal at the output.

Accepted Answer

does that mean i cannot only modifying the software part to give a digital output to this sensor? as i know, in order to monitor the value of CO, there is a calculation that needed to be considered. how can i calculate the value to measure the CO if there is no output which is the value because the current output is only the led will turn on if CO existed.

posted by Khalid Isa 11 Apr 2017

Unfotunately without modifying the HW it's impossible to read the level of CO. There are no calculations performed by the MQ-7 module. Sensor's output voltage is compared with the trip-level voltage (adjustable with potentiometer R4) by an analog comparator (like LM393). At the comparator's output (ALR) is then either 0V or 5V.

posted by Zoltan Hudak 11 Apr 2017