miguel5612 / MQSensorsLib

We present a unified library for MQ sensors, this library allows to read MQ signals easily from Arduino, Genuino, ESP8266, ESP-32 boards whose references are MQ2, MQ3, MQ4, MQ5, MQ6, MQ7, MQ8, MQ9, MQ131, MQ135, MQ136, MQ303A, MQ309A.
MIT License
173 stars 64 forks source link
arduino esp-8266 mq mq-3 mq-4 mq-5 mq-6 mq131 mq135 mq3 mq303a mq309a mq4 mq5 mq6 mq7 mq8 mq9 wemos wemos-d1

DOI Build Status Contributors Forks Stargazers Issues MIT License LinkedIn

MQSensorsLib

We present a unified library for MQ sensors, this library allows to read MQ signals easily from Arduino, Genuino, ESP8266, ESP-32 boards whose references are MQ2, MQ3, MQ4, MQ5, MQ6, MQ7, MQ8, MQ9, MQ131, MQ135, MQ303A, MQ309A.

Table of Contents

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); // Configure the equation to to calculate 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

ESP32 WROOM 32D

The ESP32 WROOM 32D does not need an external power supply. A0 goes to PIN36, Vcc to 3v3 and GND to any GND port on the board. Check the ESP2/ESP32_WROOM_32 folder to fixing the measuring issue when connecting to wifi.

Manuals

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):

Serial debug output

Note:

Usage

Prerequisites

You'll need Arduino desktop app 1.8.9 or later.

Sensor manufacturers:

Sensor Manufacture URL Datasheet
MQ-2 HANWEI Electronics datasheet
MQ-3 HANWEI Electronics datasheet
MQ-4 HANWEI Electronics datasheet
MQ-5 HANWEI Electronics datasheet
MQ-6 HANWEI Electronics datasheet
MQ-7 HANWEI Electronics datasheet
MQ-8 HANWEI Electronics datasheet
MQ-9 HANWEI Electronics datasheet
MQ-131 HANWEI Electronics datasheet
MQ-135 HANWEI Electronics datasheet
MQ-136 HANWEI Electronics datasheet
MQ-303A HANWEI Electronics datasheet
MQ-309A HANWEI Electronics datasheet

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.

Examples/MQ-3

And coding style tests

These tests may generate statistics validation using descriptive tools for quantitative variables.

Examples/MQ-board.ino

Built With

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Reviewers

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

Sponsor