ผมเชื่อมต่อเเล้วเเต่มัน error ช่วยเเนะนำหน่อยครับ ด่วนนิดนึงครับ ขอบคุณครับ
ส่วนของโค้ดครับ
----------------------------------------------
#include <LiquidCrystal.h>
#include <dht.h>
dht DHT;
#define DHT21_PIN 2
LiquidCrystal lcd(22, 24, 26, 28, 30, 32);
void setup()
{
Serial.begin(115200);
lcd.begin(20, 4);
Serial.println("Prueba de DHT");
Serial.print("Version de biblioteca: ");
Serial.println(DHT_LIB_VERSION);
Serial.println();
Serial.println("Sensor,\tEstado,\tHumedad (%),\tTemperatura (C)");
}
void loop()
{
// Lectura
Serial.print("DHT11, \t");
int chk = DHT.read11(DHT11_PIN);
switch (chk)
{
case DHTLIB_OK:
Serial.print("OK,\t");
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.print("Checksum error,\t");
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.print("Time out error,\t");
break;
default:
Serial.print("Unknown error,\t");
break;
}
// Envio a puerto serie
Serial.print(DHT.humidity,1);
Serial.print(",\t");
Serial.println(DHT.temperature,1);
// Envio a LCD
lcd.setCursor(0, 0);
lcd.print("Temp.: ");
lcd.print(DHT.temperature);
lcd.print((char)223);
lcd.print("C");
lcd.setCursor(0, 1);
lcd.print("Humedad: ");
lcd.print(DHT.humidity);
lcd.print("%");
delay(1000);
}
โคดส่วนจอ LCD ไม่มีปัญหา น่าจะติดปัญหาโคดตรงส่วน DHT ไลบารีลงไม่ถูกครับ
ผมแนะนำบทความนี้ สอนพื้นฐานจนถึงใช้งาน DHT ได้ครับ สอน วิธี ใช้งาน Arduino วัดอุณหภูมิและความชื้น ด้วยเซนเซอร์ DHT22 / DTH21 / DHT11 ใช้ได้ภายใน 3 นาที น่าจะทำได้ใน 3 นาที ได้ผลยังไงแจ้งด้วยนะครับ
โคดตรงส่วน DHT ไลบารี นั้นอยู๋ตรงไหนครับ ช่วยส่งลิ้งมาให้หน่อยครับ เเละช่วยเเนะนำการใช้งานด้วยครับ
สร้าง folder DHT หรือใน C:\Program Files\Arduino\libraries แล้วเปิดโปรแกรม arduino ว่ามี DHT ไหม
https://github.com/adafruit/DHT-sensor-library คลิกด้านขวาที่ชื่อ download Zip น่ะ
code น่าจะแบบนี้ลองดู
// Simple display of Humidity & Temperature using the DHT22 sensor from adafruit
// and a 16x2 LCD display
// Tony Akens
// 2/14/13
// Wiring for the LCD is as taken from arduino.cc, potentiometer included
// Wiring for DHT sensor is connecting data to pin 8, with a pullup resistor from
// 5v to data wire in addition.
// Details & link to library, and example code adapted from:
// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain
// http://learn.adafruit.com/dht
#include <LiquidCrystal.h>
#include "DHT.h"
#define DHTPIN 8 // what pin we're connected to
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //Pins for the LCD display, as taken from arduino.cc
// Uncomment whatever type you're using!
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
DHT dht(DHTPIN, DHTTYPE);
void setup() {
//Serial.begin(9600);
dht.begin();
lcd.begin(16, 2);
}
void loop() {
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
float t = dht.readTemperature();
t = t* 9/5 + 32;
// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t) || isnan(h)) {
lcd.setCursor(0, 0);
lcd.print("Failed to read from DHT");
//Serial.println("Failed to read from DHT");
} else {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Humidity: ");
lcd.print(h);
lcd.print("%");
lcd.setCursor(0, 1);
lcd.print("Temp: ");
lcd.print(t);
lcd.print("f");
//Serial.print("Humidity: ");
//Serial.print(h);
//Serial.print(" %\t");
//Serial.print("Temperature: ");
//Serial.print(t);
//Serial.println(" *C");
}
}
ขอบคุณ คุณ ritichai มาก ๆ ครับที่ช่วยแชร์โคด
เริ่มจาก clip ที่ผมทำให้ดู
แล้วทำตามที่คุณ ritichai แนะนำเลยครับ
ทำไมของผมเป็นตัวหนังสือภาษาไทย อ่ามั่วไปหมด