![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Read ad values from sensor, and calculate the respective ppm value of respective gas .
Revision 0:9f3c885e7d4e, committed 2018-07-17
- 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
diff -r 000000000000 -r 9f3c885e7d4e MQ4.lib --- /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
diff -r 000000000000 -r 9f3c885e7d4e main.cpp --- /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); + } +} +
diff -r 000000000000 -r 9f3c885e7d4e mbed.bld --- /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