
MQSensorsLib
This is a unified library to use sensors MQ: 2, 3, 4, 5, 6, 7, 8, 9, 131, 135, 303A and 309A.
Table of Contents
- Getting Started
- Wiring
- User Manual
- Sensor manufacturers
- Contributing
- Authors
Getting Started
//Include the library
#include <MQUnifiedsensor.h>
/************************Hardware Related Macros************************************/
#define Board ("Arduino UNO")
#define Pin (A4) //Analog input 4 of your arduino
/***********************Software Related Macros************************************/
#define Type ("MQ-4") //MQ4
#define Voltage_Resolution (5)
#define ADC_Bit_Resolution (10) // For arduino UNO/MEGA/NANO
#define RatioMQ4CleanAir (4.4) //RS / R0 = 60 ppm
/*****************************Globals***********************************************/
//Declare Sensor
MQUnifiedsensor MQ4(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin, Type);
// Setup
MQ4.setRegressionMethod("Exponential"); //_PPM = a*ratio^b
MQ4.setA(1012.7); MQ4.setB(-2.786); // Configurate the ecuation values to get CH4 concentration
MQ4.setR0(3.86018237); // Value getted on calibration
// Loop
MQ4.init();
MQ4.update();
float ppmCH4 = MQ4.readSensor();
Wiring
Sensor
Important points:
Points you should identify
- VCC -> 5V Power supply (+) wire
- GND -> GND Ground (-) wire
- AO -> Analog Output of the sensor
Data of board that you should have
Graph
RS/R0 value (From datasheet of your sensor)
- RS/R0 (Clean air - English) -> (Aire puro - Spanish)
- Note: RS/R0 is equal to Ratio variable on the program
Arduino

ESP8266

User Manual (v1.0) 12.2019
Manual
User Manual (v2.0) 04.2020
Manual
Serial debug (optional)
If your sensor is an MQ2 (Same for others sensors):
- To enable on setup wrote
- And on Loop Wrote
- Result:

Note:
Yellow -> Calibration status.
Green -> Hardware and software characteristics.
Red -> Headers of the library calculations.
- Only valid for 1 gas sensor readings.
Usage
- Quick troubleshooting, since it shows everything the library does and the results of the calculations in each function.
Prerequisites
You'll need Arduino desktop app 1.8.9 or later.
Sensor manufacturers:
Info of datasheets
Review WPDigitalizer folder website
Installing
Clone this repository into your desktop machine
git clone https://github.com/miguel5612/MQSensorsLib
Running the tests
Use calibration systems if you have several sensors that read the same gas.
Break down into end to end tests
These tests can re-adjust values defined previously and you can contribute to improve conditions or features obtained from particular scenes.
And coding style tests
These tests may generate statistics validation using descriptive tools for quantitative variables.
Built With
- Data sheets - Curves and behavior for each sensor, using logarithmic graphs.
- Main purpose - Every sensor has high sensibility for a specific gas or material.
Contributing
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
Authors
Collaborators
See also the list of contributors who participated in this project.
License
This project is licensed under the MIT License - see the LICENSE.md file for details
Cite as
- Plain text: Califa Urquiza, Miguel Angel, Contreras Contreras, Ghiordy, & Carrillo Amado, Yerson Ramiro. (2019, September 3). miguel5612/MQSensorsLib: Arduino Preview V1.03 (Version 1.0.3). Zenodo. http://doi.org/10.5281/zenodo.3384301
- CSL: { "publisher": "Zenodo", "DOI": "10.5281/zenodo.3384301", "title": "miguel5612/MQSensorsLib: Arduino Preview V1.03", "issued": { "date-parts": [ [ 2019, 9, 3 ] ] }, "abstract": "<p>Publishing on Zenodo platform as software in order to extend its applications for other works allowing to recognize MQSensorLib's Authors this work into scientific community using Digital Object Identifier System (DOI).</p>", "author": [ { "family": "Califa Urquiza, Miguel Angel" }, { "family": "Contreras Contreras, Ghiordy" }, { "family": "Carrillo Amado, Yerson Ramiro" } ], "version": "1.0.3", "type": "article", "id": "3384301" }
- BibTeX: @misc{califa_urquiza_miguel_angel_2019_3384301, author = {Califa Urquiza, Miguel Angel and Contreras Contreras, Ghiordy and Carrillo Amado, Yerson Ramiro}, title = {miguel5612/MQSensorsLib: Arduino Preview V1.03}, month = sep, year = 2019, doi = {10.5281/zenodo.3384301}, url = {https://doi.org/10.5281/zenodo.3384301} }