-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathArduinoTX.ino
More file actions
93 lines (75 loc) · 1.75 KB
/
ArduinoTX.ino
File metadata and controls
93 lines (75 loc) · 1.75 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
/*
* Arduino with THO2(Temperature/Humidity) and VOC sensors.
*
* This example show how to send the Name and Value of each Sensor
* to ESP module through Serial Port.
*
* Created by Lidia Pocero.
*/
//Libraries for I2C comunication with the THO
#include <Wire.h>
#include <TH02_dev.h>
//Estructure for each Sensor
struct Sensor {
String Name;
float Value;
};
//Definde your Sensor number
const int VarNumber = 3;
//Array of Sensors
Sensor MySensors[VarNumber];
void setup()
{
Wire.begin();
//Digital Sensors
/* Power up,delay 150ms,until voltage is stable */
delay(150);
/* Reset HP20x_dev */
TH02.begin();
delay(150);
}
void loop()
{
//TH02 sensor
//Temperature value
float t = TH02.ReadTemperature();
//Sensor name: The name of the sensor on Sensorflare
MySensors[0].Name = "mydev1/temperature";
//Sensor value
MySensors[0].Value = t;
delay(150);
//Humidity value
float h = TH02.ReadHumidity();
//Sensor name: The name of the sensor on Sensorflare
MySensors[1].Name = "mydev1/humidity";
//Sensor value
MySensors[1].Value = h;
delay(150);
//VOC sensor
int gas = analogRead(A2);
float voc = gas * 4.9;
//Sensor name: The name of the sensor on Sensorflare
MySensors[2].Name = "mydev1/voc";
//Sensor value
MySensors[2].Value = voc;
//Send all the Sensor Values to ESP
SendToESP();
}
//Funcion that send the variable names and the variable values to the ESP
void SendToESP()
{
int i = 0;
char Val[10];
Serial.begin(9600);
while (i < VarNumber)
{
dtostrf(MySensors[i].Value, 4, 2, Val);
Serial.print(MySensors[i].Name);
Serial.print(":");
Serial.println(Val);
i++;
}
Serial.end();
//Later of each send to ESP wait half minets before to go back
delay(30000);
}