Hello
I want to the values to be read from the dht11 sensor every 10 seconds. When the notification comes, I want to my next notification to come after 5 minutes. Can you check my code?
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <timer.h>
#include <dht11.h> // dht11 kütüphanesini ekliyoruz.
#define DHT11PIN 4 // DHT11PIN olarak Dijital 2"yi belirliyoruz.
dht11 DHT11;
int sicaklik, nem;
Timer timer;
// OKUNABİLİR VERİLER
// SICAKLIK - DHT11.temperature
// NEM - DHT11.humidity
// ÇİĞ NOKTASI - DHT11.fahrenheit()
// KELVİN - DHT11.kelvin()
// ÇİĞ NOKTASI - DHT11.dewPoint()
char auth[33] = "";
char ssid[33] = "";
char pass[33] = "";
void setup() {
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
}
BLYNK_READ(V0){
DHT11.read(DHT11PIN);
sicaklik = DHT11.temperature;
Serial.println("Sıcaklık: " + String(sicaklik));
Blynk.virtualWrite(V0, sicaklik);
}
BLYNK_READ(V1) {
DHT11.read(DHT11PIN);
nem = DHT11.humidity;
Serial.println("Nem: " + String(nem));
Blynk.virtualWrite(V1, nem);
}
void loop() {
sicaklik_alert();
nem_alert();
Blynk.run();
}
void sicaklik_alert(){
delay(15000);
if(sicaklik > 28)
{
Blynk.notify(String("Sıcaklık Yüksek ")+sicaklik + String("°C"));
}
if(sicaklik > 28)
{
Blynk.email("mail address", String("Sıcaklık Yüksek ")+sicaklik + String("°C"));
}
if(sicaklik < 21)
{
Blynk.notify(String("Sıcaklık Düşük ")+sicaklik + String("°C"));
}
if(sicaklik < 21)
{
Blynk.email("mail address", String("Sıcaklık Düşük ")+sicaklik + String("°C"));
}
}
void nem_alert(){
if(nem > 85)
{
Blynk.email("mail address", String("Nem Yüksek ")+nem + String(" RH"));
}
if(nem < 50)
{
Blynk.email("mail address", String("Nem Düşük ")+nem + String(" RH"));
}
if(nem > 85)
{
Blynk.notify(String("Nem Yüksek ")+nem + String(" RH"));
}
if(nem < 50)
{
Blynk.notify(String("Nem Düşük ")+nem + String(" RH"));
}
}
@Adem_Akbulut please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```
Pete.
You should start by reading this…
https://docs.blynk.io/en/legacy-platform/legacy-articles/keep-your-void-loop-clean
and getting rid of the delays and the function calls in your void loop, and using a BlynkTimer instead.
Pete.
Thank you for your support.
I solved my problem by changing my code as below.
// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
// Your WiFi credentials.
// Set password to "" for open networks.
char auth[] = "";
char ssid[] = "";
char pass[] = "";
#define DHTPIN 4 // What digital pin we're connected to
// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21 // DHT 21, AM2301
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 nem = dht.readHumidity();
float sicaklik = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(nem) || isnan(sicaklik)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V1, nem);
Blynk.virtualWrite(V0, sicaklik);
}
void sendAlert()
{
float nem = dht.readHumidity();
float sicaklik = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if(sicaklik > 26)
{
Blynk.notify(String("Sıcaklık Yüksek ")+sicaklik + String("°C"));
}
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V0, sicaklik);
}
void setup()
{
// Debug console
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
dht.begin();
// Setup a function to be called every second
timer.setInterval(5000L, sendSensor);
timer.setInterval(60000L, sendAlert);
}
void loop()
{
Blynk.run();
timer.run();
}