-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscriptArduino.ino
More file actions
42 lines (35 loc) · 1.02 KB
/
scriptArduino.ino
File metadata and controls
42 lines (35 loc) · 1.02 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
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
dht.begin();
}
void loop() {
// put your main code here, to run repeatedly:
delay(1000);
// Leemos la humedad relativa
float h = dht.readHumidity();
// Leemos la temperatura en grados centígrados (por defecto)
float t = dht.readTemperature();
// Leemos la temperatura en grados Fahrenheit
float f = dht.readTemperature(true);
// Comprobamos si ha habido algún error en la lectura
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Error obteniendo los datos del sensor DHT11");
return;
}
// Calcular el índice de calor en grados centígrados
float hic = dht.computeHeatIndex(t, h, false);
Serial.print("Humedad: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperatura: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print("Índice de calor: ");
Serial.print(hic);
Serial.println(" *C ");
}