My dht11 sensor can't send data to blynk

Hello, this is my first experience using this IoT equipment, and I have a problem where my DHT11 sensor cannot send data to the Blynk, where the gauge on the Blynk keeps showing the number 0 and doesn’t change at all even though the datastream has been connected as it should. I’m using NodeMCU with ESP8266. Please help because other sensors work as they should but not dht11

#define BLYNK_TEMPLATE_ID "TMPL6ZLR4Rs5T"
#define BLYNK_TEMPLATE_NAME "Sensor Kebakaran"
#define BLYNK_AUTH_TOKEN "ENSCLcPHZ5SYdG2lANcC5L2gTePDSJCW"

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
#include <Adafruit_Sensor.h>

// Blynk Auth Token
char auth[] = BLYNK_AUTH_TOKEN;

// WiFi credentials
char ssid[] = "---";
char pass[] = "---";

#define FLAME_SENSOR_PIN D5 // Pin yang terhubung ke Flame Sensor
#define SMOKE_SENSOR_PIN A0 // Pin yang terhubung ke MQ2 Smoke Sensor (Analog Output)
#define BUZZER_PIN D7 // Pin yang terhubung ke Buzzer
#define LED_PIN D8 // Pin yang terhubung ke LED
#define DHT_PIN D6 // Pin yang terhubung ke sensor suhu DHT
#define DHT_TYPE DHT11 // Tipe sensor suhu DHT (DHT11 atau DHT22)

#define FLAME_THRESHOLD LOW // Ambang batas untuk sensor api
#define SMOKE_THRESHOLD 1000 // Ambang batas untuk sensor asap

DHT dht(DHT_PIN, DHT_TYPE);

bool isAlarmActive = false;
bool isDeviceOn = false;

void setup() {
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);

  pinMode(FLAME_SENSOR_PIN, INPUT);
  pinMode(SMOKE_SENSOR_PIN, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(LED_PIN, OUTPUT);

  digitalWrite(BUZZER_PIN, LOW);
  digitalWrite(LED_PIN, LOW);

  dht.begin();
}

void loop() {
  Blynk.run();

  if (isDeviceOn) {
    int flameValue = digitalRead(FLAME_SENSOR_PIN);
    int smokeValue = analogRead(SMOKE_SENSOR_PIN);
    float temperature = dht.readTemperature(); // Membaca suhu dari sensor DHT

    // Kirim nilai sensor api, gas, dan suhu ke aplikasi Blynk
    Blynk.virtualWrite(V4, flameValue);
    Blynk.virtualWrite(V5, smokeValue);
    Blynk.virtualWrite(V2, temperature);

    // Jika terdeteksi api, asap, atau suhu tinggi
    if ((flameValue == FLAME_THRESHOLD || smokeValue >= SMOKE_THRESHOLD || temperature >= 30.0) && !isAlarmActive) {
      //Serial.println("Fire/smoke/heat detected!");
      activateAlarm();
      
    }
  }

 if (digitalRead(LED_PIN) == HIGH) {
    Blynk.virtualWrite(V0, 1); // Menghidupkan Widget LED di Blynk
    Blynk.virtualWrite(V4, 0);
  } else {
    Blynk.virtualWrite(V0, 0); // Mematikan Widget LED di Blynk
    Blynk.virtualWrite(V4, 1);
  }


  delay(500);
}

void activateAlarm() {
  digitalWrite(BUZZER_PIN, HIGH);
  digitalWrite(LED_PIN, HIGH);
  isAlarmActive = true;
}

void deactivateAlarm() {
  digitalWrite(BUZZER_PIN, LOW);
  digitalWrite(LED_PIN, LOW);
  isAlarmActive = false;
}

void activateDevice() {
  isDeviceOn = true;
}

void deactivateDevice() {
  isDeviceOn = false;
  deactivateAlarm(); // Memastikan alarm dimatikan saat perangkat dimatikan
}

BLYNK_WRITE(V1) {
  int pinValue = param.asInt();
  if (pinValue == 1 && !isDeviceOn) {
    // Menghidupkan perangkat jika tombol di Blynk ditekan
    activateDevice();
  } else if (pinValue == 0 && isDeviceOn) {
    // Mematikan perangkat jika tombol di Blynk ditekan
    deactivateDevice();
  }
}
BLYNK_WRITE(V0) {
  int pinValue = param.asInt();
  if (pinValue == 1 && !isAlarmActive) {
    // Menghidupkan alarm jika tombol di Blynk ditekan
    activateAlarm();
  } else if (pinValue == 0 && isAlarmActive) {
    // Mematikan alarm jika tombol di Blynk ditekan
    deactivateAlarm();
  }
}

First of all, you should read this…

Then you should take a look at the Blynk DHT example and how it does a NaN (Not a Number) check on the DHT readings before sending them to Blynk…

Lines 58-68 of this sketch are the ones you should be looking at.

If you still have problems then you need to do a serial print of the temperature value so that you can see what value the sensor is returning in your serial monitor. If that’s the value you are expecting then check how you’ve configured your temperature datastream, especially the min/max values.

Pete.

How many times have you posted this exact same answer? Your patience with lazy noobs are remarkable! :nerd_face: :grin:

Oh my! The dreaded timer.setInterval(1000L, sendSensor); is still in the DHT11 example sketch! :face_with_peeking_eye:

Have a good one Pete!

2 Likes

:rofl: :rofl: :rofl:

1 Like