2016年8月2日 星期二

自製溫度計

這個溫度計當初是在做太陽能熱風時要量測出風口溫度時做的,別看錯了,這不是Sony做的,慈濟太多塑膠難以處理,其實把一些變壓器外殼拆下來當DIY裝置的包裝挺好用的。這幾年只要想要量溫度立刻想到它,大概是目前所做最實用的裝置。其實也可以改成用二個較精密的DHT-22,擺在窗戶邊,它就變成一個室內外溫度、濕度顯示計了。



內部使用Arduino pro mini 接一顆 DHT11可量室溫及濕度,外接 DS18B20 量測溫度範圍   -55C to 125C ,日常生活使用已經很足夠了。程式很簡單,把溫度量出來然後顯示出來,使用USB
電源也容易取得。


#include <OneWire.h>
#include <DallasTemperature.h>
#include <dht.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#define ONE_WIRE_BUS 10
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);    // Pass our oneWire reference to Dallas Temperature.
LiquidCrystal_I2C lcd(0x27,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display
dht DHT;
#define DHT_Pin A1 //LC I2C use A4 & A5

void setup()
{
//  Serial.begin(9600);
//  Serial.println("Solar hot air");
  sensors.begin(); // IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay giving the IC more time to process the temperature measurement
  lcd.init();
  lcd.noBacklight();
  lcd.setCursor(0,0);
  lcd.print("Solar hot air");
  delay(3000);
}
void loop()
{
  DHT.read11(DHT_Pin);
  sensors.requestTemperatures(); // Send the command to get temperatures
/*  Serial.print("Temperature for Device 1 is: ");
  Serial.print(DHT.temperature);
  Serial.print("      ");
  Serial.println(sensors.getTempCByIndex(0));  // You can have more than one IC on the same bus. 0 refers to the first IC on the wire
*/
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Ti:");  lcd.print(DHT.temperature);
  lcd.print(" RH:");  lcd.print(DHT.humidity);
  lcd.setCursor(0,1);
  lcd.print("To:");  lcd.print(sensors.getTempCByIndex(0));

}





沒有留言: