ต่อเซ็นเซอร์ DHT22 ไม่ได้

ลงไลบลารี่แล้ว ทำทุกอย่างที่หาได้หมดแล้วครับ

Code:

#define BLYNK_TEMPLATE_ID   "xxxxxxxxx"
#define BLYNK_DEVICE_NAME "Smart Fan"
#define BLYNK_AUTH_TOKEN "xxxxxxxxxxxxxx"

char ssid[] = "xxxx";
char pass[] = "xxxxxxx";

bool fetch_blynk_state = true;

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

#define DHTPIN              D4
#define DHTTYPE DHT22

#define RelayPin1           D1
#define RelayPin2           D2
#define RelayPin3           D3

#define BLYNK_Fan_OFF     V1
#define BLYNK_Speed_1     V2
#define BLYNK_Speed_2     V3
#define BLYNK_Speed_3     V4

#define BLYNK_Temp        V7

bool toggleState_1 = LOW;
bool toggleState_2 = LOW;
bool toggleState_3 = LOW;

bool SwitchState_1 = LOW;
bool SwitchState_2 = LOW;
bool SwitchState_3 = LOW;

int wifiFlag = 0;
float temperature1 = 0;

char auth[] = BLYNK_AUTH_TOKEN;

BlynkTimer timer;
DHT dht(DHTPIN, DHTTYPE);

BLYNK_WRITE(BLYNK_Speed_1) 
{
  toggleState_1 = param.asInt();
  digitalWrite(RelayPin1, !toggleState_1);
}

BLYNK_WRITE(BLYNK_Speed_2) 
{
  toggleState_2 = param.asInt();
  digitalWrite(RelayPin2, !toggleState_2);
}

BLYNK_WRITE(BLYNK_Speed_3) 
{
  toggleState_3 = param.asInt();
  digitalWrite(RelayPin3, !toggleState_3);
}

BLYNK_WRITE(BLYNK_Fan_OFF) 
{
  all_SwitchOff();
}

void all_SwitchOff()
{
  toggleState_1 = 0; digitalWrite(RelayPin1, HIGH); Blynk.virtualWrite(BLYNK_Speed_1, toggleState_1); delay(100);
  toggleState_2 = 0; digitalWrite(RelayPin2, HIGH); Blynk.virtualWrite(BLYNK_Speed_2, toggleState_2); delay(100);
  toggleState_3 = 0; digitalWrite(RelayPin3, HIGH); Blynk.virtualWrite(BLYNK_Speed_3, toggleState_3); delay(100);
  Blynk.virtualWrite(BLYNK_Temp, temperature1);
}

void checkBlynkStatus() { // called every 2 seconds by SimpleTimer

  bool isconnected = Blynk.connected();
  if (isconnected == false) {
    wifiFlag = 1;
  }
  if (isconnected == true) 
  {
    wifiFlag = 0;
    if (!fetch_blynk_state)
    {
    Blynk.virtualWrite(BLYNK_Speed_1, toggleState_1);
    Blynk.virtualWrite(BLYNK_Speed_2, toggleState_2);
    Blynk.virtualWrite(BLYNK_Speed_3, toggleState_3);
    }
    Serial.println("Blynk Connected");
  }
}

BLYNK_CONNECTED() 
{
  if (fetch_blynk_state)
  {
    Blynk.syncVirtual(BLYNK_Speed_1);
    Blynk.syncVirtual(BLYNK_Speed_2);
    Blynk.syncVirtual(BLYNK_Speed_3);
  }
    Blynk.syncVirtual(BLYNK_Temp);  
}

void readSensor()
{
  float t = dht.readTemperature();
  
  if (isnan(h) || isnan(t)) 
  {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  else 
  {
    temperature1 = t;
  }  
}

void sendSensor()
{
  readSensor();
  Blynk.virtualWrite(BLYNK_Temp, temperature1);
}

void setup()
{
  Serial.begin(9600);

  pinMode(RelayPin1, OUTPUT);
  pinMode(RelayPin2, OUTPUT);
  pinMode(RelayPin3, OUTPUT);

  digitalWrite(RelayPin1, !toggleState_1);
  digitalWrite(RelayPin2, !toggleState_2);
  digitalWrite(RelayPin3, !toggleState_3);
  dht.begin();

  WiFi.begin(ssid, pass);
  timer.setInterval(1000L, sendSensor);
  Blynk.config(auth);
  delay(1000);

  if (!fetch_blynk_state)
  {
    Blynk.virtualWrite(BLYNK_Speed_1, toggleState_1);
    Blynk.virtualWrite(BLYNK_Speed_2, toggleState_2);
    Blynk.virtualWrite(BLYNK_Speed_3, toggleState_3);
  }
}

void loop()
{ 
  Blynk.run();
  timer.run();
}

Error Messeges:

Arduino: 1.8.19 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Disabled (new aborts on oom), Disabled, All SSL ciphers (most compatible), 32KB cache + 32KB IRAM (balanced), Use pgm_read macros for IRAM/PROGMEM, 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200"





















Smart_Fan_3.0:15:17: error: 'DHT22' was not declared in this scope; did you mean 'DHT'?

C:\Users\MyPC\OneDrive\เอกสาร\Arduino\Smart_Fan_3.0\Smart_Fan_3.0.ino:42:17: note: in expansion of macro 'DHTTYPE'

C:\Users\MyPC\OneDrive\เอกสาร\Arduino\Smart_Fan_3.0\Smart_Fan_3.0.ino: In function 'void readSensor()':

Smart_Fan_3.0:107:17: error: 'class DHT' has no member named 'readTemperature'; did you mean 'getTemperature'?

Smart_Fan_3.0:109:13: error: 'h' was not declared in this scope

C:\Users\MyPC\OneDrive\เอกสาร\Arduino\Smart_Fan_3.0\Smart_Fan_3.0.ino: In function 'void setup()':

Smart_Fan_3.0:137:7: error: 'class DHT' has no member named 'begin'

Multiple libraries were found for "DHT.h"

 Used: C:\Users\MyPC\Downloads\Blynk_Release_v1.1.0\libraries\DHT

 Not used: C:\Users\MyPC\Downloads\Blynk_Release_v1.1.0\libraries\DHT-sensor-library-master

 Not used: C:\Users\MyPC\Downloads\Blynk_Release_v1.1.0\libraries\DHT_sensor_library

 Not used: C:\Users\MyPC\Downloads\Blynk_Release_v1.1.0\libraries\DHT_sensor_library-1.4.4

 Not used: C:\Program Files (x86)\Arduino\libraries\DHT

exit status 1

'DHT22' was not declared in this scope; did you mean 'DHT'?



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

ลง library dht22 รึยังครับ

ได้แล้วครับ ได้แบบงงๆ
ขอถามอีกนิด พอดีโค้ดใช้กับรีเลย์แบบนี้ :
Screenshot 2022-06-20 110843

จะให้ใช้กับรีเลย์แบบนี้ต้องเปลี่ยนตรงไหนครับ
Screenshot 2022-07-07 080132

ปล.ใช้แบบที่สองอยู่แล้วเวลาเปิดรีเลย์ ON ทุกตัวเลย ซึ่งควรจะ ON เมื่อกดสวิตช์ครับ

เปลี่ยนคำสั่งจาก low เป็น high ครับ มัน active คนละแบบ

คำถามสุดท้ายครับ😂
พอดีทำโปรฯควบคุมพัดลมผ่าน blynk แต่ติดปัญหาตรง Blynk_Write ของแต่ละปุ่มยังไม่สามารถทำให้เวลา ON แล้วปุ่มอื่นๆจะดับเองอย่างปุ่มกดพัดลมครับ ต้องเพิ่มโค้ดตรงไหนดี