{"id":900,"date":"2018-02-05T01:08:28","date_gmt":"2018-02-05T01:08:28","guid":{"rendered":"https:\/\/zhutarduino.wordpress.com\/?page_id=900"},"modified":"2019-10-20T18:13:11","modified_gmt":"2019-10-20T18:13:11","slug":"learning-arduino-for-beginners-ep30-rfid-readers","status":"publish","type":"page","link":"https:\/\/thezhut.com\/?page_id=900","title":{"rendered":"Learning Arduino for beginners EP#30 RFID readers"},"content":{"rendered":"<h1>In this tutorial we will take a look at how you can use RFID readers with your Arduino to control things like keyless entry door locks and relays to control lights&#8230;<\/h1>\n<h2>click on video below for full tutorial&#8230;<\/h2>\n<p><iframe loading=\"lazy\" title=\"Learning Arduino for beginners EP#30 RFID readers\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/IIHTmPxTzkU?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<h1><strong><a href=\"https:\/\/www.facebook.com\/zarduino\/\">Check us out on Facebook!<\/a><\/strong><\/h1>\n<h2>Parts list:<\/h2>\n<p>affiliate links<\/p>\n<p><a href=\"https:\/\/www.amazon.com\/gp\/search\/ref=as_li_qf_sp_sr_il_tl?ie=UTF8&amp;tag=zhut01-20&amp;keywords=arduino board&amp;index=aps&amp;camp=1789&amp;creative=9325&amp;linkCode=xm2&amp;linkId=3a0ab01a594968db9425875aa77fa183\" target=\"_blank\" rel=\"noopener noreferrer\">ARDUINO board:<\/a><\/p>\n<p><a href=\"https:\/\/www.amazon.com\/gp\/search\/ref=as_li_qf_sp_sr_il_tl?ie=UTF8&amp;tag=zhut01-20&amp;keywords=RC522&amp;index=aps&amp;camp=1789&amp;creative=9325&amp;linkCode=xm2&amp;linkId=e8635efe479d8d79fe5375839e65f2f3\" target=\"_blank\" rel=\"noopener noreferrer\">RFID-RC522:<\/a><\/p>\n<p><a href=\"https:\/\/www.amazon.com\/gp\/search\/ref=as_li_qf_sp_sr_il_tl?ie=UTF8&amp;tag=zhut01-20&amp;keywords=logic level converter&amp;index=aps&amp;camp=1789&amp;creative=9325&amp;linkCode=xm2&amp;linkId=594baaad2f7ff63f5818a35685673ce9\" target=\"_blank\" rel=\"noopener noreferrer\">Logic LVL Converter:<\/a><\/p>\n<p><a href=\"https:\/\/www.amazon.com\/gp\/search\/ref=as_li_qf_sp_sr_il_tl?ie=UTF8&amp;tag=zhut01-20&amp;keywords=rgb led&amp;index=aps&amp;camp=1789&amp;creative=9325&amp;linkCode=xm2&amp;linkId=9c3fe97f9cf6758f056c03fe86229375\" target=\"_blank\" rel=\"noopener noreferrer\">RGB LED:<\/a><\/p>\n<p><a href=\"https:\/\/www.amazon.com\/gp\/search\/ref=as_li_qf_sp_sr_il_tl?ie=UTF8&amp;tag=zhut01-20&amp;keywords=arduino bread board&amp;index=aps&amp;camp=1789&amp;creative=9325&amp;linkCode=xm2&amp;linkId=0ce6926653460af26f6d152449048ea6\" target=\"_blank\" rel=\"noopener noreferrer\">Breadboard:<\/a><\/p>\n<p><a href=\"https:\/\/www.amazon.com\/gp\/search\/ref=as_li_qf_sp_sr_il_tl?ie=UTF8&amp;tag=zhut01-20&amp;keywords=arduino jumper wires&amp;index=aps&amp;camp=1789&amp;creative=9325&amp;linkCode=xm2&amp;linkId=649ad3b9aeb426f81168e2aa0ae8579d\" target=\"_blank\" rel=\"noopener noreferrer\">Jumper Wires:<\/a><\/p>\n<h2>Schematic:<\/h2>\n<p><a href=\"https:\/\/thezhut.com\/wp-content\/uploads\/2017\/01\/rfid_door_lock_schem.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-498\" src=\"https:\/\/thezhut.com\/wp-content\/uploads\/2017\/01\/rfid_door_lock_schem.jpg?w=300\" alt=\"\" width=\"639\" height=\"324\" srcset=\"https:\/\/thezhut.com\/wp-content\/uploads\/2017\/01\/rfid_door_lock_schem.jpg 1689w, https:\/\/thezhut.com\/wp-content\/uploads\/2017\/01\/rfid_door_lock_schem-300x152.jpg 300w, https:\/\/thezhut.com\/wp-content\/uploads\/2017\/01\/rfid_door_lock_schem-768x389.jpg 768w, https:\/\/thezhut.com\/wp-content\/uploads\/2017\/01\/rfid_door_lock_schem-1024x518.jpg 1024w\" sizes=\"auto, (max-width: 639px) 100vw, 639px\" \/><\/a><\/p>\n<h2>ARDUINO CODE:<\/h2>\n<p>#include &lt;SPI.h&gt;<br \/>\n#include &lt;MFRC522.h&gt;<\/p>\n<p>#define RST_PIN 9 \/\/ Configurable, see typical pin layout above<br \/>\n#define SS_PIN 10 \/\/ Configurable, see typical pin layout above<\/p>\n<p>MFRC522 mfrc522(SS_PIN, RST_PIN); \/\/ Create MFRC522 instance.<\/p>\n<p>String read_rfid;<br \/>\nString ok_rfid_1 = &#8220;66f4608e&#8221;;<br \/>\nString ok_rfid_2 = &#8220;c08e3f52&#8221;; \/\/add as many as you need.<\/p>\n<p>#define red 3 \/\/ RGB led pins<br \/>\n#define green 4<br \/>\n#define relay 7 \/\/ Relay pin#<\/p>\n<p>void setup() {<br \/>\nSerial.begin(9600); \/\/ Initialize serial communications with the PC<br \/>\nSPI.begin(); \/\/ Init SPI bus<br \/>\nmfrc522.PCD_Init(); \/\/ Init MFRC522 card<br \/>\npinMode(red, OUTPUT);<br \/>\npinMode(green, OUTPUT);<br \/>\npinMode(relay, OUTPUT);<br \/>\n}<br \/>\nvoid dump_byte_array(byte *buffer, byte bufferSize) {<br \/>\nread_rfid = &#8220;&#8221;;<br \/>\nfor (byte i = 0; i &lt; bufferSize; i++) {<br \/>\nread_rfid = read_rfid + String(buffer[i], HEX);<br \/>\n}<br \/>\n}<\/p>\n<p>void open_lock() {<br \/>\n\/\/ if rfid is good this is what will happen<\/p>\n<p>digitalWrite(green, HIGH);<br \/>\ndigitalWrite(relay, HIGH);<br \/>\ndelay(5000); \/\/ how long the relay will be on<br \/>\ndigitalWrite(green, LOW);<br \/>\ndigitalWrite(relay, LOW);<br \/>\n}<\/p>\n<p>void loop() {<\/p>\n<p>\/\/ Look for new cards<br \/>\nif ( ! mfrc522.PICC_IsNewCardPresent())<br \/>\nreturn;<\/p>\n<p>\/\/ Select one of the cards<br \/>\nif ( ! mfrc522.PICC_ReadCardSerial())<br \/>\nreturn;<\/p>\n<p>dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);<br \/>\nSerial.println(read_rfid);<br \/>\nif (read_rfid == ok_rfid_1) { \/\/ RFID #1<br \/>\n\/\/ok, open the door.<br \/>\nopen_lock();<br \/>\n}<\/p>\n<p>if (read_rfid == ok_rfid_2) { \/\/ RFID #2<br \/>\n\/\/also ok, open the door<br \/>\nopen_lock();<br \/>\n}<\/p>\n<p>if (read_rfid != ok_rfid_1 &amp;&amp; read_rfid != ok_rfid_2)<br \/>\n{<br \/>\ndigitalWrite(red,HIGH);<br \/>\ndelay(2000);<br \/>\ndigitalWrite(red,LOW);<br \/>\n}<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial we will take a look at how you can use RFID readers with your Arduino to control things like keyless entry door locks and relays to control lights&#8230; click on video below for full tutorial&#8230; Check us &hellip; <a href=\"https:\/\/thezhut.com\/?page_id=900\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":809,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":"","_links_to":"","_links_to_target":""},"class_list":["post-900","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages\/900","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/thezhut.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=900"}],"version-history":[{"count":2,"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages\/900\/revisions"}],"predecessor-version":[{"id":1473,"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages\/900\/revisions\/1473"}],"up":[{"embeddable":true,"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages\/809"}],"wp:attachment":[{"href":"https:\/\/thezhut.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=900"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}