MQ138 Library

Hi friends,
I have a NODEMCU ESP-12E Wifi module and a MQ138 Formaldehyde gas sensor and I wanted to create an IoT device that measures environment’s formaldehyde level in ppm. Even I know the connection between board and sensor (Vcc  Vin , Gnd  Gnd , A0  AO) but my problem is that I didn’t found any library for MQ138 sensor on the net to add it in Arduino IDE, is it possible to create such a device with these two elements? Or can u offer Any reference for downloading the library? ::slight_smile:

Then it probably doesn't exist.
I just looked at the spec sheet, nicely shows you the connections. With the amount of power it takes, best give it a separate power supply (it needs 5V which the NodeMCU doesn't always have available - that 5V pin is the USB).

You'll have to set it up, then calibrate it for your concentration range and type of gas. It's an analog output so easy enough to get the measurements, after that it's just a matter of math to get to a concentration. It seems to be pretty linear in double log scale.

OK, I vastly overestimated your googling skills. Sorry for that, won't happen again.

"MQ138 Arduino library".

Second hit: arduino-mysensors-contribs/AirQuality-Multiple_Gas_Sensor1_4.ino at master · empierre/arduino-mysensors-contribs · GitHub

Maybe not a library but it's not that hard to turn it into a library if you're so inclined.

Surely i will provide an external 5V power supply (such as a LiPo battery), for now i just don't know how to write the code because the library for MQ138 doesn't exists, for example i want to write a code like this below code that i used in my last project with nodemcu and MQ135 sensor:

#include "MQ135.h"
#include <CayenneMQTTESP8266.h>
#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#define VIRTUAL_PIN 5
#define ANALOGPIN A0

char ssid[] = "Zyxel";
char wifiPassword[] = "far13137474dad";

char username[] = "0628b770-693e-11e7-ac32-c53314110d38";
char password[] = "8bcd57937e106797d740610dc18ee23f54846a8e";
char clientID[] = "7e9ccf60-75f6-11e7-8230-efa4c0c056b2";

MQ135 gasSensor = MQ135(ANALOGPIN);

void setup() {
Serial.begin(115200);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

void loop() {
Cayenne.loop();

float ppm = gasSensor.getPPM();

Serial.println(ppm);
Cayenne.virtualWrite(VIRTUAL_PIN,ppm);
}

CAYENNE_IN_DEFAULT()
{
CAYENNE_LOG("CAYENNE_IN_DEFAULT(%u) - %s, %s", request.channel, getValue.getId(), getValue.asString());

}

wvmarle:
OK, I vastly overestimated your googling skills. Sorry for that, won't happen again.

"MQ138 Arduino library".

Second hit: arduino-mysensors-contribs/AirQuality-Multiple_Gas_Sensor1_4.ino at master · empierre/arduino-mysensors-contribs · GitHub

Maybe not a library but it's not that hard to turn it into a library if you're so inclined.

Thanks my friend, but i saw that earlier on github, just its so messy i just wanted download a library such as MQ138.h or etc. like this: GitHub - GeorgK/MQ135: Arduino library for the MQ135

Hi fardad74,

We're in a similar boat. I'm trying to use an MQ 137 sensor but, just like you, there is no current library for it. I did find some content about how to calculate values for the library sketch like in the MQ 135 and even some content about the temperature and humidity correction factor that you will also need to write into your code for your sensor library. There are youtube videos on how to create a library as well.