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();
}
}