-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch_mar29a.ino
145 lines (119 loc) · 3.21 KB
/
sketch_mar29a.ino
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//INCLUDES
#include <DHT.h>
#include <Wire.h>
#include <Adafruit_BMP085.h>
//DEFINITIONS
#define DHTPIN 7 // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
#define seaLevelPressure_hPa 1013.25
Adafruit_BMP085 bmp;
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino
//VARIABLES
int chk;
float hum; //Stores humidity value
float temp; //Stores temperature value
int dust; //Connect dust sensor to Arduino A0 pin
int samplingTime = 280;
int deltaTime = 40;
int sleepTime = 9680;
float voMeasured = 0;
float calcVoltage = 0;
float dustDensity = 0;
void setup()
{
Serial.begin(9600);
dht.begin();
}
void loop()
{
//LIGHT
unsigned int light;
//Serial.print("RAW Light data: ");
light = analogRead(A0);
//Serial.println(light);
if(light>=400 && light<700)
{
Serial.println("Normal lighting conditions");
}
else if(light<400)
{
Serial.println("Too bright");
}
else if(light>1000)
{
Serial.println("Dark environmental conditions");
}
//Temp & Humdidity
//Read data and store it to variables hum and temp
hum = dht.readHumidity();
temp= dht.readTemperature();
//Print temp and humidity values to serial monitor
Serial.print("Humidity: ");
Serial.print(hum);
Serial.print("%, Temp: ");
Serial.print(temp);
Serial.println("C");
//UV values
float sensorVoltage;
float uv_sensor;
uv_sensor = analogRead(1);
sensorVoltage = uv_sensor/1024*5.0;
//Serial.print("UV data= ");
//Serial.print(uv_sensor);
//Serial.print("UV sensor voltage = ");
//Serial.print(sensorVoltage);
//Serial.println(" V");
if(uv_sensor<=5)
{
Serial.println("Normal UV detected");
}
else if(uv_sensor>5)
{
Serial.println("High atmospheric UV detected");
}
//dust
// power on the LED
delayMicroseconds(samplingTime);
voMeasured = analogRead(A0); // read the dust value
delayMicroseconds(deltaTime);
delayMicroseconds(sleepTime);
// 0 - 5V mapped to 0 - 1023 integer values
// recover voltage
calcVoltage = voMeasured * (5.0 / 1024.0);
// linear eqaution taken from http://www.howmuchsnow.com/arduino/airquality/
// Chris Nafis (c) 2012
dustDensity = 170 * calcVoltage - 0.1;
Serial.print("Dust particles: ");
Serial.print(dustDensity);
Serial.println("PPM");
//Baro
//Serial.print("Temperature = ");
//Serial.print(bmp.readTemperature());
//Serial.println(" *C");
Serial.print("Pressure = ");
Serial.print(bmp.readPressure());
Serial.println(" Pa");
Serial.print("Altitude = ");
Serial.print((bmp.readAltitude()/100)*2.77);
Serial.println(" meters");
Serial.print("Pressure at sea level = ");
Serial.print(bmp.readSealevelPressure());
Serial.println(" Pa");
//Rain
int value;
value = analogRead(3);
//Serial.println("Rain data:");
//Serial.println(value);
//value = map(value,0,1023,225,0);
//Serial.println(value);
if(value>=1000)
{
Serial.println("Rain detected");
}
else
{
Serial.println("No rain detected");
}
Serial.println();
delay(3000);
}