{"id":61725,"date":"2018-05-24T12:06:04","date_gmt":"2018-05-24T12:06:04","guid":{"rendered":"http:\/\/randomnerdtutorials.com\/?p=61725"},"modified":"2019-04-02T10:23:22","modified_gmt":"2019-04-02T10:23:22","slug":"arduino-time-attendance-system-with-rfid","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/arduino-time-attendance-system-with-rfid\/","title":{"rendered":"Arduino Time Attendance System with RFID"},"content":{"rendered":"<p>In this project you&#8217;re going to build a time attendance system with MFRC522 RFID Reader and Arduino. When you swipe an RFID tag next to the RFID reader, it saves the user UID and time in an SD card. It also shows if you are late or in time accordingly to a preset hour and minute.<\/p>\n<h2>First, watch the video intro below<\/h2>\n<p style=\"text-align:center\"><iframe width=\"720\" height=\"405\" src=\"https:\/\/www.youtube.com\/embed\/b01k6YlaHfA?rel=0\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<h2>Project Overview<\/h2>\n<p>Before getting started it&#8217;s important to layout the project main features:<\/p>\n<ul>\n<li>It contains an RFID reader that reads RFID tags;<\/li>\n<li>Our setup has a real time clock module to keep track of time;<\/li>\n<li>When the RFID reader reads an RFID tag, it saves the current time and the UID of the tag in an SD card;<\/li>\n<li>The Arduino communicates with the SD card using an SD card module;<\/li>\n<li>You can set a check in time to compare if you are in time or late;<\/li>\n<li>If you are on time, a green LED lights up, if you are late, a red LED lights up;<\/li>\n<li>The system also has a buzzer that beeps when a tag is read.<\/li>\n<\/ul>\n<h2>Parts Required<\/h2>\n<p><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter size-full wp-image-61733\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/parts-required-rfid.jpg?resize=700%2C402&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"700\" height=\"402\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/parts-required-rfid.jpg?w=700&amp;quality=100&amp;strip=all&amp;ssl=1 700w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/parts-required-rfid.jpg?resize=300%2C172&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/p>\n<p>Here&#8217;s a list of the required components for this project:<\/p>\n<ul>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/compatible-arduino-uno-r3-board\/\" target=\"_blank\" rel=\"noopener noreferrer\">Arduino UNO<\/a> &#8211; read <a href=\"https:\/\/makeradvisor.com\/best-arduino-starter-kits\/\" target=\"_blank\" rel=\"noopener noreferrer\">Best Arduino Starter Kits<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/mfrc522-rfid-reader\/\" target=\"_blank\" rel=\"noopener noreferrer\">MFRC522 RFID reader + tags<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/sd-card-module\/\" target=\"_blank\" rel=\"noopener noreferrer\">SD card module<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/microsd-card-raspberry-pi-16gb-class-10\/\" target=\"_blank\" rel=\"noopener noreferrer\">Micro SD card<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/real-time-clock-module-ds1307\/\" target=\"_blank\" rel=\"noopener noreferrer\">SD1307 RTC module<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/3mm-5mm-leds-kit-storage-box\/\" target=\"_blank\" rel=\"noopener noreferrer\">2x LEDs (1x red + 1x green)<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/resistors-kits\/\" target=\"_blank\" rel=\"noopener noreferrer\">2x 220 Ohm resistor<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\" rel=\"noopener noreferrer\">Breadboard<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\" rel=\"noopener noreferrer\">Jumper wires<\/a><\/li>\n<\/ul>\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n<h2>MFRC522 RFID Reader<\/h2>\n<p>In this project we&#8217;re using the MFRC522 RFID reader and that&#8217;s the one we recommend you to get (although this project may also be compatible with other RFID readers).<\/p>\n<p>RFID means <strong>r<\/strong>adio-<strong>f<\/strong>requency <strong>id<\/strong>entification. RFID uses electromagnetic fields to transfer data over short distances and it&#8217;s useful to identify people, to make transactions, etc.<\/p>\n<p>An RFID system needs tags and a reader:<\/p>\n<ul>\n<li><strong>Tags<\/strong>\u00a0are attached to the object to be identified, in this example we have a keychain and an electromagnetic card. Some stores also use RFID tags in their products&#8217; labels to identify them. Each tag has its own unique identification (UID).<\/li>\n<\/ul>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" class=\"aligncenter size-full wp-image-61736\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/RFID-tags.jpg?resize=700%2C446&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"700\" height=\"446\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/RFID-tags.jpg?w=700&amp;quality=100&amp;strip=all&amp;ssl=1 700w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/RFID-tags.jpg?resize=300%2C191&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/p>\n<ul>\n<li><strong>Reader<\/strong> is a two-way radio transmitter-receiver that sends a signal to the tag and reads its response.<\/li>\n<\/ul>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" class=\"aligncenter wp-image-61735\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/RFID-reader-e1504101606341-768x546.jpg?resize=456%2C324&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"456\" height=\"324\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/RFID-reader-e1504101606341-768x546.jpg?resize=768%2C546&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/RFID-reader-e1504101606341-768x546.jpg?resize=300%2C213&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 456px) 100vw, 456px\" \/><\/p>\n<p>The MFRC522 RFID reader works at 3.3V and it can use SPI or I2C communication. The <a href=\"https:\/\/github.com\/miguelbalboa\/rfid\/\" target=\"_blank\" rel=\"noopener noreferrer\">library<\/a> we&#8217;re going to use to control the RFID reader only supports SPI, so that&#8217;s the communication protocol we&#8217;re going to use.<\/p>\n<p>To learn more about the RFID reader with the Arduino read:\u00a0<a href=\"https:\/\/randomnerdtutorials.com\/security-access-using-mfrc522-rfid-reader-with-arduino\/\">Security Access using MFRC522 RFID Reader with Arduino<\/a><\/p>\n<h3>Installing the\u00a0MFRC522 library<\/h3>\n<p>This project uses the MFRC522.h library to control the RFID reader. This library doesn&#8217;t come installed in Arduino IDE by default, so you need to install it. Go to \u00a0<strong>Sketch<\/strong> &gt; <strong>Include library<\/strong> &gt; <strong>Manage libraries<\/strong> and search for <strong>MFRC522<\/strong> or follow the next steps:<\/p>\n<ol>\n<li><a href=\"https:\/\/github.com\/miguelbalboa\/rfid\/archive\/master.zip\" target=\"_blank\" rel=\"noopener noreferrer\">Click here to download the MFRC522 library<\/a>. You should have a .zip folder in your Downloads folder.<\/li>\n<li>Unzip the .zip folder and you should get\u00a0<strong>RFID-master<\/strong>\u00a0folder<\/li>\n<li>Rename your folder from <del><strong>RFID-master<\/strong><\/del>\u00a0to <strong>RFID<\/strong><\/li>\n<li>Move the <strong>RFID<\/strong> folder to your Arduino IDE installation libraries folder<\/li>\n<li>Finally, re-open your Arduino IDE<\/li>\n<\/ol>\n<h3>MFRC522 RFID reader pinout<\/h3>\n<p>The following table shows the reader pinout for a future reference:<\/p>\n<table>\n<tbody>\n<tr>\n<th>PIN<\/th>\n<th>WIRING TO ARDUINO UNO<\/th>\n<\/tr>\n<tr>\n<td>SDA<\/td>\n<td>Digital 10<\/td>\n<\/tr>\n<tr>\n<td>SCK<\/td>\n<td>Digital 13<\/td>\n<\/tr>\n<tr>\n<td>MOSI<\/td>\n<td>Digital 11<\/td>\n<\/tr>\n<tr>\n<td>MISO<\/td>\n<td>Digital 12<\/td>\n<\/tr>\n<tr>\n<td>IRQ<\/td>\n<td>Don&#8217;t connect<\/td>\n<\/tr>\n<tr>\n<td>GND<\/td>\n<td>GND<\/td>\n<\/tr>\n<tr>\n<td>RST<\/td>\n<td>Digital 9<\/td>\n<\/tr>\n<tr>\n<td>3.3V<\/td>\n<td>3.3V<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Note<\/strong>: different Arduino boards have different SPI pins. If you\u2019re using another Arduino board, check the Arduino\u00a0<a href=\"https:\/\/www.arduino.cc\/en\/Reference\/SPI\" target=\"_blank\" rel=\"noopener noreferrer\">documentation<\/a>.<\/p>\n<h2>SD card module<\/h2>\n<p>When a tag is read, its UID and time are saved on an SD card so that you can keep track of check ins. There are different ways to use an SD card with the Arduino. In this project we&#8217;re using the SD card module shown in figure below &#8211; it works with micro SD card.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-61739\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/sd-card-module.jpg?resize=700%2C282&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"700\" height=\"282\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/sd-card-module.jpg?w=700&amp;quality=100&amp;strip=all&amp;ssl=1 700w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/sd-card-module.jpg?resize=300%2C121&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/sd-card-module.jpg?resize=250%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 250w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/p>\n<p>There are different models from different suppliers, but they all work in a similar way, using the SPI communication protocol. To communicate with the SD card we&#8217;re going to use a library called\u00a0<strong>SD.h<\/strong>, that comes already installed in Arduino IDE by default.<\/p>\n<p>To learn more about the SD card module with the Arduino read:\u00a0<a href=\"https:\/\/randomnerdtutorials.com\/guide-to-sd-card-module-with-arduino\/\">Guide to SD Card Module with Arduino<\/a><\/p>\n<h3>SD card module pinout<\/h3>\n<p>The following table shows the SD card module pinout for a future reference:<\/p>\n<table id=\"tablepress-37\" role=\"grid\">\n<thead>\n<tr>\n<th>PIN<\/th>\n<th>WIRING TO ARDUINO UNO<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr role=\"row\">\n<td>VCC<\/td>\n<td>3.3V<\/td>\n<\/tr>\n<tr role=\"row\">\n<td>CS<\/td>\n<td>Digital 4<\/td>\n<\/tr>\n<tr>\n<td>MOSI<\/td>\n<td>Digital 11<\/td>\n<\/tr>\n<tr>\n<td>CLK<\/td>\n<td>Digital 13<\/td>\n<\/tr>\n<tr>\n<td>MISO<\/td>\n<td>Digital 12<\/td>\n<\/tr>\n<tr>\n<td>GND<\/td>\n<td>GND<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Note<\/strong>: different Arduino boards have different SPI pins. If you\u2019re using another Arduino board, check the Arduino\u00a0<a href=\"https:\/\/www.arduino.cc\/en\/Reference\/SPI\" target=\"_blank\" rel=\"noopener noreferrer\">documentation<\/a>.<\/p>\n<h3>Preparing the SD card<\/h3>\n<p>The first step when using the SD card module with Arduino is formatting the SD card as FAT16 or FAT32. Follow the instructions below.<\/p>\n<p><strong>1)<\/strong> To format the SD card, insert it in your computer. Go to <strong>My Computer<\/strong> and right click on the SD card. Select <strong>Format<\/strong> as shown in figure below.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-61731\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/format-SD-card-1.png?resize=431%2C573&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"431\" height=\"573\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/format-SD-card-1.png?w=431&amp;quality=100&amp;strip=all&amp;ssl=1 431w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/format-SD-card-1.png?resize=226%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 226w\" sizes=\"(max-width: 431px) 100vw, 431px\" \/><\/p>\n<p><strong>2)<\/strong> A new window pops up. Select <strong>FAT32<\/strong>,\u00a0press\u00a0<strong>Start<\/strong> to initialize the formatting process and follow the onscreen instructions.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-61732\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/format-SD-card-2.png?resize=254%2C463&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"254\" height=\"463\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/format-SD-card-2.png?w=254&amp;quality=100&amp;strip=all&amp;ssl=1 254w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/format-SD-card-2.png?resize=165%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 165w\" sizes=\"(max-width: 254px) 100vw, 254px\" \/><\/p>\n<h3>Testing the SD card module<\/h3>\n<p><em>(This step is optional. This is an additional step to make sure the SD card module is working properly.)<\/em><\/p>\n<p>Insert the formatted SD card in the SD card module.<\/p>\n<p>Connect the SD card module to the Arduino as shown in the circuit schematics below or check the pinout table.<img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-61738\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/sd-card-adaptor-fritzing_bb-768x500.png?resize=768%2C500&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"768\" height=\"500\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/sd-card-adaptor-fritzing_bb-768x500.png?resize=768%2C500&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/sd-card-adaptor-fritzing_bb-768x500.png?resize=300%2C195&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/p>\n<p><em><strong>Note:<\/strong> depending on the module you\u2019re using, the pins may be placed in a different location.<\/em><\/p>\n<h3>Uploading CardInfo sketch<\/h3>\n<p>To make sure everything is wired correctly and the SD card is working properly, in the Arduino IDE window go to <strong>File<\/strong>&gt; <strong>Examples<\/strong> &gt; <strong>SD<\/strong> &gt; <strong>CardInfo<\/strong>.<\/p>\n<p>Upload the code to your Arduino board. Make sure you have the right board and COM port selected.<\/p>\n<p>Open the Serial Monitor at a baud rate of <strong>9600<\/strong> and the SD card information will be displayed. If everything is working properly you&#8217;ll see a similar message on the serial monitor.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-61727\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/card-info.png?resize=551%2C349&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"551\" height=\"349\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/card-info.png?w=551&amp;quality=100&amp;strip=all&amp;ssl=1 551w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/card-info.png?resize=300%2C190&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 551px) 100vw, 551px\" \/><\/p>\n<h2>RTC (Real Time Clock) module<\/h2>\n<p>To keep track of time, we&#8217;re using the SD1307 RTC module.\u00a0However, this project works just fine with the DS3231, which is very similar. One main difference between them is the accuracy. The DS3231 is much more accurate than the DS1307. The figure below shows the SD1307 model.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-61737\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/rtc-front-and-back-view.png?resize=515%2C247&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"515\" height=\"247\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/rtc-front-and-back-view.png?w=515&amp;quality=100&amp;strip=all&amp;ssl=1 515w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/rtc-front-and-back-view.png?resize=300%2C144&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 515px) 100vw, 515px\" \/><\/p>\n<p>The module has a backup battery installed. This allows the module to retain the time, even when it\u2019s not being powered up.<\/p>\n<p>This module uses I2C communication and we&#8217;ll use the <strong>RTCLib.h<\/strong> library to read the time from the RTC.<\/p>\n<p>To learn more about the DS1307 real time clock with the Arduino read:\u00a0<a href=\"https:\/\/randomnerdtutorials.com\/guide-for-real-time-clock-rtc-module-with-arduino-ds1307-and-ds3231\/\">Guide for Real Time Clock (RTC) Module with Arduino (DS1307 and DS3231)<\/a><\/p>\n<h3>RTC module pinout<\/h3>\n<p>The following table shows the RTC module pinout for a future reference:<\/p>\n<table id=\"tablepress-38\" role=\"grid\">\n<thead>\n<tr>\n<th>PIN<\/th>\n<th>WIRING TO ARDUINO UNO<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>SCL<\/td>\n<td>A5<\/td>\n<\/tr>\n<tr>\n<td>SDA<\/td>\n<td>A4<\/td>\n<\/tr>\n<tr>\n<td>VCC<\/td>\n<td>5V (check your module datasheet)<\/td>\n<\/tr>\n<tr>\n<td>GND<\/td>\n<td>GND<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Note<\/strong>: different Arduino boards have different I2C pins. If you\u2019re using another Arduino board, check the Arduino\u00a0<a href=\"https:\/\/www.arduino.cc\/en\/Reference\/Wire\" target=\"_blank\" rel=\"noopener noreferrer\">documentation<\/a>.<\/p>\n<h3>Installing the RTCLib library<\/h3>\n<p>To install the <strong>RTCLib.h<\/strong> go to \u00a0<strong>Sketch<\/strong> &gt; <strong>Include library<\/strong> &gt; <strong>Manage libraries<\/strong> and search for <strong>RTCLib<\/strong> or follow the next steps:<\/p>\n<ol>\n<li><a href=\"https:\/\/github.com\/adafruit\/RTClib\/archive\/master.zip\" target=\"_blank\" rel=\"noopener noreferrer\">Click here to download the RTCLib library<\/a>. You should have a .zip folder in your Downloads folder.<\/li>\n<li>Unzip the .zip folder and you should get\u00a0<strong>RTCLib-master<\/strong>\u00a0folder<\/li>\n<li>Rename your folder from <del><strong>RTCLib-master<\/strong><\/del>\u00a0to <strong>RTCLib<\/strong><\/li>\n<li>Move the <strong>RTCLib<\/strong> folder to your Arduino IDE installation libraries folder<\/li>\n<li>Finally, re-open your Arduino IDE<\/li>\n<\/ol>\n<h2>Schematics<\/h2>\n<p>The circuit for this project is shown in the circuit schematics below.<\/p>\n<p><strong>In this circuit there are 3.3V and 5V devices, make sure you wire them correctly.<\/strong> Also, if you&#8217;re using different modules, check the recommend voltage before powering the circuit. Wire one module at a time and follow the pinout tables if needed.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-61734\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/RFID-authentication_bb-995x1024.png?resize=995%2C1024&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"995\" height=\"1024\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/RFID-authentication_bb-995x1024.png?resize=995%2C1024&amp;quality=100&amp;strip=all&amp;ssl=1 995w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/RFID-authentication_bb-995x1024.png?resize=292%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 292w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/RFID-authentication_bb-995x1024.png?resize=768%2C790&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 995px) 100vw, 995px\" \/><\/p>\n<p>Here&#8217;s how your circuit should look like after assembling.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-61728\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/circuit.jpg?resize=700%2C376&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"700\" height=\"376\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/circuit.jpg?w=700&amp;quality=100&amp;strip=all&amp;ssl=1 700w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/circuit.jpg?resize=300%2C161&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/circuit.jpg?resize=280%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 280w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/p>\n<h2>Code<\/h2>\n<p>Upload the following code to your Arduino. Make sure you have the right Board and COM Port selected.<\/p>\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\n * Rui Santos \n * Complete Project Details http:\/\/randomnerdtutorials.com\n *\/\n\n#include &lt;MFRC522.h&gt; \/\/ for the RFID\n#include &lt;SPI.h&gt; \/\/ for the RFID and SD card module\n#include &lt;SD.h&gt; \/\/ for the SD card\n#include &lt;RTClib.h&gt; \/\/ for the RTC\n\n\/\/ define pins for RFID\n#define CS_RFID 10\n#define RST_RFID 9\n\/\/ define select pin for SD card module\n#define CS_SD 4 \n\n\/\/ Create a file to store the data\nFile myFile;\n\n\/\/ Instance of the class for RFID\nMFRC522 rfid(CS_RFID, RST_RFID); \n\n\/\/ Variable to hold the tag's UID\nString uidString;\n\n\/\/ Instance of the class for RTC\nRTC_DS1307 rtc;\n\n\/\/ Define check in time\nconst int checkInHour = 9;\nconst int checkInMinute = 5;\n\n\/\/Variable to hold user check in\nint userCheckInHour;\nint userCheckInMinute;\n\n\/\/ Pins for LEDs and buzzer\nconst int redLED = 6;\nconst int greenLED = 7;\nconst int buzzer = 5;\n\nvoid setup() {\n  \n  \/\/ Set LEDs and buzzer as outputs\n  pinMode(redLED, OUTPUT);  \n  pinMode(greenLED, OUTPUT);\n  pinMode(buzzer, OUTPUT);\n  \n  \/\/ Init Serial port\n  Serial.begin(9600);\n  while(!Serial); \/\/ for Leonardo\/Micro\/Zero\n  \n  \/\/ Init SPI bus\n  SPI.begin(); \n  \/\/ Init MFRC522 \n  rfid.PCD_Init(); \n\n  \/\/ Setup for the SD card\n  Serial.print(&quot;Initializing SD card...&quot;);\n  if(!SD.begin(CS_SD)) {\n    Serial.println(&quot;initialization failed!&quot;);\n    return;\n  }\n  Serial.println(&quot;initialization done.&quot;);\n\n  \/\/ Setup for the RTC  \n  if(!rtc.begin()) {\n    Serial.println(&quot;Couldn't find RTC&quot;);\n    while(1);\n  }\n  else {\n    \/\/ following line sets the RTC to the date &amp; time this sketch was compiled\n    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));\n  }\n  if(!rtc.isrunning()) {\n    Serial.println(&quot;RTC is NOT running!&quot;);\n  }\n}\n\nvoid loop() {\n  \/\/look for new cards\n  if(rfid.PICC_IsNewCardPresent()) {\n    readRFID();\n    logCard();\n    verifyCheckIn();\n  }\n  delay(10);\n}\n\nvoid readRFID() {\n  rfid.PICC_ReadCardSerial();\n  Serial.print(&quot;Tag UID: &quot;);\n  uidString = String(rfid.uid.uidByte[0]) + &quot; &quot; + String(rfid.uid.uidByte[1]) + &quot; &quot; + \n    String(rfid.uid.uidByte[2]) + &quot; &quot; + String(rfid.uid.uidByte[3]);\n  Serial.println(uidString);\n \n  \/\/ Sound the buzzer when a card is read\n  tone(buzzer, 2000); \n  delay(100);        \n  noTone(buzzer);\n  \n  delay(100);\n}\n\nvoid logCard() {\n  \/\/ Enables SD card chip select pin\n  digitalWrite(CS_SD,LOW);\n  \n  \/\/ Open file\n  myFile=SD.open(&quot;DATA.txt&quot;, FILE_WRITE);\n\n  \/\/ If the file opened ok, write to it\n  if (myFile) {\n    Serial.println(&quot;File opened ok&quot;);\n    myFile.print(uidString);\n    myFile.print(&quot;, &quot;);   \n    \n    \/\/ Save time on SD card\n    DateTime now = rtc.now();\n    myFile.print(now.year(), DEC);\n    myFile.print('\/');\n    myFile.print(now.month(), DEC);\n    myFile.print('\/');\n    myFile.print(now.day(), DEC);\n    myFile.print(',');\n    myFile.print(now.hour(), DEC);\n    myFile.print(':');\n    myFile.println(now.minute(), DEC);\n    \n    \/\/ Print time on Serial monitor\n    Serial.print(now.year(), DEC);\n    Serial.print('\/');\n    Serial.print(now.month(), DEC);\n    Serial.print('\/');\n    Serial.print(now.day(), DEC);\n    Serial.print(' ');\n    Serial.print(now.hour(), DEC);\n    Serial.print(':');\n    Serial.println(now.minute(), DEC);\n    Serial.println(&quot;sucessfully written on SD card&quot;);\n    myFile.close();\n\n    \/\/ Save check in time;\n    userCheckInHour = now.hour();\n    userCheckInMinute = now.minute();\n  }\n  else {\n    Serial.println(&quot;error opening data.txt&quot;);  \n  }\n  \/\/ Disables SD card chip select pin  \n  digitalWrite(CS_SD,HIGH);\n}\n\nvoid verifyCheckIn(){\n  if((userCheckInHour &lt; checkInHour)||((userCheckInHour==checkInHour) &amp;&amp; (userCheckInMinute &lt;= checkInMinute))){\n    digitalWrite(greenLED, HIGH);\n    delay(2000);\n    digitalWrite(greenLED,LOW);\n    Serial.println(&quot;You're welcome!&quot;);\n  }\n  else{\n    digitalWrite(redLED, HIGH);\n    delay(2000);\n    digitalWrite(redLED,LOW);\n    Serial.println(&quot;You are late...&quot;);\n  }\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Arduino-Projects\/raw\/master\/code\/25_Time_Attendance_System_with_RFID.ino\" target=\"_blank\">View raw code<\/a><\/p>\n<p><strong>Note:<\/strong>\u00a0double-check that you have the needed libraries installed.<\/p>\n<h3>Importing libraries<\/h3>\n<p>The code starts by importing the needed libraries. The <strong>MFRC522<\/strong> for the RFID reader, the <strong>SD<\/strong> for the SD card module and the <strong>RTClib<\/strong> for the RTC. You also include the <strong>SPI<\/strong> library for SPI communication with the RFID and SD card module.<\/p>\n<pre>#include &lt;MFRC522.h&gt; \/\/ for the RFID\r\n#include &lt;SPI.h&gt;     \/\/ for the RFID and SD card module\r\n#include &lt;SD.h&gt;      \/\/ for the SD card\r\n#include &lt;RTClib.h&gt;  \/\/ for the RTC<\/pre>\n<h3>Preparing RFID reader, SD card and RTC<\/h3>\n<p>Then, you define the pins for the RFID reader and the SD card module. For the RFID, the SCK pin (<strong>CS_RFID<\/strong>) is connected to pin 10 and the RST pin (<strong>RST_RFID<\/strong>) is connected to pin 9. For the SD card module, the Chip Select pin (<strong>CS_SD<\/strong>) is connected to pin 4.<\/p>\n<pre>\/\/ define pins for RFID\r\n#define CS_RFID 10\r\n#define RST_RFID 9\r\n\/\/ define chip select pin for SD card module\r\n#define CS_SD 4<\/pre>\n<p>You create a File called <strong>myFile<\/strong> to store your data.<\/p>\n<pre>File myFile;<\/pre>\n<p>Then, you create an instance for the RFID and for the RTC:<\/p>\n<pre>\/\/ Instance of the class for RFID\r\nMFRC522 rfid(CS_RFID, RST_RFID);\r\n\r\n\/\/ Instance of the class for RTC\r\nRTC_DS1307 rtc;<\/pre>\n<h3>Variables<\/h3>\n<p>You create a string variable <strong>uidString<\/strong> that holds the UID tags.<\/p>\n<pre>String uidString;<\/pre>\n<p>The following lines create variables to define the check in time hour and minute. In this case, we&#8217;re defining the check in hour to 9h05m AM. You can change the check in time by changing these values:<\/p>\n<pre>\/\/ Define check in time\r\nconst int checkInHour = 9;\r\nconst int checkInMinute = 5;<\/pre>\n<p>You also need to create variables to hold the user&#8217;s check in hour. These variables will save the hour a certain UID tag was read. The following variables hold the check in hour and the check in minute.<\/p>\n<pre>\/\/Variable to hold user check in\r\nint userCheckInHour;\r\nint userCheckInMinute;<\/pre>\n<p>Finally you attribute the pin numbers to the LEDs and buzzer.<\/p>\n<pre>\/\/ Pins for LEDs and buzzer\r\nconst int redLED = 6;\r\nconst int greenLED = 7;\r\nconst int buzzer = 5;<\/pre>\n<h3>setup()<\/h3>\n<p>Next, in the <strong>setup()<\/strong> you set the LEDs and buzzer as outputs.<\/p>\n<pre>\/\/ Set LEDs and buzzer as outputs\r\npinMode(redLED, OUTPUT);\r\npinMode(greenLED, OUTPUT);\r\npinMode(buzzer, OUTPUT);<\/pre>\n<p>After that, each module is initialed.<\/p>\n<h3>Functions<\/h3>\n<p>In this code you create 3 functions: <strong>readRFID()<\/strong>,\u00a0<strong>logCard() <\/strong>and<b>\u00a0<\/b><strong>verifyCheckIn().<\/strong><\/p>\n<p>The <strong>readRFID()<\/strong> function reads the tag UID, saves it in the <strong>uidString<\/strong> variable and displays it on the serial monitor. Also, when it reads the tag, the buzzer makes a beep sound.<\/p>\n<p>The <strong>logCard()<\/strong> function creates a file on your SD card called <strong>DATA.txt<\/strong>. You can edit the name of the file, if you want, on the following line.<\/p>\n<pre>myFile=SD.open(\"<strong>DATA.txt<\/strong>\", FILE_WRITE);<\/pre>\n<p>Then, it saves the <strong>uidString<\/strong> (that holds the UID of the tag) on the SD card and the current time.<\/p>\n<pre>myFile.print(uidString);<\/pre>\n<pre>\/\/ Save time on SD card\r\nDateTime now = rtc.now();\r\nmyFile.print(now.year(), DEC);\r\nmyFile.print('\/');\r\nmyFile.print(now.month(), DEC);\r\nmyFile.print('\/');\r\nmyFile.print(now.day(), DEC);\r\nmyFile.print(',');\r\nmyFile.print(now.hour(), DEC);\r\nmyFile.print(':');\r\nmyFile.print(now.minute(), DEC);<\/pre>\n<p>It also saves the user check In hour and minute in the following variables for further comparison with the predefined check in time.<\/p>\n<pre>userCheckInHour = now.hour();\r\nuserCheckInMinute = now.minute();<\/pre>\n<p>The <strong>verifyCheckIn()<\/strong> function simply compares the user check in time with the predefined check in hour and gives feedback accordingly. If the user is late, the red LED lights up; if the user is on time, the green LED lights up.<\/p>\n<h3>loop()<\/h3>\n<p>After studying the created functions, the<strong> loop()<\/strong> is pretty straightforward to understand.<\/p>\n<p>First, the code checks if an RFID tag was swiped. If yes, it will read the RFID UID, log the UID and the time into the SD card, and then it will give feedback to the user by lighting up one of the LEDs.<\/p>\n<h2>Grabbing the SD Card data<\/h2>\n<p>To check the data saved on the SD card, remove it from the SD card module and insert it on your computer.<\/p>\n<p>Open the SD card folder and you should have a file called DATA.txt.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-61729\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/datafile.png?resize=73%2C108&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"73\" height=\"108\" \/><\/p>\n<p>Open the file using a text editor. You&#8217;ll have something as follows:<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-61730\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/data-saved-1.png?resize=501%2C257&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"501\" height=\"257\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/data-saved-1.png?w=501&amp;quality=100&amp;strip=all&amp;ssl=1 501w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/data-saved-1.png?resize=300%2C154&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 501px) 100vw, 501px\" \/><\/p>\n<p>Notice that each value is separated by commas. This makes it easier if you want to import this data to Excel, Google Sheets, or other data processing software.<\/p>\n<h2>Wrapping up<\/h2>\n<p>In this project you&#8217;ve learned how to use an RFID card reader and the SD card module with Arduino. You can modify this project to your own needs or you can use the functions created here in other projects that require data logging or reading RFID tags.<\/p>\n<p>You can take this project further and add a display to give extra feedback to the user. You can associate a name with each UID and display the user name when the tag is read. You may want to take a look at some tutorials with the Arduino using displays:<\/p>\n<ul>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/guide-for-oled-display-with-arduino\/\" target=\"_blank\" rel=\"noopener noreferrer\">Guide for 0.96 inch OLED Display with Arduino<\/a><\/li>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/nextion-display-with-arduino-getting-started\/\" target=\"_blank\" rel=\"noopener noreferrer\">Nextion Display with Arduino \u2013 Getting Started<\/a><\/li>\n<\/ul>\n<p>This is an excerpt from our course &#8220;<a href=\"https:\/\/randomnerdtutorials.com\/arduino-step-by-step-projects\/\">Arduino Step-by-step Projects<\/a>&#8220;. If you like Arduino and you want to make more projects, we recommend downloading our course: <strong><a href=\"https:\/\/randomnerdtutorials.com\/arduino-step-by-step-projects\/\">Arduino Step-by-step Projects<\/a><\/strong>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this project you&#8217;re going to build a time attendance system with MFRC522 RFID Reader and Arduino. When you swipe an RFID tag next to the RFID reader, it saves &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Arduino Time Attendance System with RFID\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/arduino-time-attendance-system-with-rfid\/#more-61725\" aria-label=\"Read more about Arduino Time Attendance System with RFID\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":62339,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[303,2,267,264,10],"tags":[],"class_list":["post-61725","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-0-arduino","category-arduino","category-arduino-project","category-project","category-a-tutorials"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/time-attendance-system-thumbnail.jpg?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/61725","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=61725"}],"version-history":[{"count":0,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/61725\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/62339"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=61725"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=61725"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=61725"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}