-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDHT11.ino
73 lines (35 loc) · 1.45 KB
/
DHT11.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
#include <SPI.h>
#include <RF24.h>
#include <BTLE.h>
#include <DHT.h> // dht11 temperature and humidity sensor library
#define DHTPIN 4 // what digital pin we're connected to
#define DHTTYPE DHT11 // select dht type as DHT 11 or DHT22
DHT dht(DHTPIN, DHTTYPE);
RF24 radio(9, 10); // CE, CSN
BTLE btle(&radio);
void setup() {
Serial.begin(9600);
delay(1000);
Serial.print("BLE and DHT Starting... ");
Serial.println("Send Temperature Data over BTLE");
dht.begin(); // initialise DHT11 sensor
btle.begin("CD Temp"); // 8 chars max
Serial.println("Successfully Started");
}
void loop() {
float temp = dht.readTemperature();
float h,t; //read temperature data
if (isnan(h) || isnan(t)) { // Check if any reads failed and exit early (to try again).
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
Serial.print(" Temperature: "); Serial.print(t); Serial.println("°C ");
nrf_service_data buf;
buf.service_uuid = NRF_TEMPERATURE_SERVICE_UUID;
buf.value = BTLE::to_nRF_Float(temp);
if (!btle.advertise(0x16, &buf, sizeof(buf))) {
Serial.println("BTLE advertisement failed..!");
}
btle.hopChannel();
delay(2000);
}