Hello friends,
Apologies if this issue has been already answered. I am trying to test a sketch to display the Temperature and Humidity values using the Lightblue App in IOS and it seems whatever I do the temperature characteristic is not showing. Humidity is coming up with exactly identical code. I am using the nrf52840 BLE Sense Module. Any help will be greatly appreciated !
type or paste code here
``` * Connections:
* ============
* DHT11 NRF52840
* -------- ---------
* GND GND
* VCC 3.3V
* DATA Pin 7
*-------------------------
NOTE : If the COM port does not show up press the tiny RESET button Twice
*/
#include <ArduinoBLE.h>
#include <DHT.h>
#define DHTPIN D7 // Analog Pin sensor is connected to
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
int temperature;
int humidity;
int oldtemperature = 0;
int oldhumidity = 0;
// Bluetooth® Low Energy Service
BLEService temperatureService("2A6E");
BLEService humService("2A6F");
// Bluetooth® Low Energy Battery Level Characteristic
BLEUnsignedCharCharacteristic temperatureChar("2800", BLERead | BLENotify); // standard 16-bit characteristic UUID
BLEUnsignedCharCharacteristic humidityChar("2804", BLERead | BLENotify); // standard 16-bit characteristic UUID
// remote clients will be able to get notifications if this characteristic changes
long previousMillis = 0; // last time the dht value was checked, in ms
void setup() {
Serial.begin(9600); // initialize serial communication
while (!Serial)
;
pinMode(LED_BUILTIN, OUTPUT); // initialize the built-in LED pin to indicate when a central is connected
// begin initialization
if (!BLE.begin()) {
Serial.println("starting BLE failed!");
while (1)
;
}
BLE.setLocalName("DhtMonitor");
BLE.setAdvertisedService(temperatureService); // add the service UUID
temperatureService.addCharacteristic(temperatureChar); // add the temperature characteristic
BLE.addService(temperatureService); // Add the temperature service
temperatureChar.writeValue(oldtemperature); // set initial value for this characteristic
BLE.setAdvertisedService(humService); // add the service UUID
humService.addCharacteristic(humidityChar); // add the humidity characteristic
BLE.addService(humService); // Add the humidity service
humidityChar.writeValue(oldhumidity); // set initial value for this characteristic
// start advertising
BLE.advertise();
Serial.println("Bluetooth® device active, waiting for connections...");
}
void loop() {
// wait for a Bluetooth® Low Energy central
BLEDevice central = BLE.central();
// if a central is connected to the peripheral:
if (central) {
Serial.print("Connected to central: ");
// print the central's BT address:
Serial.println(central.address());
// turn on the LED to indicate the connection:
digitalWrite(LED_BUILTIN, LOW); //The builtin LED turns on when LOW and viceversa
while (central.connected()) {
long currentMillis = millis();
if (currentMillis - previousMillis >= 1000) {
previousMillis = currentMillis;
updatedht();
}
}
// when the central disconnects, turn off the LED:
digitalWrite(LED_BUILTIN, HIGH);
Serial.print("Disconnected from central: ");
Serial.println(central.address());
} else BLE.advertise();
}
void updatedht() {
//DHT.read11(dht_pin);
temperature = dht.readTemperature(true);
humidity = dht.readHumidity();
if ((temperature != oldtemperature) || (humidity != oldhumidity)) // if the dht value has changed
{
Serial.print("Temperature: "); // print it
Serial.print(temperature);
Serial.println("*F");
Serial.print("Humidity: "); // print it
Serial.print(humidity);
Serial.println("%");
temperatureChar.writeValue(temperature); // and update the temperature
oldtemperature = temperature; // save the level for next comparison
humidityChar.writeValue(humidity); // and update the humidity
oldhumidity = humidity; // save the level for next comparison
}
}