Hi guys,
I connected my Arduino Uno with the Bluetooth module HC-08 and tried to send notifications through Blynk using the following code:
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <SoftwareSerial.h>
#include <BlynkSimpleSerialBLE.h>
#include <DHT.h>
char auth[] = "fdb435043f2e481696f2f8761de71c67";
SoftwareSerial SerialBLE(11, 10); // RX, TX
#define DHTPIN 2 // What digital pin we're connected to
#define DHTTYPE DHT11 // DHT 11
WidgetLED led1(V1);
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
float humidity = dht.readHumidity();
float temp = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(humidity) || isnan(temp)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print(" %, Temp: ");
Serial.print(temp);
Serial.println(" Celsius");
delay(1000); //Delay 1 sec.
Blynk.virtualWrite(V5, humidity);//Send humidity to blynk through Virtual 5
Blynk.virtualWrite(V6, temp);//Send temperature to blynk through Virtual 6
if(temp>26.00){
Serial.println("Alert - Temperature over 26C!");
Blynk.notify("Alert - Temperature over 26C!");
}
}
void setup()
{
// pinMode(led,OUTPUT);//declare pin 9 to be an output
Serial.begin(9600);
SerialBLE.begin(9600);
Blynk.begin(SerialBLE, auth);
Blynk.notify("Device started");
Serial.println("Waiting for connections...");
dht.begin();
// Setup a function to be called every second
timer.setInterval(1000L, sendSensor);
}
void loop()
{
Blynk.run();
timer.run();
}
The message “Alert - Temperature over 26C!” showed on my Serial Monitor when I ran the code, however, there was no notification sent to my iPhone6. I don’t know what went wrong. Thanks in advance!