Skip to content

Commit 3092f14

Browse files
author
Main Push Robot
committed
Committing dev changes
1 parent 189030c commit 3092f14

35 files changed

+2833
-97
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
# NAZIV PROIZVODA Arduino library
1+
# MQ-X Arduino library
22

33
[![Compile Sketches](http://github-actions.40ants.com/e-radionicacom/Soldered-Generic-Arduino-Library/matrix.svg?branch=dev&only=Compile%20Sketches)](https://github.com/e-radionicacom/Soldered-Generic-Arduino-Library/actions/workflows/compile_test.yml)
44
[![Make docs and publish to GitHub Pages](https://github.com/e-radionicacom/Soldered-Generic-Arduino-Library/actions/workflows/make_docs.yml/badge.svg?branch=dev)](https://github.com/e-radionicacom/Soldered-Generic-Arduino-Library/actions/workflows/make_docs.yml)
55

6-
| ![Product name](https://upload.wikimedia.org/wikipedia/commons/8/8f/Example_image.svg) |
6+
| ![MQ-X](https://upload.wikimedia.org/wikipedia/commons/8/8f/Example_image.svg) |
77
| :---------------------------------------------------------------------------------------------: |
8-
| [NAZIV PROIZVODA](https://www.solde.red/SKU) |
8+
| [MQ-X](https://www.solde.red/333041) |
99

10-
OPIS PROIZVODA + LINK NA [easyC ecosystem](https://www.soldered.com/easyC).
10+
MQ-X Gas Sensors Arduino Library soon to be compliant to [easyC ecosystem](https://www.soldered.com/easyC).
1111

1212
### Repository Contents
1313
- **/src** - source files for the library (.h & .cpp)
1414
- **/examples** - examples for using the library
1515
- ***other*** - *keywords* file highlights function words in your IDE, *library.properties* enables implementation with Arduino Library Manager.
1616

1717
### Hardware design
18-
You can find hardware design for this board in NAZIV PROIZVODA hardware repository
18+
You can find hardware design for this board in MQ-X Soldered Library hardware repository
1919

2020
### Documentation
2121

2222
Access Arduino library documentation [here](https://e-radionicacom.github.io/Soldered-Generic-Arduino-Library/).
2323

24-
- Tutorial for using the NAZIV PROIZVODA board
24+
- Tutorial for using the MQ-X Sensor Soldered board
2525
- Installing an Arduino library
2626

2727
### About Soldered
@@ -37,7 +37,7 @@ At Soldered, we design and manufacture a wide selection of electronic products t
3737

3838
### Original source
3939
40-
This library is possible thanks to original [arduino-mcp23017](https://github.com/blemasle/arduino-mcp23017) library. Thank you, blemasle.
40+
This library is possible thanks to original [MQSensorsLib](https://github.com/miguel5612/MQSensorsLib) library. Thank you, miguel5612.
4141

4242

4343
### Open-source license
Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
// Include the library
2+
#include "MQ-Sensor-SOLDERED.h"
3+
4+
// Wiring NOT required, only an arduino or esp8266 board
5+
6+
/*
7+
This program was made to test the algorithm that from the ratio obtains
8+
the PPM (The core of this library), regardless of the plate in which the
9+
result is executed should give a small error (ideally less than 5%), is
10+
our way of self-evaluation, we tell the library what is the value of the
11+
ratio and ask him to calculate the PPM and compare it against the value
12+
that should really give, these values were taken from the same datasheet
13+
with which the library was made.
14+
*/
15+
16+
// Include the library
17+
#include "MQ-Sensor-SOLDERED.h"
18+
19+
// Declare Sensor, any MQ will work
20+
MQ2 sensor(A1);
21+
22+
/*****************************Globals***********************************************/
23+
double ratio[4] = {};
24+
double expectedValue[4] = {};
25+
double calculatedValues[4] = {};
26+
double error[4] = {};
27+
/**************************Object_Sensor********************************************/
28+
29+
void setup()
30+
{
31+
// Init serial port
32+
Serial.begin(115200);
33+
// init the sensor
34+
sensor.begin();
35+
36+
// Print in serial monitor
37+
Serial.println("MQ2 to MQ9 - test program");
38+
}
39+
40+
void loop()
41+
{
42+
// Testing MQ2 LPG
43+
ratio[0] = 1.8;
44+
ratio[1] = 1.05;
45+
ratio[2] = 0.8;
46+
ratio[3] = 0.5;
47+
expectedValue[0] = 200;
48+
expectedValue[1] = 500;
49+
expectedValue[2] = 1000;
50+
expectedValue[3] = 3000;
51+
testSensor("MQ-2", 574.25, -2.222);
52+
53+
// Testing MQ3 Benzene
54+
ratio[0] = 4;
55+
ratio[1] = 3;
56+
ratio[2] = 1;
57+
ratio[3] = 0.8;
58+
expectedValue[0] = 0.1;
59+
expectedValue[1] = 0.21;
60+
expectedValue[2] = 4;
61+
expectedValue[3] = 10;
62+
testSensor("MQ-3", 4.8387, -2.68);
63+
64+
// Testing MQ4 CH4
65+
ratio[0] = 1.9;
66+
ratio[1] = 1;
67+
ratio[2] = 0.6;
68+
ratio[3] = 0.42;
69+
expectedValue[0] = 200;
70+
expectedValue[1] = 1000;
71+
expectedValue[2] = 5000;
72+
expectedValue[3] = 10000;
73+
testSensor("MQ-4", 1012.7, -2.786);
74+
75+
// Testing MQ5 H2
76+
ratio[0] = 1.8;
77+
ratio[1] = 1.3;
78+
ratio[2] = 0.8;
79+
ratio[3] = 0.68;
80+
expectedValue[0] = 200;
81+
expectedValue[1] = 500;
82+
expectedValue[2] = 3000;
83+
expectedValue[3] = 10000;
84+
testSensor("MQ-5", 1163.8, -3.874);
85+
86+
// Testing MQ6 CH4
87+
ratio[0] = 2.6;
88+
ratio[1] = 1.9;
89+
ratio[2] = 1;
90+
ratio[3] = 0.8;
91+
expectedValue[0] = 200;
92+
expectedValue[1] = 500;
93+
expectedValue[2] = 2000;
94+
expectedValue[3] = 5000;
95+
testSensor("MQ-6", 2127.2, -2.526);
96+
97+
// Testing MQ7 CO
98+
ratio[0] = 1.8;
99+
ratio[1] = 1;
100+
ratio[2] = 0.4;
101+
ratio[3] = 0.25;
102+
expectedValue[0] = 50;
103+
expectedValue[1] = 100;
104+
expectedValue[2] = 400;
105+
expectedValue[3] = 1000;
106+
testSensor("MQ-7", 99.042, -1.518);
107+
108+
// Testing MQ8 H2
109+
ratio[0] = 2.6;
110+
ratio[1] = 1;
111+
ratio[2] = 0.21;
112+
ratio[3] = 0.03;
113+
expectedValue[0] = 500;
114+
expectedValue[1] = 1000;
115+
expectedValue[2] = 3000;
116+
expectedValue[3] = 10000;
117+
testSensor("MQ-8", 976.97, -0.688);
118+
119+
// Testing MQ9 LPG
120+
ratio[0] = 2;
121+
ratio[1] = 1.4;
122+
ratio[2] = 0.7;
123+
ratio[3] = 0.23;
124+
expectedValue[0] = 200;
125+
expectedValue[1] = 500;
126+
expectedValue[2] = 2000;
127+
expectedValue[3] = 10000;
128+
testSensor("MQ-9", 1000.5, -2.186);
129+
130+
// Testing MQ131 O3
131+
ratio[0] = 5;
132+
ratio[1] = 2;
133+
ratio[2] = 0.7;
134+
ratio[3] = 0.5;
135+
expectedValue[0] = 5;
136+
expectedValue[1] = 20;
137+
expectedValue[2] = 70;
138+
expectedValue[3] = 100;
139+
testSensor("MQ-131", 23.943, -1.11);
140+
141+
// Testing MQ135 NH4
142+
ratio[0] = 2.6;
143+
ratio[1] = 1.9;
144+
ratio[2] = 1.1;
145+
ratio[3] = 0.75;
146+
expectedValue[0] = 10;
147+
expectedValue[1] = 20;
148+
expectedValue[2] = 100;
149+
expectedValue[3] = 200;
150+
testSensor("MQ-135", 102.2, -2.473);
151+
152+
// Testing MQ303 Isobutano
153+
ratio[0] = 0.4;
154+
ratio[1] = 0.3;
155+
ratio[2] = 0.19;
156+
ratio[3] = 0.08;
157+
expectedValue[0] = 100;
158+
expectedValue[1] = 300;
159+
expectedValue[2] = 1000;
160+
expectedValue[3] = 10000;
161+
testSensor("MQ-303", 6.2144, -2.894);
162+
163+
// Testing MQ309 CO
164+
ratio[0] = 6;
165+
ratio[1] = 5;
166+
ratio[2] = 4.3;
167+
ratio[3] = 4;
168+
expectedValue[0] = 1000;
169+
expectedValue[1] = 3000;
170+
expectedValue[2] = 5000;
171+
expectedValue[3] = 7000;
172+
testSensor("MQ-309", 1000000, -4.01);
173+
174+
// Testing linear equation for MQ-4
175+
sensor.setRegressionMethod(0); //_PPM = pow(10, (log10(ratio)-b)/a)
176+
ratio[0] = 2.5;
177+
ratio[1] = 1.5;
178+
ratio[2] = 0.9;
179+
ratio[3] = 0.65;
180+
expectedValue[0] = 200;
181+
expectedValue[1] = 1000;
182+
expectedValue[2] = 5000;
183+
expectedValue[3] = 10000;
184+
testSensor("MQ-4", -0.318, 1.133);
185+
186+
while (1)
187+
;
188+
}
189+
190+
191+
void testSensor(String SensorName, float A, float B)
192+
{
193+
sensor.setA(A);
194+
sensor.setB(B);
195+
calculatedValues[0] = sensor.validateEcuation(ratio[0]);
196+
calculatedValues[1] = sensor.validateEcuation(ratio[1]);
197+
calculatedValues[2] = sensor.validateEcuation(ratio[2]);
198+
calculatedValues[3] = sensor.validateEcuation(ratio[3]);
199+
error[0] = calculatePercentualError(expectedValue[0], calculatedValues[0]);
200+
error[1] = calculatePercentualError(expectedValue[1], calculatedValues[1]);
201+
error[2] = calculatePercentualError(expectedValue[2], calculatedValues[2]);
202+
error[3] = calculatePercentualError(expectedValue[3], calculatedValues[3]);
203+
204+
Serial.print("Error(%) ");
205+
Serial.print(SensorName);
206+
Serial.print(": ");
207+
Serial.print(error[0]);
208+
Serial.print(" ");
209+
Serial.print(error[1]);
210+
Serial.print(" ");
211+
Serial.print(error[2]);
212+
Serial.print(" ");
213+
Serial.print(error[3]);
214+
Serial.print(" | Calculated(PPM): ");
215+
Serial.print(calculatedValues[0]);
216+
Serial.print(" ");
217+
Serial.print(calculatedValues[1]);
218+
Serial.print(" ");
219+
Serial.print(calculatedValues[2]);
220+
Serial.print(" ");
221+
Serial.print(calculatedValues[3]);
222+
Serial.print(" | Expected(PPM): ");
223+
Serial.print(expectedValue[0]);
224+
Serial.print(" ");
225+
Serial.print(expectedValue[1]);
226+
Serial.print(" ");
227+
Serial.print(expectedValue[2]);
228+
Serial.print(" ");
229+
Serial.print(expectedValue[3]);
230+
Serial.println(" | ");
231+
}
232+
233+
double calculatePercentualError(double expectedValue, double calculatedValue)
234+
{
235+
// Return the diference between two measures
236+
return abs(calculatedValue - expectedValue) / expectedValue;
237+
}

examples/Calibration/Calibration.ino

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
MQUnifiedsensor Library - calibrating an mq2
3+
4+
Demonstrates the use a mq2 sensor.
5+
Library originally added 01 may 2019
6+
by Miguel A Califa, Yersson Carrillo, Ghiordy Contreras, Mario Rodriguez
7+
8+
Added example
9+
modified 27 May 2019
10+
by Miguel Califa
11+
12+
This example code is in the public domain.
13+
14+
*/
15+
16+
// Include the library
17+
#include "MQ-Sensor-SOLDERED.h"
18+
19+
double alcoholPPM = (0);
20+
// Defaults, uncomment if you need
21+
#define RatioMQ2CleanAir 9.83 // RS / R0 = 9.83 ppm
22+
//#define RatioMQ3CleanAir 60 //RS / R0 = 60 ppm
23+
//#define RatioMQ4CleanAir 4.4 //RS / R0 = 4.4 ppm
24+
//#define RatioMQ5CleanAir 6.5 //RS / R0 = 6.5 ppm
25+
//#define RatioMQ6CleanAir 10 //RS / R0 = 10 ppm
26+
//#define RatioMQ7CleanAir 27.5 //RS / R0 = 27.5 ppm
27+
//#define RatioMQ8CleanAir 70 //RS / R0 = 70 ppm
28+
//#define RatioMQ9CleanAir 9.6 //RS / R0 = 9.6 ppm
29+
//#define RatioMQ131CleanAir 15 //RS / R0 = 15 ppm
30+
//#define RatioMQ135CleanAir 3.6//RS / R0 = 3.6 ppm
31+
//#define RatioMQ303CleanAir 1 //RS / R0 = 1 ppm
32+
//#define RatioMQ309CleanAir 11 //RS / R0 = 11 ppm
33+
34+
unsigned long counter = 0;
35+
36+
37+
MQ2 mq2(A1);
38+
39+
void setup()
40+
{
41+
// Init serial port
42+
Serial.begin(115200);
43+
mq2.setRegressionMethod(1); //_PPM = a*ratio^b
44+
mq2.setA(574.25);
45+
mq2.setB(-2.222); // Configurate the ecuation values to get LPG concentration
46+
/*
47+
//If the RL value is different from 10K please assign your RL value with the following method:
48+
MQ3.setRL(10);
49+
*/
50+
// init the sensor
51+
mq2.begin();
52+
// Print in serial monitor
53+
Serial.println("mq2 - Calibracion");
54+
Serial.println("Note - Make sure you are in a clean room and the sensor has pre-heated almost 4 hours");
55+
Serial.println("Autonumeric | lecture (R0)");
56+
}
57+
58+
void loop()
59+
{
60+
mq2.update();
61+
// Read the sensor and print in serial port
62+
float lecture = mq2.calibrate(RatioMQ2CleanAir);
63+
// Print in serial monitor
64+
Serial.print(counter);
65+
Serial.print(" | ");
66+
Serial.println(lecture);
67+
// Increment counter
68+
counter++;
69+
// Wait to measure next sample
70+
delay(400);
71+
}

0 commit comments

Comments
 (0)