{"id":2102,"date":"2024-07-15T12:32:23","date_gmt":"2024-07-15T12:32:23","guid":{"rendered":"https:\/\/iotthinghub.com\/?p=2102"},"modified":"2024-08-11T17:43:42","modified_gmt":"2024-08-11T17:43:42","slug":"rfid-card-interface","status":"publish","type":"post","link":"https:\/\/iotthinghub.com\/?p=2102","title":{"rendered":"RFID Card Interface"},"content":{"rendered":"\n<p class=\"has-text-color has-link-color wp-elements-7de7ec5b9c7131479e7e538761388d36 wp-block-paragraph\" style=\"color:#5c5c5c\">Some time we need a square door lock or entry for security reasons. RFID card has a unique ID with 1Kb ram. We can write or read from the memory block. Let\u2019s look at the package that available in market-<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"336\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/07\/RFID-Card-1024x336.jpg\" alt=\"\" class=\"wp-image-2107\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/07\/RFID-Card-1024x336.jpg 1024w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/07\/RFID-Card-300x98.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/07\/RFID-Card-768x252.jpg 768w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/07\/RFID-Card.jpg 1280w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-9babaf65106f24edb9b1b61c1e88c1a4 wp-block-paragraph\" style=\"color:#5c5c5c\">The MFRC522 is a highly integrated reader\/writer IC for contactless communication at 13.56MHz. Since on board we have 27.12MHz frequency, we have to divide the clock. The MFRC522 can operate in SPI, I<sup>2<\/sup>C or UART protocol. The pin that controlling the protocol are-<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><img decoding=\"async\" width=\"1024\" height=\"314\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/07\/Table-7-1024x314.jpg\" alt=\"\" class=\"wp-image-2109\" style=\"width:740px;height:auto\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/07\/Table-7-1024x314.jpg 1024w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/07\/Table-7-300x92.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/07\/Table-7-768x235.jpg 768w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/07\/Table-7.jpg 1228w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-18bf9df705ed780665e234cf4e1e0331 wp-block-paragraph\" style=\"color:#5c5c5c\">By default, in the package EA = 3.3 V and I<sup>2<\/sup>C = 0 V, so it can only controller by SPI interface. If you change the wiring then it can be controlled by I<sup>2<\/sup>C or UART protocol. SPI protocol can operate up to 10Mbit\/s. Let\u2019s look at pin available \u2013<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><img decoding=\"async\" width=\"1024\" height=\"403\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/07\/pin-RFID-1024x403.jpg\" alt=\"\" class=\"wp-image-2113\" style=\"width:760px;height:auto\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/07\/pin-RFID-1024x403.jpg 1024w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/07\/pin-RFID-300x118.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/07\/pin-RFID-768x302.jpg 768w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/07\/pin-RFID.jpg 1371w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"482\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/07\/RFID-Interface-1024x482.jpg\" alt=\"\" class=\"wp-image-2114\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/07\/RFID-Interface-1024x482.jpg 1024w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/07\/RFID-Interface-300x141.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/07\/RFID-Interface-768x361.jpg 768w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/07\/RFID-Interface.jpg 1037w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-b0b6339ea367813f62f205a766ad2712 wp-block-paragraph\" style=\"color:#5c5c5c\">Here we use ATmega8 for our project. Connect the I<sup>2<\/sup>C LCD and RFID reader to the microcontroller. Here PD2 for load control that may be any door lock or any other medium. Download the hex file and load the microcontroller. Connect all devices according to the connection. Remember that the RFID reader has a VCC 3.3V, don\u2019t connect the 5V directly.<\/p>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-c1fae1ab3f5ea75c7c23774f45b93dcd wp-block-paragraph\" style=\"color:#5c5c5c\">The procedure is as follow-<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"225\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/07\/function-18-1024x225.jpg\" alt=\"\" class=\"wp-image-2116\" style=\"width:678px;height:auto\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/07\/function-18-1024x225.jpg 1024w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/07\/function-18-300x66.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/07\/function-18-768x169.jpg 768w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/07\/function-18.jpg 1347w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-bd58b8c7e638e8b0a0322843c30df76d wp-block-paragraph\" style=\"color:#5c5c5c\">After following the above procedure you are done with your device setup. Now whenever you place your Tag ID pin PD2 will high for 30s then it will go low. Use PD2 pin for your security purpose. Remember<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"67\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/07\/function-19-1024x67.jpg\" alt=\"\" class=\"wp-image-2118\" style=\"width:672px;height:auto\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/07\/function-19-1024x67.jpg 1024w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/07\/function-19-300x20.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/07\/function-19-768x50.jpg 768w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/07\/function-19.jpg 1312w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-1888af16dc851338e730199dd97be8c3 wp-block-paragraph\" style=\"color:#5c5c5c\">The main program as follow-<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\n #include&lt;avr\/io.h&gt;\n #include&lt;util\/delay.h&gt;\n #include&lt;stdio.h&gt;\n #include&quot;RFID.h&quot;\n #include&quot;I2CLCD.h&quot;\nuint8_t FoundTag,ReadTag,TagData&#x5B;16],sw; \/\/ Variable used to store Full Tag Data\nuint8_t YourTag&#x5B;4]={0xB3,0x4A,0x63,0xA9};\nchar buffer&#x5B;20];\nint main(void)\n {\n DDRD|=(1&lt;&lt;DDD2);                  \/\/Load pin\n DDRD&amp;=~((1&lt;&lt;DDD3)|(1&lt;&lt;DDD4));    \/\/input pin\n init_spi();\n system_init();\n LCD_Clear();\n begin(); \/\/initialize MFRC522\n LCD_write_string(1,1,&quot;Waiting for TAG&quot;);\n uint8_t version = readFromRegister(VersionReg);\n if(!version) LCD_write_string(1,2,&quot;NO DEVICE&quot;);\n if(version)\n {\n   LCD_write_string(1,2,&quot;DEVICE found&quot;);\n   _delay_ms(1000);\n   sprintf(buffer,&quot;%2X          &quot;,(version)); \/\/display version in hexadecimal\n   LCD_write_string(1,2,buffer);\n }\n sw=PIND&amp;(1&lt;&lt;PIND3);\n while(sw)\n  {\n    sw=PIND&amp;(1&lt;&lt;PIND3);\n    FoundTag = requestTag(MF1_REQIDL, TagData);\n    if (FoundTag == MI_OK)\n\t{\n\t\tReadTag = antiCollision(TagData);\n\t\tLCD_write_string(1,1,&quot;Tag Detected    &quot;);\n\t\tfor(uint8_t i=0;i&lt;4;i++)\n        YourTag&#x5B;i]=TagData&#x5B;i];\n\t\t_delay_ms(1000);\n\t\tsprintf(buffer,&quot;Sl %2X:%2X:%2X:%2X  &quot;,YourTag&#x5B;0],YourTag&#x5B;1],YourTag&#x5B;2],YourTag&#x5B;3]);\n\t\tLCD_write_string(1,1,buffer);\n\t\tLCD_write_string(1,2,&quot;Enter to save   &quot;);\n\t}\n }\n LCD_Clear();\n while(1)\n  {\n   LCD_write_string(1,1,&quot;Security System  &quot;);\n   FoundTag = requestTag(MF1_REQIDL, TagData);\n   if (FoundTag == MI_OK)\n     {\n       ReadTag = antiCollision(TagData);\n\t   if((YourTag&#x5B;0]==TagData&#x5B;0])&amp;&amp;(YourTag&#x5B;1]==TagData&#x5B;1])&amp;&amp;(YourTag&#x5B;2]==TagData&#x5B;2])&amp;&amp;(YourTag&#x5B;3]==TagData&#x5B;3]))\n\t   {\n\t   LCD_write_string(1,2,&quot;unlock for 30s  &quot;);\n\t\tPORTD|=(1&lt;&lt;PORTD2);  \/\/open for 30s\n\t\t_delay_ms(30000);\n\t\tLCD_write_string(1,2,&quot;**** Locked ****  &quot;);\n\t   }\n     }else PORTD&amp;=~(1&lt;&lt;PORTD2);\n }\nreturn 0;\n}\n\n<\/pre><\/div>\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-7387b849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:33.33%\">\n<div class=\"wp-block-buttons is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-3e41869c wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/ID-0x3f.rar\" style=\"padding-top:var(--wp--preset--spacing--30);padding-right:var(--wp--preset--spacing--40);padding-bottom:var(--wp--preset--spacing--30);padding-left:var(--wp--preset--spacing--40)\">download<\/a><\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:66.66%\">\n<p class=\"has-text-color has-link-color has-upper-heading-font-size wp-elements-dc95ff5b4842bacc382c96fdedba56aa wp-block-paragraph\" style=\"color:#252525\"><a href=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/ID-0x3f.rar\">main.hex with I<sup>2<\/sup>C ID : 0x3F<\/a><\/p>\n<\/div>\n<\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-7387b849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:33.33%\">\n<div class=\"wp-block-buttons is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-3e41869c wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/ID-0x27-1.rar\" style=\"padding-top:var(--wp--preset--spacing--30);padding-right:var(--wp--preset--spacing--40);padding-bottom:var(--wp--preset--spacing--30);padding-left:var(--wp--preset--spacing--40)\">download<\/a><\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:66.66%\">\n<p class=\"has-text-color has-link-color has-upper-heading-font-size wp-elements-3e4b5392b62ab66f887be8921c3922a2 wp-block-paragraph\" style=\"color:#252525\"><a href=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/ID-0x27-1.rar\">main.hex with I<sup>2<\/sup>C ID : 0x27<\/a><\/p>\n<\/div>\n<\/div>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-cae320935419aa643cd888d77f16d8b3 wp-block-paragraph\" style=\"color:#5c5c5c\">Since the I<sup>2<\/sup>C LCD has a unique ID. So download according to the I<sup>2<\/sup>C LCD device ID. I<sup>2<\/sup>C will be discussing in the next article and you can find I<sup>2<\/sup>C address detecting hex file.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Some time we need a square door lock or entry for security reasons. RFID card has a unique ID with 1Kb ram. We can write or read from the memory block. Let\u2019s look at the package that available in market- The MFRC522 is a highly integrated reader\/writer IC for contactless communication at 13.56MHz. Since on [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-2102","post","type-post","status-publish","format-standard","hentry","category-spi"],"_links":{"self":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/2102","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2102"}],"version-history":[{"count":12,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/2102\/revisions"}],"predecessor-version":[{"id":2640,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/2102\/revisions\/2640"}],"wp:attachment":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2102"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2102"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2102"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}