內部使用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));
}

沒有留言:
張貼留言