Read ad values from sensor, and calculate the respective ppm value of respective gas .

Dependencies:   MQ4 mbed

Files at this revision

API Documentation at this revision

Comitter:
renanbmx123
Date:
Tue Jul 17 04:40:44 2018 +0000
Commit message:
MQ4 gas sensor example for reading 3 different types of gas.

Changed in this revision

MQ4.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MQ4.lib	Tue Jul 17 04:40:44 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/renanbmx123/code/MQ4/#401959f72658
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Jul 17 04:40:44 2018 +0000
@@ -0,0 +1,26 @@
+#include "mbed.h"
+#include "MQ4.h"
+
+Serial pc(USBTX, USBRX); // tx, rx
+MQ4 mq4(p18);                                                                    // Analog Port to read from
+
+int main() {
+    pc.baud(9600);
+    mq4.begin();                                                                // 'Calibrate' sensor
+    MQ4_data_t MQ4_data;                                                        // Structure to hold data.
+    pc.printf("Ro calculated: %f\r\n",mq4.get_Ro()); 
+    while (true) {
+        pc.printf("H2 PPM: %.0f\r\n",mq4.readH2());                             // Performs a one shot read of CO
+        pc.printf("CH4 PPM: %.0f\r\n",mq4.readCH4());                       // Performs a one shot read of Smoke
+        pc.printf("LPG PPM: %.0f\r\n",mq4.readLPG());                           // Performs a one shot read of LPG
+        wait(1);
+        pc.printf("................................\r\n");                      
+        mq4.read(&MQ4_data);                                                    // Alt reading method, reading to struct
+        pc.printf("CO PPM: %.0f\r\n",MQ4_data.h2);                              // Return data from strut
+        pc.printf("Smoke PPM: %.0f\r\n",MQ4_data.ch4);                        // Return data from strut
+        pc.printf("LPG PPM: %.0f\r\n",MQ4_data.lpg);                            // Return data from strut
+        pc.printf("................................\r\n");                      
+        wait(1);
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Jul 17 04:40:44 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/a7c7b631e539
\ No newline at end of file