์๋ ํ์ธ์. ์๋์ด๋ ธ MQ Series PPM์ผ๋ก ๋ณํํ๊ธฐ ๋ฒ์ธ ํธ์ ๋๋ค.
์ ๋ฒ ๊ธ์ ํ๋ก๋๋ฅผ ๋ณด์๊ณ , ์ค๋์ ํ์ด์ฌ์ผ๋ก PPM์ผ๋ก ๋ณํํ๋๋ก ํ๊ฒ ์ต๋๋ค.
ํ์ด์ฌ์ผ๋ก ๊ตณ์ด ์ฌ์ฉํ ์ด์ ๋ ๊ธํ๊ฒ ์คํํ๋๋ผ, ์ผ์ ๊ฐ์ PPM์ผ๋ก ๋ณํํ์ง ์๊ณ ๊ทธ๋๋ก CSVํ์ผ ํ์์ผ๋ก ๋ฐ์๊ธฐ ๋๋ฌธ์ ํ์ด์ฌ์ผ๋ก ๋ฐ์ดํฐ๋ฅผ ์ ์ฒ๋ฆฌํด์ผ๋ง ํ์ต๋๋ค.
import csv
import numpy as np
import math
import matplotlib.pyplot as plt
"""
PPM
VCC = 3.3V
RL = 10k
VL = VCC*(RL/(RS+RL)
RS = (RL*VCC)/VL-RL
PPM = a * ratio * b
"""
vcc = 3.3
rl = 10
mq3, mq4, mq6, mq7, mq8, mg811 = 7, 8, 9, 10, 11, 12
# Calculate Rs
def rs_cal(vl):
return ((vcc * rl) / vl) - rl
# Calculate Ro
def ro_cal(rs, num, clean_air_ppm):
ro_tmp = 0
for i in range(num):
ro_tmp += rs[i] / clean_air_ppm
return ro_tmp/num
# Calculate ratio
def ratio_cal(rs_, ro_):
return rs_/ro_
# Calculate PPM
def ppm_cal(ratio, a, b):
return a * pow(ratio, b)
# Calculate logscale PPM
def ppm_log_cal(ratio, a, b):
return (math.log10(ratio)-b)/a
def co2_cal(adc_v):
return pow(10, ((adc_v / 8.5) - 0.220) / (0.020 / (2.602 - 3)) + 2.602)
constant = {"mq3": ['Alcohol', "mq3", 0.3934, -1.504],
"mq4": ['CH4', "mq4", 1012.7, -2.786],
"mq6": ['LPG', "mq6", 1009.2, -2.35],
"mq7": ['CO', "mq7", 99.042, -1.518],
"mq8": ['H2', "mq8", 976.97, -0.688]}
file_name_1 = '2020923_105132.csv'
file_name_2 = '2020923_113418.csv'
file_name_3 = '2020923_125810.csv'
header = ['boot_ms[ms]',
'latitude[degE7]', 'longitude[degE7]', 'relative altitude[mm]',
'local position x[m]', 'local position y[m]', 'local position z[m]',
'mq3', 'mq4', 'mq6', 'mq7', 'mq8', 'mq811',
'PM1.0', 'PM2.5', 'PM10.0', 'ozone', 'gamma']
csv_1 = np.loadtxt(file_name_1, delimiter=",")
# file = np.vstack([header, csv_1])
adc_v_list = []
rs_list = []
ratio_list = []
ppm_list = []
tmp = []
for i in range(len(csv_1)):
adc_v_list.append(csv_1[i][mq4])
for i in range(len(csv_1)):
rs_list.append(rs_cal(csv_1[i][mq4]))
ro = ro_cal(rs=rs_list, num=10, clean_air_ppm=4.4)
for i in range(len(csv_1)):
ratio_list.append(ratio_cal(rs_list[i], ro))
for i in range(len(csv_1)):
ppm_list.append(ppm_cal(ratio_list[i], constant['mq4'][2], constant['mq4'][3]))
time = []
for i in range(len(csv_1)):
time.append((csv_1[i][0]-csv_1[0][0])/1000/60)
print("time :", time)
print("adc_v :", adc_v_list)
print("ro :", ro)
print("rs :", rs_list)
print("ratio : ", ratio_list)
print("ppm :", ppm_list)
print("clean air :", 1012.7 * pow(4.4, -2.786))
plt.plot(time, [300 for _ in range(len(csv_1))], color='red')
# plt.plot(time, [10000 for _ in range(len(csv_1))], color='red')
plt.plot(time, ppm_list, color='green')
plt.xlabel('[Minute]')
plt.ylabel('[PPM]')
plt.title("MQ4 - CH4( 300~10000ppm )")
plt.show()
์ ์์ค์ฝ๋ ๊ฐ์ ๊ฒฝ์ฐ๋ ํ๋ก์ ํธ์์ ์ค์ํ๋ค๊ณ ์๊ฐํ ๋ถ๋ถ๋ง ๊ฐ์ ธ์์ต๋๋ค.
์๋๋ PPM์ผ๋ก ๋ณํํ ๋ ํ์ํ ํจ์์ ๋๋ค.
# Calculate Rs
def rs_cal(vl):
return ((vcc * rl) / vl) - rl
# Calculate Ro
def ro_cal(rs, num, clean_air_ppm):
ro_tmp = 0
for i in range(num):
ro_tmp += rs[i] / clean_air_ppm
return ro_tmp/num
# Calculate ratio
def ratio_cal(rs_, ro_):
return rs_/ro_
# Calculate PPM
def ppm_cal(ratio, a, b):
return a * pow(ratio, b)
# Calculate logscale PPM
def ppm_log_cal(ratio, a, b):
return (math.log10(ratio)-b)/a
๊ทธ๋ฆฌ๊ณ ๊ธฐ์ต์ ์๋์ง ์์ง๋ง, CO2 ์ผ์๋ ์ ๊ณต์ ๋ง๊ณ ๋ค๋ฅธ ์์ ์ฌ์ฉํฉ๋๋ค.
# Calculate CO2 PPM
def co2_cal(adc_v):
return pow(10, ((adc_v / 8.5) - 0.220) / (0.020 / (2.602 - 3)) + 2.602)
1ํธ
2ํธ
728x90
๋ฐ์ํ