ขอคำแนะนำเกี่ยวกับการควบคุม อุณหภูมิ และคุมความชื่้น หน่อยครับ Error

โคดนี้ผมเขียนตามความเข้าใจ ซึ่ง Error ช่วยแก้ไขผมหน่อยครับ

#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleDHT.h>
#include <SimpleTimer.h>
//ปั้ม
 int pinPump1 = D3;
 int pinPump2 = D4;
 int pinPump3 = D6;
// DHT Config
int pinDHT22 = D5;
SimpleDHT22 dht22;

// SET Timer
SimpleTimer timer;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Ammara_2.4GHz";
char pass[] = "0866922890";

BLYNK_CONNECTED() {
    Blynk.syncAll();
}

void setup()
{
  // Debug console
  Serial.begin(9600);
  // You can also specify server:
  Blynk.begin(auth, ssid, pass, "oasiskit.com", 8080);
  timer.setInterval(4000L, sendTemp);
  pinMode(pinPump1, OUTPUT);
  pinMode(pinPump2, OUTPUT);
  pinMode(pinPump3, OUTPUT);
}

void sendTemp()
{
  float temperature = 0;
  float humidity = 0;
  int err = SimpleDHTErrSuccess;
  if ((err = dht22.read2(pinDHT22, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
    Serial.print("Read DHT22 failed, err="); Serial.println(err);delay(2000);
    return;
}  
  Blynk.virtualWrite(10, temperature); // virtual pin 
  Blynk.virtualWrite(11, humidity); // virtual pin 
}

void loop()
{
  float h = Humidity();
  float t = Temperature();
  if (temperature >= 28)
  [
    digitalWrite(pinPump1, HIGH);
    digitalWrite(pinPump2, HIGH);
    digitalWrite(pinPump3, HIGH);
  ]
  else
  [
    digitalWrite(pinPump1, LOW);
    digitalWrite(pinPump2, LOW);
    digitalWrite(pinPump3, LOW);
  ]
  if (humidity <= 79)
  [
    digitalWrite(pinPump1, HIGH);
    digitalWrite(pinPump2, HIGH);
    digitalWrite(pinPump3, HIGH);
  ]
  else
  [
    digitalWrite(pinPump1, LOW);
    digitalWrite(pinPump2, LOW);
    digitalWrite(pinPump3, LOW);
  ]
  Blynk.run();
  timer.run();
}

โค้ด Error

Arduino:1.8.13 (Windows 10), บอร์ด:"NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Disabled, 4M (no SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200"












C:\Users\huawe\Documents\Arduino\dth22\dth22.ino: In function 'void loop()':

dth22:59:7: error: 'temperature' was not declared in this scope

   if (temperature >= 28)

       ^

dth22:61:5: error: capture of non-variable 'void digitalWrite(uint8_t, uint8_t)' 

     digitalWrite(pinPump1, HIGH);

     ^

In file included from sketch\dth22.ino.cpp:1:0:

C:\Users\huawe\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266/Arduino.h:200:6: note: 'void digitalWrite(uint8_t, uint8_t)' declared here

 void digitalWrite(uint8_t pin, uint8_t val);

      ^

dth22:61:17: error: expected ',' before '(' token

     digitalWrite(pinPump1, HIGH);

                 ^

dth22:61:17: error: expected identifier before '(' token

dth22:61:33: error: expected ']' before ';' token

     digitalWrite(pinPump1, HIGH);

                                 ^

C:\Users\huawe\Documents\Arduino\dth22\dth22.ino: In lambda function:

dth22:61:33: error: expected '{' before ';' token

C:\Users\huawe\Documents\Arduino\dth22\dth22.ino: In function 'void loop()':

dth22:64:3: error: expected primary-expression before ']' token

   ]

   ^

dth22:64:3: error: expected ';' before ']' token

dth22:70:3: error: expected primary-expression before ']' token

   ]

   ^

dth22:70:3: error: expected ';' before ']' token

dth22:76:3: error: expected primary-expression before ']' token

   ]

   ^

dth22:76:3: error: expected ';' before ']' token

dth22:82:3: error: expected primary-expression before ']' token

   ]

   ^

dth22:82:3: error: expected ';' before ']' token

exit status 1

'temperature' was not declared in this scope



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

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

นี่คือ library ของผม ต้องลงอันไหนเพิ่มบ้างครับ

มันมีปันหาตรงส่วนนี้

  float t = temperature()
  float h = humidity()
  
  if (t >= 28)
  [
    digitalWrite(pinPump1, HIGH);
    digitalWrite(pinPump2, HIGH);
    digitalWrite(pinPump3, HIGH);
  ]
  else
  [
    digitalWrite(pinPump1, LOW);
    digitalWrite(pinPump2, LOW);
    digitalWrite(pinPump3, LOW);
  ]
  if (h <= 79)
  [
    digitalWrite(pinPump1, HIGH);
    digitalWrite(pinPump2, HIGH);
    digitalWrite(pinPump3, HIGH);
  ]
  else
  [
    digitalWrite(pinPump1, LOW);
    digitalWrite(pinPump2, LOW);
    digitalWrite(pinPump3, LOW);
  ]

โคดError

Arduino:1.8.13 (Windows 10), บอร์ด:"NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Disabled, 4M (no SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 9600"





















C:\Users\huawe\Documents\Arduino\dth22\dth22.ino: In function 'void loop()':

dth22:59:25: error: 'temperature' was not declared in this scope

   float t = temperature()

                         ^

dth22:67:3: error: expected primary-expression before ']' token

   ]

   ^

dth22:67:3: error: expected ';' before ']' token

dth22:73:3: error: expected primary-expression before ']' token

   ]

   ^

dth22:73:3: error: expected ';' before ']' token

dth22:79:3: error: expected primary-expression before ']' token

   ]

   ^

dth22:79:3: error: expected ';' before ']' token

dth22:85:3: error: expected primary-expression before ']' token

   ]

   ^

dth22:85:3: error: expected ';' before ']' token

exit status 1

'temperature' was not declared in this scope



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

BLYNK_WRITE(V4) มันตรงกับvไหนของSliderหรอครับ
BLYNK_WRITE(V3)มันตรงกับvไหนของSliderหรอครับ

ลองดูครับ ผม complies ผ่านนะครับ

#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleDHT.h>
#include <SimpleTimer.h>
//ปั้ม
 int pinPump1 = D3;
 int pinPump2 = D4;
 int pinPump3 = D6;
// DHT Config
int pinDHT22 = D5;
SimpleDHT22 dht22;

// SET Timer
SimpleTimer timer;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Ammara_2.4GHz";
char pass[] = "0866922890";

BLYNK_CONNECTED() {
    Blynk.syncAll();
}


  float temperature = 0;
  float humidity = 0;

void setup()
{
  // Debug console
  Serial.begin(9600);
  // You can also specify server:
  Blynk.begin(auth, ssid, pass, "oasiskit.com", 8080);
  timer.setInterval(4000L, sendTemp);
  pinMode(pinPump1, OUTPUT);
  pinMode(pinPump2, OUTPUT);
  pinMode(pinPump3, OUTPUT);
}

void sendTemp()
{
 // float temperature = 0;
 // float humidity = 0;
  int err = SimpleDHTErrSuccess;
  if ((err = dht22.read2(pinDHT22, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
    Serial.print("Read DHT22 failed, err="); Serial.println(err);delay(2000);
    return;
}  
  Blynk.virtualWrite(10, temperature); // virtual pin 
  Blynk.virtualWrite(11, humidity); // virtual pin 
}

void loop()
{
//  float h = Humidity();
//  float t = Temperature();
  if (temperature >= 28)
  {
    digitalWrite(pinPump1, HIGH);
    digitalWrite(pinPump2, HIGH);
    digitalWrite(pinPump3, HIGH);
  }
  else
  {
    digitalWrite(pinPump1, LOW);
    digitalWrite(pinPump2, LOW);
    digitalWrite(pinPump3, LOW);
  }
  if (humidity <= 79)
  {
    digitalWrite(pinPump1, HIGH);
    digitalWrite(pinPump2, HIGH);
    digitalWrite(pinPump3, HIGH);
  }
  else
  {
    digitalWrite(pinPump1, LOW);
    digitalWrite(pinPump2, LOW);
    digitalWrite(pinPump3, LOW);
  }
  Blynk.run();
  timer.run();
}

ดูเหมือน มันลอยๆ อยู่ไม่ได้ใช้ครับ ผมลอง Disable ดู

float h = Humidity();
float t = Temperature();

ผมขอไลบลารี่พี่ยกโฟลเดอร์ได้ไหมครับ

ผมใช้แค่ตัวนี้กับการ แก้ code เล็กน้อยครับ
SimpleDHT.rar (14.9 KB)

1

พี่ผมจะเพิ่มคุมอุณหภูมิด้วนครับ

complies ผ่านแล้วเหรอครับ

ลืมคับ55555

ลองดูก่อนครับ แล้ว upload ดูว่ามันใช้ได้มั๊ย

Arduino: 1.8.13 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200"





D:\Documents\Arduino\sketch_sep10b\sketch_sep10b.ino: In function 'void loop()':

sketch_sep10b:75:32: error: expected '}' at end of input

     digitalWrite(pinPump3, LOW);

                                ^

sketch_sep10b:75:32: error: expected '}' at end of input

exit status 1

expected '}' at end of input



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

คือตอนนี้เอาCode ที่ผม ปรับแก้ไปใช้หรือปล่าวครับ ที่โพสต์ไว้ข้างบนน่ะครับ

1

ใช่คับ
ผมเอาโคดจากด้านบนคับ

มันฟ้องเรื่อง ปีกกาครับ เอาใหม่ครับ sketch_sep10b.rar (963 Bytes)

ผ่านแล้วคับผมขาดปีกกาไป 2ตัว

1 Like

ผมจะเพิ่มคุมความชื้นด้วยครับ