-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathAirQualitySensorLibrary.py
61 lines (37 loc) · 1.01 KB
/
AirQualitySensorLibrary.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#
# read and interpret AirQualitySensor
# SwitchDoc Labs April 2016 - reversed sense of AirQuality sensor numbers
#
import time
# Check for user imports
try:
import conflocal as config
except ImportError:
import config
def readAirQualitySensor(ads1115):
# Select the gain
gain = 6144 # +/- 6.144V
# Select the sample rate
sps = 250 # 250 samples per second
sensor_value = ads1115.readRaw(config.AirQualityADPin, gain, sps)
return sensor_value
def interpretAirQualitySensor(sensor_value):
value = ""
returnValue = -1
if (sensor_value > 11200):
value = "Very High Pollution Detected"
returnValue= 4;
if (sensor_value > 6400):
value = "High Pollution"
returnValue= 3;
if (sensor_value > 4800):
value = "Medium Pollution"
returnValue= 2
if (sensor_value > 3200):
value = "Low Pollution"
returnValue= 1
else:
value = "Fresh Air"
returnValue= 0
atuple = (value, returnValue)
return list(atuple)