本帖最後由 f1226 於 2019-2-19 10:03 編輯
1、目前使用DT-11、FC-37兩種元件組合打算針對機房做漏水偵測和溫度警示控管
2、從網路上找了兩種元件的程式組合也運行完成(如下圖)
3、FC-37的部分修改容易沒什問題,但是DT-11修改的時候遭遇問題,能否指導我如何將DT-11的偵測結果改為類似FC-37的內容?
例:"目前溫度低於40度,正常"、"目前溫度高於40度,小於45度,請注意"、"目前溫度高於49度,請立即查看"
4、目前程式內容如下:
// Written by ladyada, public domain
// lowest and highest sensor readings:
const int sensorMin = 0; // sensor minimum
const int sensorMax = 1024; // sensor maximum
// 导入头文件
#include "DHT.h"
// 定义OUT接口的数字引脚
#define DHTPIN 2 // what digital pin we're connected to
// Uncomment whatever type you're using!
// 选择DHT类型为 DHT 11
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 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
// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors. This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
// 生成 DHT 对象,参数是PIN和DHT类型
DHT dht(DHTPIN, DHTTYPE);
void setup() {
// initialize serial communication @ 9600 baud:
Serial.begin(9600);
Serial.println("DHTxx test!");
// 必须使用的begin()函数
dht.begin();
}
void loop() {
// read the sensor on analog A0:
int sensorReading = analogRead(A0);
// map the sensor range (four options):
// ex: 'long int map(long int, long int, long int, long int, long int)'
int range = map(sensorReading, sensorMin, sensorMax, 0, 3);
// range value:
switch (range) {
case 0: // Sensor getting wet
Serial.println("機房幹管破裂,請立即回大樓查看!!");
break;
case 1: // Sensor getting wet
Serial.println("機房幹管可能滲漏或誤報,請提高警覺或查看");
break;
case 2: // Sensor dry - To shut this up delete the " Serial.println("Not Raining"); " below.
Serial.println("機房幹管正常,無滲漏");
break;
}
delay(5000); // delay between reads
// Wait a few seconds between measurements.
// 每次等待2秒后再输出(必须等、大于1秒,1秒等於1000)
delay(5000);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
// readHumidity() 这里是读取当前的湿度
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
// readTemperature() 读取当前的温度,单位C
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
//readTemperature(true) 读取当前的温度,单位F
float f = dht.readTemperature(true);
// 如果读取失败则退出,再读取一次
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("自DHT sensor讀取數值失敗!");
return;
}
// Compute heat index in Fahrenheit (the default)
// 读取体感温度,单位F
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
// 读取体感温度,单位C
float hic = dht.computeHeatIndex(t, h, false);
Serial.print("空氣濕度: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("溫度: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(f);
Serial.print(" *F\t");
Serial.print("酷熱指數: ");
Serial.print(hic);
Serial.print(" *C ");
Serial.print(hif);
Serial.println(" *F");
}
/* Flame Sensor analog example.
- If the Sensor Board is completely soaked; "case 0" will be activated and " Flood " will be sent to the serial monitor.
- If the Sensor Board has water droplets on it; "case 1" will be activated and " Rain Warning " will be sent to the serial monitor.
- If the Sensor Board is dry; "case 2" will be activated and " Not Raining " will be sent to the serial monitor.
*/
5、麻煩前輩給新手指導,謝謝!! |