-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.ino
More file actions
113 lines (98 loc) · 2.12 KB
/
test.ino
File metadata and controls
113 lines (98 loc) · 2.12 KB
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
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <ArduinoJson.h>
#include "FS.h"
#include "DHT.h"
#include "MQ135.h"
#define DHTPIN D2
#define DHTTYPE DHT22
#define LED D7
#define relay D1
DHT dht(DHTPIN, DHTTYPE);
//const int LED = D7;
//const int relay = ;
const int mq135Pin = 0;
MQ135 gasSensor = MQ135(mq135Pin);
const int temperature = 1;
const int humidity = 1;
const int ir = 1;
const int voc = 1;
const int hp_control = 1;
int r_time = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(LED, OUTPUT);
pinMode(relay, OUTPUT);
Serial.setTimeout(2000);
if (voc == 1)
{
Serial.println("MQ135 Running!");
float rzero = gasSensor.getRZero();
Serial.print("R0: ");
Serial.println(rzero);
}
if (temperature == 1 || humidity == 1)
{
while (!Serial) {}
Serial.println("DHT22 Running!");
}
}
void loop() {
// put your main code here, to run repeatedly:
if (hp_control == 1)
{
digitalWrite(relay, HIGH);
delay(5000);
digitalWrite(relay, LOW);
delay(1000);
}
if (ir == 1)
{
digitalWrite(LED, HIGH);
delay(5000);
digitalWrite(LED, LOW);
delay(1000);
}
if (r_time > 20000)
{
if (voc == 1)
{
//float ppm = gasSensor.getPPM();
Serial.print("A0: ");
int gas = analogRead(mq135Pin);
Serial.println(gas);
//Serial.print(" ppm CO2: ");
//Serial.println(ppm);
}
if (temperature == 1)
{
float temperature = dht.readTemperature();
if (isnan(temperature))
{
Serial.println("Failed to read temperature from DHT sensor!");
r_time = 0;
return;
}
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println("*C");
}
if (humidity == 1)
{
float humidity = dht.readHumidity();
if (isnan(humidity))
{
Serial.println("Failed to read humidity from DHT sensor!");
r_time = 0;
return;
}
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println("%\t");
}
r_time = 0;
}
delay(100);
r_time += 12100;
}