【Ameba】智慧型防盜鎖

Description

Description
指導教授:曹永忠 博士 
作者:第三組 許聖國、謝政倫、賴宜鴻、謝耿順、林奇伯

創作發想

鎖是一類現代化社會產物,人類日常生活中隨時必須接觸使用物件。因此,本研究以智慧型防盜鎖為實例,將物聯網概念運用於門鎖,進而提升居住的安全性。

所需材料

a. ameba開發板

Ameba是與物聯網兼容的Arduino開發板,除了WiFi連接之外,它還包括一個NFC標籤,並且可以通過Arduino兼容的標頭支持乙太網。該主板的大腦是Realtek RTL8195AM Wi-Fi SoC,內置Arm®Cortex®-M3 MCU,內含WiFi連接,硬件SSL,SRAM和閃存。

b.麵包板

c.語音模組 – DF Player Mini SKU

d.繼電器

e.電鎖- 內開型(正鎖)

f.傳輸線

g.Power Spray-輸出5V 2A

h.小喇叭

i.手機

運作原理

透過Arduino撰寫程式後,由傳輸線寫入 ameba開發板,此時Arduino運作視窗會給一組IP位址,將手機網頁輸入IP位址,出現Open/Close按鈕,就可進行遠端開鎖及解鎖,開鎖後會發出語音訊息通知已解鎖,尚未關門會提醒請關門。

電路圖

成果DEMO

Resource

程式碼如下:

#include <WiFi.h>

#include <SoftwareSerial.h>

#include <DFPlayer_Mini_Mp3.h>

SoftwareSerial mySerial(0, 1); // RX, TX

 

char ssid[] = “NCNU-EMBA”;      // your network SSID (name)

char pass[] = “0492918270”;     // your network password

int keyIndex = 0;                 // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;

WiFiServer server(80);

#define RelayPin 8

#define Turnon HIGH

#define Turnoff LOW

 

void setup() {

Serial.begin (9600);

mySerial.begin (9600);

Serial.println(“hello,this is lock system”);

mp3_set_serial (mySerial);      //set Serial for DFPlayer-mini mp3 module

delay(1);                     // delay 1ms to set volume

mp3_set_volume (30);          // value 0~30

 

/*=======on top of is voice code======*/

 

Serial.begin(9600);      // initialize serial communication

pinMode(RelayPin, OUTPUT);      // set the LED pin mode’

digitalWrite(RelayPin, Turnoff) ;

// check for the presence of the shield:

if (WiFi.status() == WL_NO_SHIELD) {

Serial.println(“WiFi shield not present”);

while (true);       // don’t continue

}

 

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 Network named: “);

Serial.println(ssid);                   // print the network name (SSID);

 

// Connect to WPA/WPA2 network. Change this line if using open or WEP network:

//    status = WiFi.begin(ssid);    //no pass

status = WiFi.begin(ssid, pass);    //wpa use

// wait 10 seconds for connection:

delay(10000);

}

server.begin();                           // start the web server on port 80

printWifiStatus();                        // you’re connected now, so print out the status

}

 

void loop() {

WiFiClient client = server.available();   // listen for incoming clients

 

if (client) {                             // if you get a client,

Serial.println(“new client”);           // print a message out the serial port

String currentLine = “”;                // make a String to hold incoming data from the client

while (client.connected()) {            // loop while the client’s connected

if (client.available()) {             // if there’s bytes to read from the client,

char c = client.read();             // read a byte, then

Serial.write(c);                    // print it out the serial monitor

if (c == ‘\n’) {                    // if the byte is a newline character

 

// if the current line is blank, you got two newline characters in a row.

// that’s the end of the client HTTP request, so send a response:

if (currentLine.length() == 0) {

// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)

// and a content-type so the client knows what’s coming, then a blank line:

client.println(“HTTP/1.1 200 OK”);

 

client.println(“Content-type:text/html”);

client.println();

 

// the content of the HTTP response follows the header:

client.print(“Click <a href=\”/H\”>here</a> turn Lock on<br>”);

//client.print(“Click <a href=\”/L\”>here</a> turn Power off<br>”);

 

// The HTTP response ends with another blank line:

client.println();

// break out of the while loop:

break;

} else {    // if you got a newline, then clear currentLine:

currentLine = “”;

}

} else if (c != ‘\r’) {  // if you got anything else but a carriage return character,

currentLine += c;      // add it to the end of the currentLine

}

 

// Check to see if the client request was “GET /H” or “GET /L”:

if (currentLine.endsWith(“GET /H”)) {

//Serial.println(“LIGHT ON”);

digitalWrite(RelayPin, Turnon); // GET /H turns the LED on

Serial.println(“LIGHT ON”);

delay(500);

PlayVoice (12,40);  //this is onlock voice

delay(1000);

digitalWrite(RelayPin, Turnoff); // GET /H turns the LED on

PlayVoice (13,40);  //this is onlock voice

delay(1000);

 

}

/*if (currentLine.endsWith(“GET /L”)) {

//Serial.println(“LIGHT OFF”);

digitalWrite(RelayPin, Turnoff);                // GET /L turns the LED off

Serial.println(“LIGHT OFF”);

mp3_play (13);  //this is lock voice

delay(1000);

}*/

}

}

// close the connection:

client.stop();

Serial.println(“client disonnected”);

}

}

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”);

// print where to go in a browser:

Serial.print(“To see this page in action, open a browser to http://”);

Serial.println(ip);

}

void PlayVoice(int no, int waiting)

{

Serial.print(no) ;

mp3_play(no);

delay(waiting*100) ;

}

 

void PlayNumber(int no)

{

mp3_play(no);

delay(700) ;

}

Latest posts by pigdashx2 Sheng kuo (see all)

    Contact

    Contact
    • Category
      Arduino

    Project簡述

    Project簡述
    • 簡述
      以智慧型防盜鎖為實例,將物聯網概念運用於門鎖,進而提升居住的安全性。
    • 作者
      許聖國、謝政倫、賴宜鴻、謝耿順、林奇伯

    您的姓名 〈需填寫〉

    您的電子郵件信箱 〈需填寫〉

    主旨

    您的信件內容