Skip to content

This library calculates the slopes of a wide variety of gas sensors, popular models such as [MQ-2, MQ-3, MQ-4, MQ-5, MQ-6, MQ-7, MQ-8, MQ-9, MQ131, MQ-135, MQ-136, MQ-137, MQ303A, MQ307A, MQ309A]. It also supports Geiger Counters for Radioactive analysis It integrates with Matplotlib for data visualization, facilitates Data Science apply.

License

Notifications You must be signed in to change notification settings

abcdaaaaaaaaa/MQSpaceData.h

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MQSpaceData

What awaits v4.0.0?

newplotMQ-135curves newplotMQ-135TH newplotMQ-135TH4)

Sample Projects

Place Category Project Name
[1] Getting Started Adjustable Air Quality Monitoring & Analysis Platform

Formulla

  1. ppm = a*ratio^b (a: valuea b: valueb)
  2. ppm = 10^[(log10(ratio)-b)/m] (m: logm b: logb)

If R^2 equals 1 :

a*ratio^b = 10^[(log10(ratio)-b)/m]
logm = valueb, logb = log10(valuea)

1]

loghello

[(1,10), (2,4), (3,3)]

loge(b) = ln(b)

(ln(1),ln(10)) for ≈ (0,2.3026)

(ln(2),ln(4)) ≈ (0.6931,1.3863) and

(ln(3),ln(3)) ≈ (1.0986,1.0986)

b = ∑ i=1 n (x i − x ˉ ) 2 ∑ i=1 n (xi − xˉ)(yi−yˉ)

ln(x):(0,0.6931,1.0986)ln(y):(2.3026,1.3863,1.0986)ln(y)ˉ=(2.3026+1.3863+1.0986)/3≈1.5958

ln(x)ˉ=(0+0.6931+1.0986)/3≈0.5972

b = (0−0.5972)(2.3026−1.5958)+(0.6931−0.5972)(1.3863−1.5958)+(1.0986−0.5972)(1.0986−1.5958)/(0−0.5972)^2+(0.6931−0.5972)^2+(1.0986−0.5972)^2 ≈ -1.2

ln(a) = − ln ˉ (y) - b ln ˉ (x) ≈ 1.5958−(−1.2)⋅0.5972≈2.31244

a=e^2.31244 ≈ 9.947

b ≈ -1.2

a ≈ 9.947

2]

y = mx+ n
n = b
log10(y) = m*log10(x) + b

-b = m*log10(x) - log10(y)

last b = log10(y) - m*log10(x)

m = (y - y0) / (x - x0)

m = (log10(y) - log10(y0)) / (log10(x) - log10(x0))

if y= a*x^b:

last m = log10(y/y0) / log10(x/x0)

m = slope of the line

b = intersection point

m = log10(y/y0) / log10(x/x0)

b = log10(y) - m*log10(x)

    if r_squared >= 0.9995:
        print("R-squared value for {gas name} is above 0.9995, plotting against first and last values.")
        
        x0, y0 = x[0], y[0]
        xn, yn = x[-1], y[-1]
        b = np.log10(yn/y0) / np.log10(xn/x0)
        a = 10**(np.log10(yn) - b * np.log10(xn))
        b2 = np.log10(yn) - b * np.log10(xn)
        b2_rounded = round(b2, 4)
        a_rounded = round(a, 4)
        b_rounded = round(b, 4)

The first formula is determined according to all points (OldCurve.py, OldCurve), while the second formula is determined according to the first and last point. Therefore, in order to collect them all in the same formula and to increase the accuracy rate, we used the method in the second formula and took the logarithm (if R^2 = 1 (%100) always: logm = valueb, logb = log10(valuea)) for slopes greater than 99.95% and collected them all in the first formula, thus we increased the accuracy rate without having to use 2 different formulas (Regression.py, NewCurve).

V = I x R

V = I x R -> VRL = [VC / (RS + RL)] x RL -> VRL = (VC x RL) / (RS + RL)

RS: -> VRL x (RS + RL) = VC x RL -> (VRL x RS) + (VRL x RL) = VC x RL -> (VRL x RS) = (VC x RL) - (VRL x RL)

RS = [(VC x RL) - (VRL x RL)] / VRL -> RS = [(VC x RL) / VRL] – RL

Rs = (voltage * Rload) / (voltage/2^n-1)) - (Rload)

analogRead(pin) / bitadc -> calibrationPercentile / 100

Rs = bitadc * Rload / analogRead(pin) - Rload -> calibrationRs = 100 * Rload / calibrationPercentile – Rload

Ro = calibrationRs / Air ||| ratio = Rs / Ro -> ratio = Rs / (calibrationRs / Air) -> ratio = Rs x Air / calibrationRs

Ratio = (bitadc * Rload / analogRead(pin) – Rload) * RsRoMQAir / (100 * Rload / calibrationPercentile – Rload) [Rs / Ro]

Calculate Ratio

(1) if ratio = Rs / Ro:

ratio = (bitadc * Rload / analogRead(pin) – Rload) * RsRoMQAir / (100 * Rload / calibrationPercentile – Rload)

(2) if ratio = Rs / Rs:

ratio = (bitadc * Rload / analogRead(pin) – Rload) / (100 * Rload / calibrationPercentile – Rload) [No RsRoMQAir]

(3) if ratio = Ro / Rs:

ratio = (bitadc * Rload / analogRead(pin) – Rload) * RsRoMQAir / (100 * Rload / calibrationPercentile – Rload)

But: slpoe = slope x -1

valueb() = valueb() * -1

logm() = logm() * -1

    float MQSpaceData::readValue()
    {
     if (_ratioMode == "Ro/Rs") _vb = _vb * -1;
     return pow(ratio(),_vb)*_va;
    }
    
    float MQSpaceData::logValue()
    {
     if (_ratioMode == "Ro/Rs") _mlog = _mlog * -1;
     return pow(10,((log10(ratio())-_blog)/_mlog));
    }

Ratio for Sensors

STATUS 1: MQ-2, MQ-3, MQ-4, MQ-5, MQ-6, MQ-7, MQ-8, MQ-9, MQ-135, MQ-136, MQ-137 [Almost All & Standart]

STATUS 2: MQ303A, MQ307A, MQ309A [A models]

STATUS 3: MQ131 [MQ131 only]

MQDataScience

"The first and only Arduino library where Geiger Counter and MQ Sensors combine with Data Science" MQ2datascience MQ3datascience MQ4datascience MQ5datascience MQ6datascience MQ7datascience MQ8datascience MQ9datascience MQ131datascience MQ135datascience MQ136datascience MQ137datascience MQ303Adatascience MQ307Adatascience MQ309Adatascience

RadioactivityDataScience

"The first and only Arduino library where Geiger Counter and MQ Sensors combine with Data Science" LowGeigerCounterScience MediumGeigerCounterScience HighGeigerCounterScience SpecialGeigerCounterScience

SpaceDataScience

"The first and only Arduino library where Geiger Counter and MQ Sensors combine with Data Science" SpaceDataScience

MQ-135

newplotMQ-135curves newplotMQ-135TH newplotMQ-135TH4)

MQ-2

NewCurve:

MQ2curve

OldCurve:

MQ2curve

MQ-3

NewCurve:

MQ3curve

OldCurve:

MQ3curve

MQ-4

NewCurve:

MQ4curve

OldCurve:

MQ4curve

MQ-5

NewCurve:

MQ5curve

OldCurve:

MQ5curve

MQ-6

NewCurve:

MQ6curve

OldCurve:

MQ6curve

MQ-7

NewCurve:

MQ7curve

OldCurve:

MQ7curve

MQ-8

NewCurve:

MQ8curve

OldCurve:

MQ8curve

MQ-9

NewCurve:

MQ9curve

OldCurve:

MQ9curve

MQ131

NewCurve:

MQ131curve

OldCurve:

MQ131curve

MQ-136

NewCurve:

MQ136curve

OldCurve:

MQ136curve

MQ-137

NewCurve:

MQ137curve

OldCurve:

MQ137curve

MQ303A

NewCurve:

MQ303Acurve

OldCurve:

MQ303Acurve

MQ307A

NewCurve:

MQ307AScience

OldCurve:

MQ307AScience

MQ309A

NewCurve:

MQ309Acurve

OldCurve:

MQ309Acurve

NOTE: [For detailed explanation, You can also check out the github wiki page] https://github.com/abcdaaaaaaaaa/MQSpaceData.h/wiki

MQSpaceData Contents

MQSpaceData MQ Sensor List

MQ Sensor List: [MQ-2, MQ-3, MQ-4, MQ-5, MQ-6, MQ-7, MQ-8, MQ-9, MQ131, MQ-135, MQ-136, MQ-137, MQ303A, MQ307A, MQ309A] MQSensorList

MQSpaceData Geiger Counter

GeigerCounter

You can access the library's article here

About

This library calculates the slopes of a wide variety of gas sensors, popular models such as [MQ-2, MQ-3, MQ-4, MQ-5, MQ-6, MQ-7, MQ-8, MQ-9, MQ131, MQ-135, MQ-136, MQ-137, MQ303A, MQ307A, MQ309A]. It also supports Geiger Counters for Radioactive analysis It integrates with Matplotlib for data visualization, facilitates Data Science apply.

Topics

Resources

License

Stars

Watchers

Forks