[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 | 閱讀: 6249 | 轉發
안전놀이터추천 [ 2023-05-13 16:59 網址 | 回覆 | 編輯/刪除 ]
I finally found what I was looking for! I'm so happy. 안전놀이터추천 Your article is what I've been looking for for a long time. I'm happy to find you like this. Could you visit my website if you have time? I'm sure you'll find a post of interest that you'll find interesting.
sanskarishwetamalik [ 2024-01-08 20:09 | 回覆 | 編輯/刪除 ]
Send any whatsapp Pune Call Girl a message that you have seen their photo call girl Pune online and want to have sex in Pune with them. We make sure that whichever kinky call girl in Delhi you contact for phone sex, you should pay her through us.
soniya singhania [ 2024-01-24 13:12 | 回覆 | 編輯/刪除 ]
We bring you reliable Goa Escorts to make your intimate and nightclub fantasies come true in a secure and confidential manner. So don’t worry you are now at a reputed online escort service website in Goa. Escorts in Goa counted amongst the most trusted organizations in Goa. Our operators will guide you on the safe and right way to meet a trusted escort.
Neha Dutt [ 2024-02-03 15:30 | 回覆 | 編輯/刪除 ]
Our agency “Luxury Escort Services” is the ultimate destination where all ranges of attractive beautiful luxury models are available to attend your special love desires. Goa Escort Service, it is not just they are in this profession to meet your sexual needs, but they are also trained to accompany you to any business event as well.
Swarna Yadav [ 2024-02-03 15:41 | 回覆 | 編輯/刪除 ]
Our agency is popular for bringing some of the best luxury Call Girl in Chandigarh for fun and excitement. Come on men; get ready to show your love & passion to your companion now! Throughout the city, ‘Luxury Escorts Services is one of the highly rated escort service providers and also proud to serve premium quality services to our clients.
Malika [ 2024-02-16 17:47 | 回覆 | 編輯/刪除 ]
Majority of the sex-deprived, lonely or sex-crazy men will admit of not interacting with the right hot chicks. It results in an unsatisfactory type of sexual time with the so-called hot babe. Just wearing a sexy dress and make-up does not qualify you of a perfectionist type of sexy Escorts in Agonda Beach .
goabeauties [ 2024-02-17 17:43 | 回覆 | 編輯/刪除 ]
Get ready to have Goa female escorts take you on a journey of sheer gratification, a journey full of love and lust to break the monotony of your boring life by filling it with hot sexual activities.
Escorts in Fatorpa
Arambol Beach Escorts Service
Siolim Call Girls
Call Girls in Valpoi
Betul Escorts
Jiamalik [ 2024-04-04 18:54 | 回覆 | 編輯/刪除 ]
Possibly a good escort will present herself, but what if your attraction to her outweighs your comfort with her work ethic? You've probably been dealing with this for quite some time. Good Escorts in Maidens Hotel New Delhi are recognised for their personalities rather than their filthiness. If you are happy with the service provided, you will either feel better or get your money back. Although many agencies take great care to ensure that their escorts are attractive, we regret to inform you that you will not be able to tell whether or not someone provided a satisfactory service without first consulting with us.
Ruby Rajput [ 2024-05-14 21:25 | 回覆 | 編輯/刪除 ]
They're essential if you want to have fun and avoid local quirks. It's a dream come true for VIP Escort in Mohali to have a close, satisfying relationship with an erogenous nut they get to work with. Experts in the field of performing romantic bed postures with a partner to the complete delight of both partners should be sought out. Take a look at your adult friends' spectacular inflatables or mistakes and store away some unforgettable moments.
發表評論
暱 稱(*): 密 碼:
網 址: E - mail:
驗證碼(*): 驗證碼圖片 選 項:
頭 像:
內 容(*):