步驟1:所需的零件
必需的零件。
1-帶拇指的門鎖打開門的內(nèi)部
1-Arduino Uno r3(或兼容)
1-360度伺服系統(tǒng)
1-HC-06藍(lán)牙模塊
1-RC522 RFID閱讀器(可能是Sintron,不記得了)
1-16 x 2-4線LDC屏幕
1-RGB LED
2-220Ω電阻器
1-瞬時(shí)按動(dòng)開關(guān)(從內(nèi)部操作以鎖定/
1-1-1kΩ電阻器
2-雙后箱(1個(gè)約45mm深度,另一個(gè)約33mm深度)
跳線
電源(我打算使用2 x 9v電池,但已決定使用市電供電的9v電源,因?yàn)楦煽浚?/p>
螺絲或堅(jiān)固的雙面膠帶
1-伺服支架(我自己設(shè)計(jì)和印刷)
** ----------------等待發(fā)貨-------- ------------------- ------------ **
2-雙盲板
1-12芯報(bào)警電纜的長(zhǎng)度(長(zhǎng)度取決于放置位置)
2-5amp模塊連接器(每個(gè)12線)
** --------------------------- -------------------------------------------------- ---- **
Andriod藍(lán)牙鎖應(yīng)用程序。 BTControl.apk
步驟2:接線
電源:
9v穩(wěn)壓電源(或電池)
RFID讀取器:
VCC-引腳3.3v
GND-GND
重置(RST)-引腳D9
SDA(SS)-引腳D10
MOSI-引腳D11
MISO-引腳D12
SCK-引腳D13
LCD屏幕
VCC-5v
GND-GND
SDA-引腳A4
SCL-引腳A5
瞬時(shí)開關(guān):
VCC-5v(如上所示)
GND到1kΩ電阻(如上所示)
Pin 8 arduino(如上所示)
RGB LED:
將D7的220Ω電阻接至LED引腳(紅色)
將D6的220Ω電阻接至LED引腳(綠色)
公共(長(zhǎng)線)- GND
伺服:
VCC-5v
GND-GND
信號(hào)-引腳D5
藍(lán)牙模塊:
VCC-5v
GND -GND
TX-D0(RX)
RX-D1(TX)
Fritzing圖:
步驟3:Pu一起努力
Arduino,藍(lán)牙模塊和瞬間開關(guān)+ RGB LED電路安裝在45mm的底盒中。我剛剛使用Blu-Tac將它們固定在原位,因?yàn)橐坏┕潭ㄔ趬ι暇筒粫?huì)移動(dòng)。我已經(jīng)將開關(guān),LED和電阻器焊接到了電路板上,并在電路板的任何一側(cè)創(chuàng)建了GND和VCC連接,還將放置一個(gè)用于12芯報(bào)警電纜的塊連接器,以連接RFID和LCD屏幕到arduino。蓋子上會(huì)鉆2個(gè)孔,以容納開關(guān)和引線。
RFID和LCD屏幕安裝在33mm的后蓋內(nèi),并開有一個(gè)插槽,用于LCD屏幕穿過(guò)。這些將通過(guò)12芯報(bào)警電纜和模塊連接器連接到arduino。
為使伺服器連接到門鎖,我3D打印了一個(gè)支架,該支架將擰緊到門上并連接到門上。
步驟4:代碼-(于2018年6月23日更新)
/*
* ----------------------------------------------------------------------------
* This sketch uses the MFRC522 library ; see https://github.com/miguelbalboa/rfid
* for further details and other examples.
*
* NOTE: The library file MFRC522.h has a lot of useful info. Please read it.
*
* This sketch show a simple locking mechanism using the RC522 RFID module.
* ----------------------------------------------------------------------------
* Typical pin layout used:
* -----------------------------------------------------------------------------------------
* MFRC522 Arduino Arduino Arduino Arduino Arduino
* Reader/PCD Uno Mega Nano v3 Leonardo/Micro Pro Micro
* Signal Pin Pin Pin Pin Pin Pin
* -----------------------------------------------------------------------------------------
* RST/Reset RST 9 5 D9 RESET/ICSP-5 RST
* SPI SS SDA(SS) 10 53 D10 10 10
* SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16
* SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14
* SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15
*
*/
#include
#include
#include
#include
#include
#include
#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 10
#define Green_LED 6 //pin for green “door unlocked” indicator LED
#define Red_LED 7 //pin for red “door locked” indicator LED
char array1[]=“ Swipe Your Tag”; //the string to print on the LCD
char array2[]=“ On The Reader.”;
char array3[]=“ Tag Accepted. ”;
char array4[]=“ Locking. ”;
char array5[]=“ Unlocking. ”;
int tim = 1; //the value of delay time
// initialize the library with the numbers of the interface pins
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
Servo myservo;
String read_rfid;
String ok_rfid_1=“94e68de2”;
String ok_rfid_2=“f5642a50”;
String ok_rfid_3=“4249622993c81”;
int addr = 1;
int eVal = 0;
int lockPosition;
int servo_position;
int BUTTON1 = 8;
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
{
lcd.init(); //initialize the lcd
lcd.backlight(); //open the backlight
lcd.begin(16,2);
}
pinMode(Green_LED, OUTPUT); //set all input/output pins, including whether they should be high (5v) or low (ground)
pinMode(Red_LED, OUTPUT);
digitalWrite(Green_LED, LOW);
digitalWrite(Red_LED, HIGH);
pinMode(BUTTON1,INPUT);
myservo.attach(5);
lockPosition = EEPROM.read(1);
// Serial.print(EEPROM.read(1));
if(lockPosition == 1){
digitalWrite(Red_LED, LOW);
digitalWrite(Green_LED, HIGH);
}
else {
digitalWrite(Red_LED, HIGH);
digitalWrite(Green_LED, LOW);
lockUnlock();
}
swipeText();
/*
* Dump a byte array as hex values to Serial.
*/
void dump_byte_array(byte *buffer, byte bufferSize) {
read_rfid=“”;
for (byte i = 0; i 《 bufferSize; i++) {
read_rfid=read_rfid + String(buffer[i], HEX);
}
}
void lockUnlock() { // locks or unlocks door
myservo.attach(5);
if(lockPosition == 1) {
lock2();
servo_position = 0;
myservo.write(servo_position);
digitalWrite(Red_LED, HIGH);
digitalWrite(Green_LED, LOW);
delay(3000);
lockPosition = 2;
eVal = lockPosition;
EEPROM.write(1,eVal);
// Serial.print(eVal);
}
else if(lockPosition == 2) {
lock1();
servo_position = 350;
myservo.write(servo_position);
digitalWrite(Red_LED, LOW);
digitalWrite(Green_LED, HIGH);
delay(3000);
lockPosition = 1;
eVal = lockPosition;
EEPROM.write(1,eVal);
// Serial.print(eVal);
}
myservo.detach();
}
void swipeText()
{
lcd.clear(); //Clears the LCD screen and positions the cursor in the upper-left corner.
lcd.setCursor(0,0); // set the cursor to column 15, line 0
for (int positionCounter1 = 0; positionCounter1 《 15; positionCounter1++)
{
lcd.print(array1[positionCounter1]); // Print a message to the LCD.
delay(tim); //wait for 250 microseconds
}
lcd.setCursor(0,1); // set the cursor to column 15, line 1
for (int positionCounter = 0; positionCounter 《 15; positionCounter++)
{
lcd.print(array2[positionCounter]); // Print a message to the LCD.
delay(tim); //wait for 250 microseconds
}
}
void lock1()
{
lcd.clear();
lcd.setCursor(0,0);
for (int positionCounter1 = 0; positionCounter1 《 15; positionCounter1++)
{
lcd.print(array3[positionCounter1]);
delay(tim);
}
lcd.setCursor(0,1);
for (int positionCounter1 = 0; positionCounter1 《 10; positionCounter1++)
{
lcd.print(array4[positionCounter1]);
delay(tim);
}
}
void lock2()
{
lcd.clear();
lcd.setCursor(0,0);
for (int positionCounter1 = 0; positionCounter1 《 15; positionCounter1++)
{
lcd.print(array3[positionCounter1]);
delay(tim);
}
lcd.setCursor(0,1);
for (int positionCounter1 = 0; positionCounter1 《 12; positionCounter1++)
{
lcd.print(array5[positionCounter1]);
delay(tim);
}
}
void loop() {
if(digitalRead(BUTTON1) == HIGH){
lockUnlock();
swipeText();
}
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
return;
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
return;
dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
Serial.println(read_rfid);
if (read_rfid==ok_rfid_1) {
//ok, open the door.
lockUnlock();
swipeText();
}
//Add below as many “keys” as you want
if (read_rfid==ok_rfid_2) {
//also ok, open the door
lockUnlock();
swipeText();
}
//Add below as many “keys” as you want
if (read_rfid==ok_rfid_3) {
//also ok, open the door
lockUnlock();
swipeText();
}
}
-
RFID
+關(guān)注
關(guān)注
388文章
6180瀏覽量
238188 -
藍(lán)牙
+關(guān)注
關(guān)注
114文章
5844瀏覽量
170787 -
門鎖
+關(guān)注
關(guān)注
0文章
47瀏覽量
11936
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論