[DIY] 智慧家庭氣象觀測站

 多數人都有這樣的困擾,家人白天上班的上班,上課的上課,NAS 24hr 運作,寵物在家獨守空房,沒人可以即時因應氣溫的變化,因此很久以前就有個念頭,希望可以記錄家裡的環境變化甚至可以遠端了解目前狀況。這幾年拜 IOT 科技所賜,這方面的工具也逐漸推出,只是市面產品功能及穩定性參差不齊,也怕買到地雷,還不如依自身的需求自己 DIY 實作看看,功能還可以逐步擴充,重點是價格低廉實惠,庶民百姓都玩得起。


http://digiland.tw/uploads/3_dht11_03.jpg

這樣的需求,首選的工具當然就是用 Arduino 來擔綱囉,以下是演員陣容: 
▼ 主要控制板 Arduino UNO。
http://digiland.tw/uploads/3_dht11_10.jpg

▼ 溫溼度偵測元件 DHT11。
http://digiland.tw/uploads/3_dht11_14.jpg

▼ 因為只要顯示溫溼度等資訊,所以 LCD 選擇便宜的 1602 就足夠使用。
http://digiland.tw/uploads/3_dht11_12.jpg

▼ 這是LCD背面接腳,會選擇 I2C 是因為只要 4 條杜邦線就可以完成連接。
http://digiland.tw/uploads/3_dht11_13.jpg

▼ 如果想要能透過網路連線查詢即時狀態,則需要再加一張 W5100 Ethernet 擴充板。
http://digiland.tw/uploads/3_dht11_11.jpg

▼ 所有演員大集合,準備開工拜拜。
http://digiland.tw/uploads/3_dht11_09.jpg

單機版家庭氣象觀測站
▼ 單機板家庭氣象站接線圖,第一次畫不太熟練,找不到 DHT11 元件 拿 RHT03 充當orz
http://digiland.tw/uploads/3_dht11_15.jpg

▼ 實際接線圖,接得有點混亂,請多包涵jolin
http://digiland.tw/uploads/3_dht11_02.jpg

▼ 單機版程式碼

#include <LiquidCrystal_I2C.h> #include <dht11.h> #include <Wire.h> LiquidCrystal_I2C lcd(0x27, 16, 2); dht11 DHT11; const byte dataPin = 2; void setup() { // put your setup code here, to run once: lcd.init(); lcd.backlight(); } void loop() { // put your main code here, to run repeatedly: int chk = DHT11.read(dataPin); if(chk == 0) { lcd.setCursor(4,0); lcd.print("Temp"); lcd.setCursor(0,1); lcd.print("Humidity"); lcd.setCursor(9,0); lcd.print((float)DHT11.temperature, 2); lcd.print((char) 0xDF); lcd.print("C"); lcd.setCursor(9,1); lcd.print((float)DHT11.humidity, 2); lcd.print("%"); } else { lcd.clear(); lcd.print("Error code:"); lcd.print(chk); } delay(5000); }


▼ 開機後,會將 DHT11 偵測出來的溫溼度數據顯示在 LCD 畫面
http://digiland.tw/uploads/3_dht11_03.jpg

網路版家庭氣象觀測站
單機板似乎只能單機作業眼見為憑,還不如加上網路功能,讓遠端也能透過網路監看家裡的溫溼度狀況,所以以前述的單機板為基礎,我們再加上一片 W5100 Ethernet 擴充板,即可升級為網路版家庭氣象站。

▼ 在 Arduino UNO 上再堆疊一片 W5100,即可擁有網路版的功能。
http://digiland.tw/uploads/3_dht11_05.jpg

▼ 網路版程式碼

#include <LiquidCrystal_I2C.h> #include <dht11.h> #include <Wire.h> #include <SPI.h> #include <Ethernet.h> LiquidCrystal_I2C lcd(0x27, 16, 2); byte mac[] = { 0xF0, 0x7B, 0xCB, 0x4B, 0x7C, 0x9F }; dht11 DHT11; const byte dataPin = 2; EthernetServer server(80); void setup() { // put your setup code here, to run once: lcd.init(); lcd.backlight(); Ethernet.begin(mac); } void loop() { // put your main code here, to run repeatedly: char buffer[5] = ""; int chk = DHT11.read(dataPin); IPAddress ip = Ethernet.localIP(); EthernetClient client = server.available(); if (client) { while (client.connected()) { if (client.available()) { client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println(); client.println("<!doctype html>"); client.println("<html>"); client.println("<meta charset="utf-8" />"); client.println("<meta http-equiv='Refresh' CONTENT='30'>"); client.println("<title>智慧家庭氣象觀測站"); client.println("</head>"); client.print("溫度:"); client.print(dtostrf(DHT11.temperature, 5, 2, buffer)); client.print("°C<br>"); client.print("溼度:"); client.print(dtostrf(DHT11.humidity, 5, 2, buffer)); client.print("%"); client.println("</body>"); break; } } delay(1); client.stop(); } lcd.setCursor(0,0); lcd.print(ip); if(chk == 0) { lcd.setCursor(0,1); lcd.print(dtostrf(DHT11.temperature, 5, 2, buffer)); lcd.print((char) 0xDF); lcd.print("C"); lcd.setCursor(8,1); lcd.print(dtostrf(DHT11.humidity, 5, 2, buffer)); lcd.print("%"); } else { lcd.clear(); lcd.print("Error code:"); lcd.print(chk); } delay(5000); }


▼ 開機後,W5100 會啟動 DHCP 功能取得一組可用的 IP,並顯示在 LCD 上,第二列才會顯示目前的溫度及溼度。
http://digiland.tw/uploads/3_dht11_06.jpg

▼ 有了 IP,可以方便透過瀏覽器讀取目前的溫溼度狀態。
http://digiland.tw/uploads/3_dht11_07.jpg

▼ 透過 VPN 連線,甚至可以在辦公室遠端連線回來查看家裡的溫溼度資訊。
http://digiland.tw/uploads/3_dht11_08.jpg

後記
這樣的實作花費大概台幣 500 元上下就能擁有,程式碼也很簡單易學,後續可延伸的方向:1.透過 MRTG 功能可以定時記錄家裡溫溼度的變化。2.改成無線網路,讓偵測點不受限於網路線。3.增加繼電器,可以設定條件自動開啟或關閉家電,例如設定溫度達 25 度自動開啟電風扇,溼度達 80% 開啟除溼機等等,當然也可透過網路遠端控制開關。4.增加其他監控功能,例如瓦斯偵測、PM2.5偵測等等,這樣的 DIY 只要有創意就會有樂趣。

備註:為讓顯示順利,程式碼中的"<"字元皆使用全形符號,使用時請自行替換。

 
引用通告地址: 點擊獲取引用地址
評論: 39 | 引用: 0 | 閱讀: 6253 | 轉發
온라인카지노 [ 2022-12-30 10:23 網址 | 回覆 | 編輯/刪除 ]
I've been looking for photos and articles on this topic over the past few days due to a school assignment, 온라인카지노 and I'm really happy to find a post with the material I was looking for! I bookmark and will come often! Thanks :D
custom packaging boxes u [ 2023-01-07 21:51 網址 | 回覆 | 編輯/刪除 ]
You have performed a great job on this article <a href="https://qpack.co.uk/">custom packaging boxes</a>
custom packaging boxes u [ 2023-01-07 21:53 網址 | 回覆 | 編輯/刪除 ]
[url=https://qpack.co.uk/][custom packaging boxes/url]
Sarah [ 2023-02-05 00:16 網址 | 回覆 | 編輯/刪除 ]
https://www.airmax720.us.org/
https://www.ringspandora.us/
https://www.wholesalejordansfactory.us/
https://www.jordan-12.us.org/
https://www.nikeair-force1.us.org/
https://www.air-max2019.us.org/
https://www.jerseysstore.ca/
https://www.airjordan33.us/
https://www.pandorajewelryoutlets.us.com/
https://www.nikerunningshoesforwomen.us.com/
https://www.pandora-jewelry-charms.us/
https://www.pandorajewelryofficialsites.us/
https://www.jewelryspandora.us.com/
https://www.toddlerbabyinfantjordans.us/
https://www.jordans33.us/
https://www.nikeairmaxs-270.us.com/
https://www.nikecanadashoesshop.ca/
https://www.redbottomslouboutinshoes.us.org/
https://www.nike-outlets.us.com/
https://www.cheapjordanswholesalefreeshipping.us/
https
Rodolfo [ 2023-02-06 05:13 網址 | 回覆 | 編輯/刪除 ]
https://www.jacketsmoncleroutlet.us.com/
https://www.jordansretro12.us/
https://www.air-jordan1s.us.com/
https://www.nikesales.us.com/
https://www.outletnikestore.us.com/
https://www.monclercom.us.com/
https://www.jordan-shoesformen.us.com/
https://www.balenciagatriples.us.org/
https://www.nikeoutletfactorys.us.com/
https://www.jordansretro3.us/
https://www.louboutinshoesheels.us.com/
https://www.kyrieirving-shoes.us.org/
https://www.jordan11low.us.com/
https://www.fjallraven-kanken.us.com/
https://www.pandorasjewelry.us.com/
https://www.monclervest.us.com/
https://www.lebron-shoes.us.com/
https://www.nike--shoes.us.com/
https://www.nikeshoes-cheap.us.com/
https://www.nikeair-maxs.us.com/
https://www.canadapandoracharms.c
Parker [ 2023-02-06 12:16 網址 | 回覆 | 編輯/刪除 ]
https://www.jordanretro1.us.com/
https://www.outletasics.us.com/
https://www.monclerjacket.com.co/
https://www.airjordan1shoes.us.com/
https://www.pandorashop.us.com/
https://www.pandoras-charms.us.com/
https://www.balenciagastore.us.com/
https://www.ferragamosbelt.us.com/
https://www.adidassale.us.com/
https://www.goyardbagsoutlet.us.com/
https://www.jordanones.us/
https://www.nike--shoes.ca/
https://www.pandora-outletcharms.us.com/
https://www.balenciagasneakersoutlet.us.com/
https://www.pandora-jewellery.us.com/
https://www.adidass.ca/
https://www.wholesaleairjordanscheap.us/
https://www.adidasofficialwebsite.us.com/
https://www.airjordan1s.us.com/
https://www.monclersaleoutlets.us.com/
https://www.pandorajewelryshop.u
Darleen [ 2023-02-06 13:51 網址 | 回覆 | 編輯/刪除 ]
https://www.baseballjerseyscheap.us.com/
https://www.nhlhockeyjerseyswholesale.us.com/
https://www.nflproshops.com.co/
https://www.footballproshop.us.com/
https://www.mlbbaseballjerseys.us.org/
https://www.cheaphockeyjerseys.us.com/
https://www.cheap-jerseyswholesale.com.co/
https://www.jerseyscheapwholesalefromchina.us.com/
https://www.cheapfootballjerseysfromchina.us.com/
https://www.footballstore.us.com/
https://www.hockeyjerseyswholesale.us.com/
https://www.nhlstore.com.co/
https://www.nflfootballjerseys.com.co/
https://www.nfljerseysofficialshop.us/
https://www.basketballjerseyswholesale.us.com/
https://www.cheapnfljerseysfromchina.com.co/
https://www.cheapjerseysfromchinawholesale.com/
https://www.nbastores.com.co/
ht
Barbara [ 2023-02-07 06:11 網址 | 回覆 | 編輯/刪除 ]
https://www.nikeshoesstores.us.com/
https://www.nikeshoesformens.us.com/
https://www.kidsjordans.us/
https://www.nikerosheblazer.us.org/
https://www.airjordan33.us/
https://www.nhlshops.ca/
https://www.christianlouboutinshoess.us.com/
https://www.jordan21.us/
https://www.nikeair-force1.us.org/
https://www.jordans32.us/
https://www.pandorajewelryoutlets.us.com/
https://www.cheapjordansshoessale.us/
https://www.jordans33.us/
https://www.airmax-outlet.us.com/
https://www.nikeoutlet-store.us.org/
https://www.nikejordan1.us.com/
https://www.pandorasjewelrycharms.us/
https://www.cheapjordanshoessuppliers.us.org/
https://www.nikeoffwhite.us.org/
https://www.jordan35.us/
https://www.nikesoutletfactory.us.com/
https://www.officia
Santos [ 2023-02-08 19:57 網址 | 回覆 | 編輯/刪除 ]
https://www.yeezy500boost.us.com/
https://www.pandoras.uk.com/
https://www.nmdsadidas.us.com/
https://www.nike-onlinecanada.ca/
https://www.nike-outletfactory.us.com/
https://www.trainerssale.uk.com/
https://www.nikeshoesoutlets.us.com/
https://www.adidass.us.com/
https://www.adidas-superstars.us.com/
https://www.airforce1s.us.com/
https://www.pandoracharmsbracelets.us.com/
https://www.nike-rosherun.us.com/
https://www.adidasoutletstores.us.com/
https://www.nikesneakersstore.us.com/
https://www.yeezyshoesboost.us.com/
https://www.adidas-originalssuperstar.us.com/
https://www.nikepresto.us.org/
https://www.newtrainers.uk.com/
https://www.pandorascharms.uk.com/
https://www.nikesrunningshoes.us.com/
https://www.adidasyeezyof
發表評論
暱 稱(*): 密 碼:
網 址: E - mail:
驗證碼(*): 驗證碼圖片 選 項:
頭 像:
內 容(*):