本帖最后由 cnkids 于 2012-11-23 17:44 编辑
协会要换锁,上门禁系统,{:soso_e135:}{:soso_e135:}找不到人焊锁。。囧囧的。。
使用的材料有:
电机锁 x1
MANGO x1
RFID读卡模块 x1
ID卡 若干
直流稳压电源板 x1
DC-DC固态继电器 x1
先来几张图~{:soso_e147:}{:soso_e147:}
上视频,不是很长,基本演示了一下功能。
贴个程序,有兴趣的一起研究哈~- #include <EEPROM.h>
- #define EEPROM_write(address, p) {int i = 0; byte *pp = (byte*)&(p);for(; i < sizeof(p); i++) EEPROM.write(address+i, pp[i]);}
- #define EEPROM_read(address, p) {int i = 0; byte *pp = (byte*)&(p);for(; i < sizeof(p); i++) pp[i]=EEPROM.read(address+i);}
- const int ENPin = 2; // the number of the EN pin
- int ENState = 1; //default EN state was HIGH
- int lock = 3;
- void setup()
- {
- Serial.begin(9600);
- pinMode(ENPin, INPUT);
- pinMode(lock,OUTPUT);
- digitalWrite(lock,LOW);
- }
- void loop()
- {
- unsigned long ID = 0; //define a string variable
- unsigned long IDR = 0;
- for(ENState = digitalRead(ENPin) ; ENState == LOW && Serial.available() > 0; ) // read the state of the EN value,check if the EN is LOW,the output the data.
- {
- ID = ID * 10 + int(Serial.read()-'0'); //read the number from IDcard
- delay(2);
- }
- if(ID != 0) //if comdata gets the IDcard number,show it
- {
- Serial.println(ID);
- for(int addr = 0; addr <= 1020; addr = addr + 10)
- {
- EEPROM_read(addr, IDR);
- if(ID == IDR)
- {
- digitalWrite(lock, HIGH);
- delay(1000);
- digitalWrite(lock, LOW);
- delay(20);
- Serial.println("Welcome!"); break;
- }
- }
- if(ID != IDR) Serial.println("Sorry,you are not allowed!");
- ID = 0; //clean the comdata
- }
- }
复制代码 |