MQ-7 Gas Sensor demo

Dependencies:   mbed

Dependents:   GloboMet

Committer:
bryanbates
Date:
Mon Oct 31 21:59:53 2016 +0000
Revision:
0:ff650029fdf8
Carbon monoxide sensor "Hello World"

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bryanbates 0:ff650029fdf8 1 #include "mbed.h"
bryanbates 0:ff650029fdf8 2 #include "MQ7.h"
bryanbates 0:ff650029fdf8 3
bryanbates 0:ff650029fdf8 4 DigitalOut led1(LED1);
bryanbates 0:ff650029fdf8 5 DigitalOut led2(LED2);
bryanbates 0:ff650029fdf8 6 DigitalOut led3(LED3);
bryanbates 0:ff650029fdf8 7 MQ7 sensor(p21, p22); // ALR, HSW
bryanbates 0:ff650029fdf8 8
bryanbates 0:ff650029fdf8 9 int main() {
bryanbates 0:ff650029fdf8 10
bryanbates 0:ff650029fdf8 11 while(1) {
bryanbates 0:ff650029fdf8 12 led1 = 0;
bryanbates 0:ff650029fdf8 13 led2 = 0;
bryanbates 0:ff650029fdf8 14 led3 = 0;
bryanbates 0:ff650029fdf8 15
bryanbates 0:ff650029fdf8 16 // Purge the device for 60 sec
bryanbates 0:ff650029fdf8 17 sensor.setHeat(1.0f); // supply full 5V to module
bryanbates 0:ff650029fdf8 18 led1 = 1; // Turn on only LED1 during Purge phase
bryanbates 0:ff650029fdf8 19 for (int i = 0; i < 60; i++){
bryanbates 0:ff650029fdf8 20 wait(1); // wait 60 seconds
bryanbates 0:ff650029fdf8 21 }
bryanbates 0:ff650029fdf8 22
bryanbates 0:ff650029fdf8 23 // Purge complete
bryanbates 0:ff650029fdf8 24 // Sense the device for 90 sec
bryanbates 0:ff650029fdf8 25 sensor.setHeat(0.28f); // supply 1.4V to module
bryanbates 0:ff650029fdf8 26 led1 = 0;
bryanbates 0:ff650029fdf8 27 led2 = 1; // Turn on only LED2 during Sense phase
bryanbates 0:ff650029fdf8 28 for (int i = 0; i < 90; i++){
bryanbates 0:ff650029fdf8 29 if (sensor.getAlarm() == 1)
bryanbates 0:ff650029fdf8 30 led3 = 1; // Turn on LED3 if CO gas levels reached
bryanbates 0:ff650029fdf8 31 wait(1);
bryanbates 0:ff650029fdf8 32 }
bryanbates 0:ff650029fdf8 33 // Sense complete, start over
bryanbates 0:ff650029fdf8 34 wait(0.5);
bryanbates 0:ff650029fdf8 35 }
bryanbates 0:ff650029fdf8 36 }