ผมอยากได้โคดที่รับค่ามาจากตัวdht22มาเก็บใว้ในตัวแปรtหรือh อะครับ
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#define DHTPIN 2 // Digital pin connected to the DHT sensor
// Feather HUZZAH ESP8266 note: use pins 3, 4, 5, 12, 13 or 14 --
// Pin 15 can work but DHT must be disconnected during program upload.
// Uncomment the type of sensor in use:
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
// See guide for details on sensor wiring and usage:
// https://learn.adafruit.com/dht/overview
DHT_Unified dht(DHTPIN, DHTTYPE);
float t;
float h;
uint32_t delayMS;
void setup() {
Serial.begin(9600);
// Initialize device.
dht.begin();
Serial.println(F("DHTxx Unified Sensor Example"));
// Print temperature sensor details.
sensor_t sensor;
dht.temperature().getSensor(&sensor);
Serial.println(F("------------------------------------"));
Serial.println(F("Temperature Sensor"));
Serial.print (F("Sensor Type: ")); Serial.println(sensor.name);
Serial.print (F("Driver Ver: ")); Serial.println(sensor.version);
Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id);
Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F("°C"));
Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F("°C"));
Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F("°C"));
Serial.println(F("------------------------------------"));
// Print humidity sensor details.
dht.humidity().getSensor(&sensor);
Serial.println(F("Humidity Sensor"));
Serial.print (F("Sensor Type: ")); Serial.println(sensor.name);
Serial.print (F("Driver Ver: ")); Serial.println(sensor.version);
Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id);
Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F("%"));
Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F("%"));
Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F("%"));
Serial.println(F("------------------------------------"));
// Set delay between sensor readings based on sensor details.
delayMS = sensor.min_delay / 1000;
}
void loop() {
// Delay between measurements.
delay(delayMS);
// Get temperature event and print its value.
sensors_event_t event;
dht.temperature().getEvent(&event);
if (isnan(event.temperature)) {
Serial.println(F("Error reading temperature!"));
}
else {
t = event.temperature;
Serial.print(F("Temperature: "));
Serial.print(t);
Serial.println(F("°C"));
}
// Get humidity event and print its value.
dht.humidity().getEvent(&event);
if (isnan(event.relative_humidity)) {
Serial.println(F("Error reading humidity!"));
}
else {
h = event.relative_humidity;
Serial.print(F("Humidity: "));
Serial.print(h);
Serial.println(F("%"));
}
}
1 Like
โคดแบบไหนคับพี่
มันคืออะไรหรอคับ
17:55:34.491 -> [12118] Connecting to oasiskit.com:8080
17:55:39.516 -> [17119] Connecting to :8080
17:55:44.502 -> [22122] Connecting to :8080
17:55:49.508 -> [27123] Connecting to :8080
17:55:54.526 -> [32124] Connecting to :8080
17:55:59.497 -> [37125] Connecting to :8080
17:56:04.511 -> [42126] Connecting to :8080
17:56:09.498 -> [47127] Connecting to :8080
17:56:14.524 -> [52128] Connecting to :8080
17:56:19.523 -> [57129] Connecting to :8080
17:56:24.530 -> [62130] Connecting to :8080
หายแล้วคับ ติดไฟล์วอล เครื่อง wifi ปิดติดไฟล์วอล หาย
1 Like
ใช้คอมปล่อย Wifi หรอครับ
ไม่ครับแต่เครื่องwifiผมมันมีไฟล์วอลด้วยครับต้องเข้าไปตั้งค่า