forked from ledeveo/Tomaattivahti
/
tomaattivahti.ino
45 lines (39 loc) · 951 Bytes
/
tomaattivahti.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
#include <dht.h>
dht DHT;
#define DHT11_PIN 2
int soilPin = 7;
int soilValue = 0;
int soilpre = 0;
int sensorPin = A5;
int lightValue = 0;
int lightpre = 0;
float temppre = 0;
float humpre = 0;
float temp = 0;
float hum = 0;
void setup() {
Serial.begin(115200);
}
void loop() {
soilValue = analogRead(soilPin);
int chk = DHT.read11(DHT11_PIN); //needed for DHT library to work
lightValue = analogRead(sensorPin);
soilValue = int(0.7*soilValue + 0.3*soilpre);//floating average
soilpre = soilValue;
hum = DHT.humidity;
hum = 0.7*hum + 0.3*humpre;
humpre = hum;
temp = DHT.temperature;
temp = 0.7*temp + 0.3*temppre;
temppre = temp;
lightValue = int(0.7*lightValue + 0.3*lightpre);
lightpre = lightValue;
Serial.print(DHT.humidity, 1);
Serial.print("\t");
Serial.print(DHT.temperature, 1);
Serial.print("\t");
Serial.print(soilValue);
Serial.print("\t");
Serial.println(lightValue, DEC);
delay(200);
}