ความรู้แน่น ฟรีสำหรับชุมชน ArduinoAll ที่นี่เท่านั้น

ฟรีและดีที่สุด คอร์สอบรม Arduino + NodeMCU
ทำเพื่อแบ่งปัน ห้ามนำไปจำหน่าย หรือเก็บเงินค่าเรียน
  !!!


  


AllNewStep รับประกันคุณภาพทุกชิ้น วันจันทร์-ศุกร์แจ้งชำระสินค้าก่อน 14.00 จัดส่งทันทีวันนี้ค่ะ

กรุงเทพ /ภาคกลาง ได้พรุ่งนี้


*** สินค้าทุกชิ้น ถ้าสามารถทำรายการสั่งซื้อได้ แสดงว่ามีครบทุกรายการค่ะ *** 

พิมพ์ค้นหาบทความ หัวข้อกระทู้ และสินค้าในเว็บ AllNewStep ได้ที่นี่
QUOTE 

DHT22 ส่งค่า "1" ตลอด

Pound111

ใช้ Arduino mega 2560 กับ DHT22,sound detector
เพื่อแสดงค่าออก TFT LCD3.5" ครับ

แต่ DHT22 ส่งค่า Temp เป็น 1 ตลอด
ส่วนค่า Humid ส่งค่าเป็น 1 หรือ 2-3 บ้าง บางเวลา

ต้องแก้ตรงไหนครับ

#include <MCUFRIEND_kbv.h>
#include <Adafruit_GFX.h> // Core graphics library
#include "DHT.h"

DHT dht;


#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0

// Assign human-readable names to some common 16-bit color values:

#define WHITE 0x0000
#define BLACK 0xFFFF
#define YELLOW 0x001F
#define SKY 0xF800
#define PURPLE 0x07E0
#define RED 0x07FF
#define GREEN 0xF81F
#define BLUE 0xFFE0


MCUFRIEND_kbv tft;
int x = 1;
int sensorPin = A7;
float sensorValue = 0.0;


void setup(void) {
Serial.begin(9600);
Serial.println(F("TFT LCD test"));

tft.reset();
uint16_t identifier = tft.readID();
tft.begin(identifier);
tft.setRotation(1);

dht.setup(23); // data pin 23
}

void loop(void) {
delay(dht.getMinimumSamplingPeriod());


float humidity = dht.getHumidity();
float temperature = dht.getTemperature();

//float humidity = 60;
//float temperature = 30;
sensorValue = analogRead(sensorPin);

sensorValue = 0.25*sensorValue;
sensorValue = sensorValue+46;
//Serial.println(sensorValue);
//Serial.println(temperature);
//Serial.println(humidity);

if(x==4){
x=1;
}

tft.fillScreen(BLACK);
unsigned long start = micros();
tft.setCursor(0, 0);

if(x==1){
if(sensorValue < 80.0 || sensorValue == 80.0){
tft.setTextColor(GREEN);
}
if(sensorValue > 80.0 && sensorValue < 85.0){
tft.setTextColor(YELLOW);
}
if(sensorValue > 85.0 || sensorValue == 85.0){
tft.setTextColor(RED);
}
tft.setTextSize(8);
tft.println(" ");
tft.println("SOUND(dB)");
tft.setTextSize(4);
tft.println(" ");
tft.setTextSize(12);
tft.println(sensorValue);
}


if(x==2){
if(temperature < 30.0 || temperature == 30.0){
tft.setTextColor(GREEN);
}
if(temperature > 30.0 && temperature < 34.0){
tft.setTextColor(YELLOW);
}
if(temperature > 34.0 || temperature == 34.0){
tft.setTextColor(RED);
}
tft.setTextSize(8);
tft.println(" ");
tft.println(" TEMP(C)");
tft.setTextSize(4);
tft.println(" ");
tft.setTextSize(12);
tft.println(temperature);
}


if(x==3){
if(humidity < 67.0 || humidity == 67.0){
tft.setTextColor(GREEN);
}
if(humidity > 67.0){
tft.setTextColor(YELLOW);
}
tft.setTextSize(8);
tft.println(" ");
tft.println(" HUMID(%)");
tft.setTextSize(4);
tft.println(" ");
tft.setTextSize(12);
tft.println(humidity);
}


x = x+1;
delay(3000);
}

QUOTE 
ความคิดเห็นที่ #1
Pound111

QUOTE 
ความคิดเห็นที่ #2
เจ้าของร้าน

ใช้ไลบารีตัวนี้ ใช้ได้ทันทีครับ

https://www.arduinoall.net/arduino-tutor/download/DHT.zip

แสดงความคิดเห็นที่ 1-2 จากทั้งหมด 2 ความคิดเห็น
ขาย ARDUINO
คุณภาพ อันดับ 1

ได้รับรางวัลร้านยอดเยี่ยม
ตั้งแต่ปี 2558
ขาย Arduino
วีดีโอสอน Arduino

สอน esp8266

สอน Arduino IoT
สอน Arduino แบบเร็ว

สอน NodeMCU

อุปกรณ์ Arduino

MEMBER ZONE

พูดคุย-สอบถาม