作者:國立暨南國際大學光電碩士學位學程    施啟祥、蔡圳彬、邱文燦、蕭智仁、蘇泉瑋

指導教授:曹永忠 博士

創作發想

近年來節能成為重要課題,但實際上家裡用電情況往往是收到電費單後才知道,所以如何讓使用者馬上知道用電情況,進一步達到節約用電,為本次設計重點。

製作步驟

1. 系統架構圖

2. 實際安裝接線

3. 電路板

4.程式撰寫

// #include #include #include #include “wiring_watchdog.h” Adafruit_ADS1115 ads; // double sqI[4],sumI[4]; double sampleI[4]; double Irms[4]; uint8_t MacData[6]; int voltage[4]={110,110,110,110}; IPAddress Meip ,Megateway ,Mesubnet ; String MacAddress=”” ; char ssid[] = “NCNUIOT”; // your network SSID (name) char pass[] = “12345678”; // your network password int keyIndex = 0; // your network key Index number (needed only for WEP) int status = WL_IDLE_STATUS; char server[] = “192.168.99.200”; // name address for Google (using DNS) String connectstr ; String table_temp = “current”; WiFiClient client; double squareRoot(double fg) //開根號 { double n = fg / 2.0; double lstX = 0.0; while (n != lstX) { lstX = n; n = (n + fg / n) / 2.0; } return n; } void calcIrms(unsigned int Number_of_Samples, float multiplier,double ical) { int i; for (unsigned int n = 0; n < Number_of_Samples; n++) { for(i=0;i<=1;i++) { ads.convert_v1(0x48,i+1); ads.convert_v1(0x49,i+1); sampleI[0+i]=ads.read_v1(0x48); sampleI[2+i]=ads.read_v1(0x49); sqI[i] = sampleI[i] * sampleI[i]; sumI[i] += sqI[i]; sqI[2+i] = sampleI[2+i] * sampleI[2+i]; sumI[2+i] += sqI[2+i]; wdt_reset() ; } } for(i=0;i<=3;i++) { Irms[i] = squareRoot(sumI[i] / Number_of_Samples) * multiplier * ical/100 * 0.1875/1000; sumI[i] = 0; } //-------------------------------------------------------------------------------------- } void ShowMac() { Serial.print("MAC:"); Serial.print(MacAddress); Serial.print("\n"); } void printWifiStatus() { // print the SSID of the network you're attached to: Serial.print("SSID: "); Serial.println(WiFi.SSID()); // print your WiFi shield's IP address: IPAddress ip = WiFi.localIP(); Serial.print("IP Address: "); Serial.println(ip); // print the received signal strength: long rssi = WiFi.RSSI(); Serial.print("signal strength (RSSI):"); Serial.print(rssi); Serial.println(" dBm"); } String GetWifiMac() { String tt ; String t1,t2,t3,t4,t5,t6 ; WiFi.status(); //this method must be used for get MAC WiFi.macAddress(MacData); Serial.print("Mac:"); Serial.print(MacData[0],HEX) ; Serial.print("/"); Serial.print(MacData[1],HEX) ; Serial.print("/"); Serial.print(MacData[2],HEX) ; Serial.print("/"); Serial.print(MacData[3],HEX) ; Serial.print("/"); Serial.print(MacData[4],HEX) ; Serial.print("/"); Serial.print(MacData[5],HEX) ; Serial.print("~"); t1 = print2HEX((int)MacData[0]); t2 = print2HEX((int)MacData[1]); t3 = print2HEX((int)MacData[2]); t4 = print2HEX((int)MacData[3]); t5 = print2HEX((int)MacData[4]); t6 = print2HEX((int)MacData[5]); tt = (t1+t2+t3+t4+t5+t6) ; Serial.print(tt); Serial.print("\n"); return tt ; } String print2HEX(int number) { String ttt ; if (number >= 0 && number < 16) { ttt = String("0") + String(number,HEX); } else { ttt = String(number,HEX); } return ttt ; } void setup() /*----( SETUP: RUNS ONCE )----*/ { wdt_enable(8000); Wire.begin(); /* ADS1115 @ +/- 4.096V gain (16-bit results) 0.125mV Step*/ ads.setGain(GAIN_ONE); ads.begin(); Serial.println(); Serial.println("current meter"); MacAddress = GetWifiMac() ; // get MacAddress ShowMac() ; //Show Mac Address Serial.begin(9600); // check for the presence of the shield: if (WiFi.status() == WL_NO_SHIELD) { Serial.println("WiFi shield not present"); // don't continue: while (true); } String fv = WiFi.firmwareVersion(); if (fv != "1.1.0") { Serial.println("Please upgrade the firmware"); } // attempt to connect to Wifi network: while (status != WL_CONNECTED) { Serial.print("Attempting to connect to SSID: "); Serial.println(ssid); // Connect to WPA/WPA2 network. Change this line if using open or WEP network: status = WiFi.begin(ssid,pass); wdt_reset(); // wait 10 seconds for connection: delay(5000); } status = WL_IDLE_STATUS; Serial.println("Connected to wifi"); printWifiStatus(); }// END Setup static int count=0; void loop() { wdt_reset(); if(WiFi.status() != WL_CONNECTED) { while (status != WL_CONNECTED) { Serial.print("Attempting to connect to SSID: "); Serial.println(ssid); // Connect to WPA/WPA2 network. Change this line if using open or WEP network: status = WiFi.begin(ssid,pass); wdt_reset(); // wait 10 seconds for connection: delay(5000); } status = WL_IDLE_STATUS; digitalWrite(6,HIGH); } connectstr = "" ; calcIrms(3840, 0.125F,9.6); // wdt_reset(); wdt_disable(); connectstr = "?mac="+MacAddress+"&v=" + String(voltage[1])+"&c="+String(Irms[1])+"&w="+String(Irms[1]*voltage[1]); if (client.connect(server,80)) { // REPLACE WITH YOUR SERVER ADDRESS client.print("POST /iot/power/poweradd.php"); client.print(connectstr); client.println(" HTTP/1.1"); Serial.print(connectstr); client.print("Host:"); // SERVER ADDRESS HERE TOO client.println(server); // SERVER ADDRESS HERE TOO client.println("Content-Type: application/x-www-form-urlencoded"); client.print("Content-Length: "); client.println(connectstr.length()); client.println(); client.print(connectstr); // Serial.print(connectstr); if (client.connected()) { client.stop(); // DISCONNECT FROM THE SERVER delay(30); } wdt_enable(8000); } } // END Loop

5. 電流變化測試

6. 檢測資料

7.電器耗電表

成果影片

結語

未來我們期待能夠整合燈光、空調、影音、電器、監視等,輕鬆地操作家用設備,及電器電能管理。

(本文經同意轉載自Project Plus原文連結;責任編輯:林亮潔)

Related Posts

【代表學校】 嘉義縣竹崎高中 【團隊名稱】 遠的要命王國 【作品簡介】 ...
林 亮潔
2020 年 7 月 9 日
創作發想 運動娛樂類型遊戲以為飛行、射擊、拳擊、跑步為主,為了讓搖桿具備這些類型體感操控,「UControl ...
makerpro
2020 年 7 月 2 日
林 亮潔
2020 年 7 月 2 日