[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 | 閱讀: 6247 | 轉發
Robert [ 2023-02-18 05:41 網址 | 回覆 | 編輯/刪除 ]
https://www.jordan32shoes.us/
https://www.nikeoutletonline-store.us.com/
https://www.cheapnikesshoes.us.com/
https://www.pandoracanadajewelrycharms.ca/
https://www.nikeairmax720.us.com/
https://www.nikeair-max270.us/
https://www.nikeshoesonlines.us.com/
https://www.nikeshoesclearance.us.com/
https://www.nikeshoesshop.us.com/
https://www.jordans13retro.us/
https://www.asicsshoesoutlet.us.com/
https://www.jordanaj1.us.com/
https://www.jordan-retro4.us.com/
https://www.outletstoreonlineshopping.us/
https://www.nikehuaraches.us.com/
https://www.yeezy500.us.org/
https://www.nikebasketball-shoes.us.com/
https://www.lebron16shoes.us/
https://www.nikeoutlet-factory.us.com/
https://www.nikeoutletstoreonline-shopping.us.com/
https:
Holder [ 2023-02-18 23:43 網址 | 回覆 | 編輯/刪除 ]
https://www.nfljerseysofficialshop.us/
https://www.hockeyjerseyscheap.us/
https://www.nhljerseyscheapwholesale.us.com/
https://www.baseballjerseyswholesale.us/
https://www.newfootballjerseys.us.com/
https://www.bestnfljerseyscheap.us.com/
https://www.nflgearuniforms.us/
https://www.wholesalecheapjerseysshop.com.co/
https://www.wholesalecheapjerseysfromchina.us/
https://www.baseballjerseyscheap.us.com/
https://www.footballstore.us.com/
https://www.nhlstore.com.co/
https://www.nbashop.us.org/
https://www.nhlhockeyjerseyswholesale.us.com/
https://www.basketballjerseyscheapwholesale.us.com/
https://www.nfljerseyscheap.com.co/
https://www.cheapbaseballjerseyswholesale.us.com/
https://www.jerseyscheapwholesalefromchina.us.com/
ht
Katina [ 2023-02-19 07:24 網址 | 回覆 | 編輯/刪除 ]
https://www.jamesharden-shoes.us.org/
https://www.jordan-shoesformen.us.com/
https://www.airmax270.us.org/
https://www.jordansshoesforsale.us.com/
https://www.vanscom.us.com/
https://www.jordan1universityblue.us.com/
https://www.christianslouboutinshoes.us.com/
https://www.jordans-sneakers.us.com/
https://www.jordan-4.us.com/
https://www.jordan13.us.org/
https://www.jordan-retro6.us/
https://www.yeezys-shoes.us.org/
https://www.huarachesnike.us.com/
https://www.jordan11low.us.com/
https://www.redbottomshoeslouboutin.us.com/
https://www.nmds.us.com/
https://www.jordanretro-11.us.com/
https://www.goldengoosessneakers.us.com/
https://www.jordan13s.us/
https://www.redbottomslouboutin.us.org/
https://www.nikeairjordan.us.com/
Anthony [ 2023-02-23 04:12 網址 | 回覆 | 編輯/刪除 ]
https://www.air-jordan8.us.com/
https://www.ferragamosshoes.us.com/
https://www.jordanshoesforkids.us/
https://www.fjallravenbackpack.us/
https://www.pandoracom.ca/
https://www.nikeoutletstores.us.org/
https://www.nikeair-max.us.org/
https://www.shoesyeezy.us.com/
https://www.sneakerswebsite.us/
https://www.jordan7.us.com/
https://www.nikeoutletstoreonlines.us.com/
https://www.air-jordansretro.us.com/
https://www.airmax2019.us.org/
https://www.nikeshoescybermondayblackfriday.us.com/
https://www.christianlouboutins.uk.com/
https://www.yeezysboosts.us.com/
https://www.nikefreernrun.us.com/
https://www.pandorasjewelryoutlet.us.com/
https://www.kyrieirvingbasketballshoes.us.com/
https://www.nikeair-jordan.us.com/
https://www.
Parker [ 2023-02-24 18:32 網址 | 回覆 | 編輯/刪除 ]
https://www.nhlstore.com.co/
https://www.nbastores.com.co/
https://www.nflfootballjerseys.com.co/
https://www.cheapfootballjerseysfromchina.us.com/
https://www.nflgearuniforms.us/
https://www.jerseyscheap.com.co/
https://www.cheapjerseysfromchinawholesale.com/
https://www.nflstoreonlineshopping.us/
https://www.cheap-nfljerseys.com.co/
https://www.mlbbaseballjerseyscheap.us.com/
https://www.cheapnfljerseyswholesale.com.co/
https://www.cheapbaseballjerseyswholesale.us.com/
https://www.baseballjerseyscheapwholesale.us.com/
https://www.cheap-jerseyswholesale.com.co/
https://www.cheapwholesalejerseys.com.co/
https://www.jerseyswholesale.com.co/
https://www.nhljerseyscheapwholesale.us.com/
https://www.nflfanshop.us.com/
https://w
Maria [ 2023-02-28 07:47 網址 | 回覆 | 編輯/刪除 ]
https://www.nflfootballjerseys.com.co/
https://www.nfl-shop.com.co/
https://www.basketballjerseyswholesale.us.com/
https://www.nflgearuniforms.us/
https://www.nhlstore.com.co/
https://www.nhljerseysforcheap.us.com/
https://www.jerseyscheap.com.co/
https://www.nbashop.us.org/
https://www.officialbaseballjerseys.us.com/
https://www.footballproshop.us.com/
https://jerseysforcheapwholesale.us.com/
https://www.cheaphockeyjerseys.us.com/
https://www.cheapjerseyssale.us.org/
https://www.footballjerseys.com.co/
https://www.baseballjerseyssale.us.com/
https://www.baseballjerseyscheap.us.com/
https://www.nflproshops.com.co/
https://www.jerseysforcheapwholesale.us/
https://www.mlbshops.com.co/
https://www.cheapestjerseysfromchinafact
Barbara [ 2023-03-10 13:07 網址 | 回覆 | 編輯/刪除 ]
https://www.jordans11.us.com/
https://www.nikeairmax98.us/
https://www.retro-jordans.us/
https://www.nmds.us.com/
https://www.canadapandoracharms.ca/
https://www.jordan1universityblue.us.com/
https://www.air-jordans11.us.com/
https://www.jordans-sneakers.us.com/
https://www.nike-jordans.us.com/
https://www.goldengoosemidstar.us.com/
https://www.airjordan6rings.us/
https://www.monclerstores.us.com/
https://www.nikeair-jordan1.us.com/
https://www.airforceoneshoes.us.com/
https://www.fitflop-shoes.us.org/
https://www.pandorascharms.us.com/
https://www.jordan1.us.com/
https://www.airjordan4s.us/
https://www.nikefactoryoutlets.us.org/
https://www.pandoraonline.us/
https://www.air-jordanssneakers.us/
https://www.nikeoutletfact
Sarah [ 2023-03-14 02:36 網址 | 回覆 | 編輯/刪除 ]
https://www.nikeair-jordan1.us.com/
https://www.airjordan5.us/
https://www.jordan10.us.com/
https://www.fjallraven-kanken.us.com/
https://www.jordan12retros.us/
https://www.jordan-12.us.com/
https://www.retrosjordans.us/
https://www.goldengooseshoess.us.com/
https://www.birkin-bag.us.com/
https://www.jordanretro-11.us.com/
https://www.new-jordans.us.com/
https://www.ggdbs.us.com/
https://www.nikeoutletshoes.us.com/
https://www.pandorascharms.us.com/
https://www.balenciagatriples.us.org/
https://www.jordan9.us.com/
https://www.balenciagaofficial.us.com/
https://www.pandorasjewelry.us.com/
https://www.airjordansneakers.us.com/
https://www.pandoras.us.com/
https://www.airmax270s.us.com/
https://www.christian-louboutinheels.
Lisa [ 2023-03-16 23:19 網址 | 回覆 | 編輯/刪除 ]
https://www.outletgoldengoose.us.com/
https://www.jordanshoess.us.com/
https://www.nikesoutletstoreonlineshopping.us.com/
https://www.nike-airmax2018.us.com/
https://www.adidasnmdr1.us.org/
https://www.redbottomshoeslouboutin.us.com/
https://www.newjordansshoes.us.com/
https://www.jordans-11.us/
https://www.nikeofficialwebsite.us.com/
https://www.outletnikestore.us.com/
https://www.air-jordan4.us.com/
https://www.pandorajewelryofficial-site.us/
https://www.pandorascharms.us.com/
https://www.nikeairmax-shoes.us.com/
https://www.nike--shoes.us.com/
https://www.nikesales.us.com/
https://www.nikeairjordan.us.com/
https://www.jamesharden-shoes.us.org/
https://www.airjordan4s.us/
https://www.jordan1lows.us.com/
https://www.monc
Sarah [ 2023-03-22 14:08 網址 | 回覆 | 編輯/刪除 ]
https://www.yeezyonline.us.com/
https://www.jordans-sneakers.us.com/
https://www.nikesoutletstoreonlineshopping.us.com/
https://www.airmax270.us.org/
https://www.jordans1s.us.com/
https://www.jordanshoess.us.com/
https://www.goldengooseshoess.us.com/
https://www.birkin-bag.us.com/
https://www.jordan-4.us.com/
https://www.jordan-12.us.com/
https://www.air-jordan6.us/
https://www.jordanretros.us.com/
https://www.jordan13s.us/
https://www.nikeoutletstoresonlineshopping.us.com/
https://www.airjordan4s.us/
https://www.yeezys-shoes.us.com/
https://www.vanscom.us.com/
https://www.jordansneakerss.us/
https://www.redbottomshoesforwomen.us.com/
https://www.redbottomshoeslouboutin.us.com/
https://www.huarachesnike.us.com/
https://w
發表評論
暱 稱(*): 密 碼:
網 址: E - mail:
驗證碼(*): 驗證碼圖片 選 項:
頭 像:
內 容(*):