You are on page 1of 3

1 #!

/usr/bin/env python
2 from __future__ import print_function
3
4 """Masurare concentratie gaze cu senzori analogici
5
6
7 ------------------------------------------------------------------------
8 In acest exemplu, semnalul analogic transmis de senzori
9 este convertit in semnal digital cu ajutorul
10 Convertorului analog digital ADS1115 (16 biti)
11
12 Din datele producatorului
13 Zhengzhou Winsen Electronics Technology Co., Ltd
14
15 ConcGAZ[ppm] = a*exp(b*Tensiune[V]) + c*exp(d*Tensiune[V])
16
17 Senzor MQ4 - Gaz metan NH4
18
19 f(x) = a*exp(b*x) + c*exp(d*x)
20 Coefficients (with 95% confidence bounds):
21 a = 6.965e-05 (-0.0003081, 0.0004474)
22 b = 4.886 (3.466, 6.306)
23 c = 195.7 (128.7, 262.7)
24 d = 0.9555 (0.8199, 1.091)
25
26 Senzor MQ7 - CO Monoxid de carbon
27 f(x) = a*exp(b*x) + c*exp(d*x)
28 Coefficients (with 95% confidence bounds):
29 a = 8.646 (1.403, 15.89)
30 b = 0.7393 (0.495, 0.9837)
31 c = 4.569e-08 (-3.092e-07, 4.006e-07)
32 d = 4.92 (3.27, 6.571)
33
34 Senzor MQ 135
35 f(x) = a*exp(b*x) + c*exp(d*x)
36 Coefficients (with 95% confidence bounds):
37 a = 16.77 (-6.184, 39.73)
38 b = 1.154 (0.6361, 1.671)
39 c = 1.589e-07 (-1.123e-06, 1.441e-06)
40 d = 6.654 (4.369, 8.939)
41
42 """
43
44 import time
45 import datetime
46 import numpy as np
47 import matplotlib.pyplot as plt
48
49 from ADS1115 import ADS1115
50 ads1115 = ADS1115()
51
52 " Senzori de gaze tip: MQ4 -metan (NH4) ; MQ7 - monoxid de carbon (CO) ; MQ135 -
hidrogen (H2) "
53
54 senzor = 'MQ135'
55
56 plt.ion()
57
58 ConcGAZ_lista = []
59
60 axaOX = []
61 var1 = 0
62
63 acuma = datetime.datetime.now().strftime("%y-%m-%d %H-%M-%S")
64 filename = "/home/pi/SenzoriGAZE_MQ/DateEXP/SENZOR_"+str(senzor)+ "_"+
str(acuma)+".csv"
65 f = open(filename,"w+")
66
67 print(""" Laborator SMAPD Program monitorizare concentratie gaze, Senzor tip-"""
,senzor, """ -
68 Press Ctrl+C to exit"""
69 )
70 time.sleep(5)
71
72 def decimalToBinary(n):
73 return bin(n).replace("0b", "")
74
75 while True :
76 DataOra = datetime.datetime.now().strftime("%y-%m-%d %H:%M:%S")
77 ads1115.set_channel()
78 ads1115.config_single_ended()
79 time.sleep(0.1)
80 adc = ads1115.read_adc()
81 volt = 4.096*adc/32767
82
83 if senzor == 'MQ4' :
84
85 a = 6.965e-05
86 b = 4.886
87 c = 195.7
88 d = 0.9555
89 ConcNH4_ppm = a*np.exp(b*volt) + c*np.exp(d*volt)
90 ConcNH4 = round(ConcNH4_ppm,3)
91 ConcGAZ = ConcNH4
92
93 elif senzor == 'MQ7' :
94
95 a = 8.646
96 b = 0.7393
97 c = 4.569e-08
98 d = 4.92
99 ConcCO_ppm = a*np.exp(b*volt) + c*np.exp(d*volt)
100 ConcCO = round(ConcCO_ppm,3)
101 ConcGAZ = ConcCO
102
103 elif senzor == 'MQ135' :
104
105 a = 16.77
106 b = 1.154
107 c = 1.589e-07
108 d = 6.654
109 ConcH2_ppm = a*np.exp(b*volt) + c*np.exp(d*volt)
110 ConcH2 = round(ConcH2_ppm,3)
111 ConcGAZ = ConcH2
112
113 print ("Senzor tip : ", senzor)
114 print ("Value binary - 16 bits ", '{0:016b}'.format(adc))
115 print ("Digital Value of Analog Input : %d ", (adc))
116 print ("Analog Value of Input : %d ,", volt)
117 print (" ********************************************* ")
118 print ("Conc Gaz_ppm : %d ,", ConcGAZ)
119
120
121
122 f.write(DataOra +',Senzor,'+str(senzor) +' ,digital, '+str(adc)+', analog,
'+str(volt)+
123 ', ConcGaz, '+str(ConcGAZ) + "\r\n")
124 f.flush()
125
126 ConcGAZ_lista.append(ConcGAZ)
127
128 axaOX.append(var1)
129 var1 = var1+1
130
131 time.sleep(1)
132
133 if var1/10 == int(var1/10):
134 plt.clf()
135 #plt.plot(axaOX,Analog_lista,'m')
136 plt.plot(axaOX,ConcGAZ_lista,'r')
137
138 plt.ylabel('ConcGaz[ppm]')
139 plt.title('Senzor tip: '+ str(senzor))
140 plt.grid(True)
141 plt.draw()
142
143

You might also like