Giter Club home page Giter Club logo

arduino-mq131-driver's Introduction

Arduino-MQ131-driver

Arduino library for ozone gas sensor MQ131

This is a comprehensive Arduino library to obtain ozone (O3) concentration in the air with the Winsen MQ131 sensor. The library supports both versions of the sensor (low concentration and high concentration), the calibration, the control of the heater, the environmental adjustments (temperature and humidity) and the output of values in ppm (parts per million), ppb (parts per billion), mg/m3 and µg/m3.

To know before starting...

  • The MQ131 is a semiconductor gas sensor composed by a heater circuit and a sensor circuit.
  • Heater consumes at least 150 mA. So, don't connect it directly on a pin of the Arduino.
  • It is important to respect the pinout of the sensor. If you put Vcc on the sensor and not on the heater, you could damage your sensor irreversibly.
  • Sensor MQ131 requires minimum 48h preheat time before giving consistent results (also called "burn-in" time)
  • There are two different MQ131; a black bakelite sensor for low concentration of ozone and a metal sensor for high concentration of ozone.
  • This driver is made to control the "naked" Winsen MQ131. The driver is able to pilot the low concentration version and the high concentration version.
  • To measure the air quality (e.g. pollution), it's better to use the low concentration MQ131 because the high concentration is not accurate enough for low concentration.

How to install the library?

  1. Click on Clone or download on GitHub
  2. Choose Download ZIP
  3. Open Arduino IDE
  4. In the menu Sketch -> Include Library -> Add .ZIP Library
  5. Select the downloaded file or folder (if automatically uncompress)
  6. Restart Arduino IDE
  7. Enjoy!

Circuit

  • Heater is controlled by NPN transistor via the control pin (on schema pin 2, yellow connector)
  • Result of the sensor is read through analog with RL of 10kΩ (on schema pin A0, green connector)

Breadboard schematics

MQ131 pinout

Schematics

Basic program to use your MQ131

#include "MQ131.h"

void setup() {
  Serial.begin(115200);

  // Init the sensor
  // - Heater control on pin 2
  // - Sensor analog read on pin A0
  // - Model LOW_CONCENTRATION
  // - Load resistance RL of 10KOhms (10000 Ohms)
  MQ131.begin(2,A0, LOW_CONCENTRATION, 10000);  

  Serial.println("Calibration in progress...");
  
  MQ131.calibrate();
  
  Serial.println("Calibration done!");
  Serial.print("R0 = ");
  Serial.print(MQ131.getR0());
  Serial.println(" Ohms");
  Serial.print("Time to heat = ");
  Serial.print(MQ131.getTimeToRead());
  Serial.println(" s");
}

void loop() {
  Serial.println("Sampling...");
  MQ131.sample();
  Serial.print("Concentration O3 : ");
  Serial.print(MQ131.getO3(PPM));
  Serial.println(" ppm");
  Serial.print("Concentration O3 : ");
  Serial.print(MQ131.getO3(PPB));
  Serial.println(" ppb");
  Serial.print("Concentration O3 : ");
  Serial.print(MQ131.getO3(MG_M3));
  Serial.println(" mg/m3");
  Serial.print("Concentration O3 : ");
  Serial.print(MQ131.getO3(UG_M3));
  Serial.println(" ug/m3");

  delay(60000);
}

The result gives us:

Calibration in progress...
Calibration done!
R0 = 110470.60 Ohms
Time to heat = 72 s
Sampling...
Concentration O3 : 0.01 ppm
Concentration O3 : 11.90 ppb
Concentration O3 : 0.03 mg/m3
Concentration O3 : 25.14 ug/m3

Usage

The driver has to be initialized with 4 parameters:

  • Pin to control the heater power (example: 2)
  • Pin to measure the analog output (example: A0)
  • Model of sensor LOW_CONCENTRATION or HIGH_CONCENTRATION (example: LOW_CONCENTRATION)
  • Value of load resistance in Ohms (example: 10000 Ohms)
MQ131.begin(2,A0, LOW_CONCENTRATION, 10000);

Before using the driver, it's better to calibrate it. You can do that through the function calibrate(). The best is to calibrate the sensor at 20°C and 65% of humidity in clean fresh air. The calibration adjusts 2 parameters:

  • The value of the base resistance (R0)
  • The time required to heat the sensor and get consistent readings (Time to read)
MQ131.calibrate();

Those calibration values are used for the usage of the sensor as long as the Arduino is not restarted. Nevertheless, you can get the values for your sensor through the getters:

MQ131.getR0();
MQ131.getTimeToRead();

And set up the values in the initialization of your program through the setters:

MQ131.setR0(value);
MQ131.setTimeToRead(value);

In order to get the values from the sensor, you just start the process with the sample() function. Please notice that the function locks the flow. If you want to do additional processing during the heating/reading process, you should extend the class. The methods are protected and the driver can be extended easily.

MQ131.sample();

The reading of the values is done through the getO3() function. Based on the parameter, you can ask to receive the result in ppm (PPM), ppb (PPB), mg/m3 (MG_M3) or µg/m3 (UG_M3).

MQ131.getO3(PPM);
MQ131.getO3(PPB);
MQ131.getO3(MG_M3);
MQ131.getO3(UG_M3);

The sensor is sensible to environmental variation (temperature and humidity). If you want to have correct values, you should set the temperature and the humidity before the call to getO3() function with the function setEnv(). Temperature are in °C and humidity in %. The values should come from another sensor like the DHT22.

MQ131.setEnv(23, 70);

Links

arduino-mq131-driver's People

Contributors

ostaquet avatar per1234 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.