티스토리 뷰
0. 목차 |
1. Ver 1.0 & Ver 2.0 : http://twinw.tistory.com/136
2. Ver 3.0 : http://twinw.tistory.com/168(현재 페이지)
3. Ver 4.0 : http://twinw.tistory.com/170
1. 개요(이전 버전) |
Ver 1.0은 아래 그림과 아두이노로 릴레이에 연결된 도어락 모듈을 제어하는 단순한 방식이다.
Ver 1.0 의 NFC 도어락은 http://twinw.tistory.com/136에 가면 동영상을 볼 수 있다. 도어락 모듈을 따로 물어보시는 분들이 계신데 URL은 기억이 나지 않고 네이버 쇼핑에서 도어락 모듈 검색을 하다 구매한 기억이 남아있다.
Ver 2.0는 많은 시행착오를 겪고 실제 사물함에 설치한 버전이다.
시나리오에 대해 자세히 설명하겠다.
1. 버튼을 눌러 Sleep모드 중인 아두이노 보드를 깨운다.
2. 아두이노는 NFC 모듈의 전원이 연결되어 있는 릴레이에 신호를 보내 NFC 모듈을 켠다.
3. NFC 모듈은 일정 시간 동안 데이터를 읽고 신호가 없다면 아두이노 보드는 다시 Sleep모드로 돌아간다.
4. 만약 NFC 모듈에 신호가 있다면, 즉 등록된 카드를 모듈에 댄다면, 아두이노는 도어락 제어선이 연결된 릴레이 모듈에 신호를 주어 도어락을 동작시킨다.
앞서 말했지만 Ver.01과 Ver.02는 http://twinw.tistory.com/136에가면 더욱 더 자세히 볼 수 있다.
2. Ver.03 |
먼저 Ver.02과 Ver.03의 모습을 비교해 보자. 가장 먼저 눈에 띄는건 9V 사각전지가 샤오미 배터리로 변경되면서 복잡하던 회로가 모두 사라졌다. 또한 사각 전지가 각각 보드, 릴레이, NFC모듈에게 전원을 주던것을 배터리가 하나로 줄면서 보드가 받은 전압을 다시 모듈들에게 전달한다. 그리고 회로만 변경되었지 동작 시나리오는 변경되지 않았다.
회로를 Symbol로 만들어 보면 위와 같다. Fritzing으로 만들기 너무 귀찮아서 PowerPoint로 만들었다.
대체된 NFC 모듈은 NFC Module for Arduino v1.0이라는 모듈이고 기존 SPI통신으로 핀 4개를 사용하여 전류를 더럽게 먹던 RFID-RC522 모듈과 달리 Serial 통신을 하여 2개의 통신 핀만 사용해서 상대적으로 전류 사용량이 적다. 그러나 4000원 하던 RFID-RC522 모듈과 달리 20000원 정도 한다.
NFC Module for Arduino v1.0 모듈의 기본 Sample 코드는 https://www.dfrobot.com/wiki/index.php/NFC_Module_for_Arduino_(SKU:DFR0231)에 잘 설명되어 있다. (Google에 모듈명 치면 바로 나옴)
해당 버전에는 치명적인 문제가 있다. 바로 샤오미 !!
현재 전력소모를 적게 하기 위해 동작 시를 제외하고는 Sleep모드로 보드가 동작하는데 샤오미는 일정이상의 전력을 소비하지 않으면 꺼져버린다. 따라서 아래와 같은 독자적인 리튬 전지를 이용하기를 바란다.
해당 문제점을 해결한 것이 다음 버전인 Ver 4.0이고 http://twinw.tistory.com/170에서 볼 수 있다.
3. Ver 3.0 Source Code |
소스 코드는 https://github.com/cckr2/DoorLock에서 전 버전 다 다운 받을 수 있다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | #include "LowPower.h" #define wake_result 15 #define firmware_result 19 #define tag_result 25 const unsigned char wake[24]={ 0x55, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x03, 0xfd, 0xd4, 0x14, 0x01, 0x17, 0x00}; //wake up NFC module const unsigned char firmware[9]={ 0x00, 0x00, 0xFF, 0x02, 0xFE, 0xD4, 0x02, 0x2A, 0x00}; // const unsigned char tag[11]={ 0x00, 0x00, 0xFF, 0x04, 0xFC, 0xD4, 0x4A, 0x01, 0x00, 0xE1, 0x00}; //detecting tag command const unsigned char std_ACK[25] = { 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x0C, \ 0xF4, 0xD5, 0x4B, 0x01, 0x01, 0x00, 0x04, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00, 0x4b, 0x00}; unsigned char old_id[5]; unsigned char cur_id[5]; unsigned char receive_ACK[25]; //Command receiving buffer const int button = 2; const int power_Relay = 7; const int door_Relay = 8; void setup() { Serial.begin(115200); // open serial with PC delay(100); pinMode(power_Relay,OUTPUT); pinMode(door_Relay,OUTPUT); pinMode(button,INPUT_PULLUP); } void loop() { attachInterrupt(0, wakeUp, LOW); LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF); //set Sleep mode detachInterrupt(0); checking(); } void UART_Send_Byte(unsigned char command_data) { //send byte to device Serial.write(command_data); Serial.flush(); // complete the transmission of outgoing serial data } void wake_card( void ) { //send wake[] to device unsigned char i; for (i=0;i<24;i++) //send command UART_Send_Byte(wake[i]); } void firmware_version( void ) { //send firmware[] to device unsigned char i; for (i=0;i<9;i++) //send command UART_Send_Byte(firmware[i]); } void send_tag( void ) { //send tag[] to device unsigned char i; for (i=0;i<11;i++) //send command UART_Send_Byte(tag[i]); } void read_ACK(unsigned char temp) { //read ACK into reveive_ACK[] //Serial.println("read the result"); unsigned char i; for (i=0;i<temp;i++) { receive_ACK[i]= Serial.read(); } } void display(unsigned char tem) { for ( int i=0;i<tem;i++) { if (receive_ACK[i] < 16) // to make 2 digits Serial.print( "0" ); Serial.print(receive_ACK[i], HEX); if (i<(tem-1)) Serial.print( " " ); } Serial.println(); } void copy_id ( void ) { //save old id int i; for (i=0 ; i<5 ; i++) { old_id[i] = cur_id[i]; } } // read tag id from tag values void read_id ( void ) { int ai, ci; for (ci=0, ai=19; ci<5; ci++,ai++) { cur_id[ci] = receive_ACK[ai]; } } //return true if find id is old char same_id ( void ) { int ai, oi; for (oi=0,ai=19; oi<5; oi++,ai++) { if (old_id[oi] != receive_ACK[ai]) return 0; } return 1; } // true if tag is FF FF FF FF FF char no_detection( void ) { int i; for (i=0 ; i< sizeof (cur_id) ; i++) { if (cur_id[i] != 255) // FF return 0; } return 1; } void print_id() { for ( int i=0 ; i< sizeof (cur_id) ; i++) { if (cur_id[i] < 16) // to make 2 digits Serial.print( "0" ); Serial.print(cur_id[i], HEX); Serial.print( "(" ); Serial.print(cur_id[i]); Serial.print( ")" ); if (i<( sizeof (cur_id)-1)) Serial.print( " " ); } Serial.println(); } int check_id( int count) { for ( int i=0 ; i<5 ; i++) { if (cur_id[i] < 16) // to make 2 digits Serial.print( "0" ); Serial.print(cur_id[i]); } if (cur_id[0] == 115 && cur_id[1] == 5 && cur_id[2] == 85) { digitalWrite(door_Relay, HIGH); delay(500); digitalWrite(door_Relay, LOW); return 0; } else if (cur_id[0] == 7 && cur_id[1] == 78 && cur_id[2] == 123) { digitalWrite(door_Relay, HIGH); delay(500); digitalWrite(door_Relay, LOW); return 0; } else if (cur_id[0] == 5 && cur_id[1] == 167 && cur_id[2] == 165) { digitalWrite(door_Relay, HIGH); delay(500); digitalWrite(door_Relay, LOW); return 0; } else if (cur_id[0] == 238 && cur_id[1] == 49 && cur_id[2] == 26) { digitalWrite(door_Relay, HIGH); delay(500); digitalWrite(door_Relay, LOW); return 0; } return count; } void NFC_init(){ Serial.println( "wake card" ); delay(100); // give delay before sending command bytes wake_card(); delay(100); read_ACK(wake_result); delay(100); display(wake_result); firmware_version(); delay(100); read_ACK(firmware_result); delay(100); display(firmware_result); } void wakeUp(){} void checking() //when wake up, this function will working { int button_state = 0; int count = 0; int k,check_nfc=0; digitalWrite(power_Relay, HIGH); count=15; delay(100); NFC_init(); delay(100); while (count!=0){ check_nfc=0; button_state = digitalRead(button); count--; if (button_state==0){ // this is safe Function. delay(100); for (k=0;k<25;k++){ button_state = digitalRead(button); if (button_state==0){ delay(200); check_nfc++; } else break ; } if (check_nfc>20){ digitalWrite(door_Relay, HIGH); delay(500); digitalWrite(door_Relay, LOW); count=0; } } else { send_tag(); read_ACK(tag_result); read_id(); if (!no_detection()) { //print_id(); count = check_id(count); } } delay(100); } digitalWrite(power_Relay, LOW); } |
'HardWare > 프로젝트' 카테고리의 다른 글
스마트 멀티탭 만들기 -(1)사전 준비 (0) | 2017.05.02 |
---|---|
wifi기반 진동벨 만들기 (8) | 2017.04.05 |
아두이노 프로젝트 - 스마트 홈(1) 적외선(리모컨) 제어 (0) | 2016.11.28 |
아두이노 프로젝트 - NFC 도어락(DoorLock) Ver 4.0 (12) | 2016.11.20 |
아두이노 프로젝트 - NFC 도어락(DoorLock) Ver 1.0 & Ver 2.0 (27) | 2016.08.15 |
- Total
- Today
- Yesterday
- java url
- java 파일 입출력
- 유전 알고리즘
- 안드로이드
- 테라펀딩 #투게더펀딩 #P2P투자 #부동산 소액 투자 #카카오 #토스
- 인텐트
- 서버
- 카운터
- counter
- Service
- Java Decompiler
- php
- 5582
- 파일입출력
- Res
- 자바 입출력
- android
- 아두이노
- 파일 입출력
- LISTVIEW
- 포켓몬 Go
- 포켓몬 고
- java
- vim 설치
- 알고리즘
- c언어
- jad
- vim
- Notification
- 유전
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |