 This is an RFID scanner and reader. It allows us to give labels to things that might not have an electronic label. For example, when you go into the gym, you have these little key tags you scan, and the gym knows who's coming in and out, or the same thing with key cards when you're going in and out of the office building. RFID technology lets us do that and in today's video we're going to go over how it works, how to set it up, and how to write the code for it so that you can be using it in your own project. RFID is like a high-tech way of identifying and tracking things using radio waves. It all begins with these nifty little tags or cards. Think of them like mini computers, really really small computers, and each tag has a special identification number, just like your own name. This identification number is unique to every one of these tags, so nothing in this picture should have the same tags. The first one, the second one, and the third one should all have unique tags. To interact with these unique identification numbers, you're going to need something to read off of these tags or off these cards, and that's where our RFID reader and writer comes in. When you bring out one of those tags or cards close to the RFID reader, it's like waking up the tag's mini computer. How? Well, the reader sends out those radio waves, and that's intercepted by our key tag. And since our key tag doesn't have any battery or any type of power source in it, it's using those radio frequencies to power it. Then when our tag's mini computer gets powered up by these radio waves, it goes, hey, I'm here, my name is, and then identification number. And all that is being read by the reader. So now because they're close to each other, they can kind of communicate between the two. Like I said, there's no power supply in these, so this key card right here has nothing in it that supplies power. Same thing with this key tag. All this collected info can then be sent to a computer database to check for matches or store any data relating to that identification number. So if you're wondering in places where we would be using this technology, it's like when you go to the gym, you scan, and then we keep track of who's coming in and out when they come in, how many days they'll have left before their plan runs out, all that information comes back from this tag. And this tag is how we keep track of your movements in and out of certain spots. A lot of the time with secure or government buildings, you have these RFID cards with your name on them, whatever, and you scan them to get into parts of the building. That's because we have an identification number on this card to figure out who's scanning it. So that identification number kind of becomes your name in the system, or at least a link to it. And that's pretty much RFID technology in a nutshell. We're giving these tags their own unique names and then using radio waves to have a chat with them and figure out who they are. Now we're just going to wire up our reader to our microcontroller we're using an Arduino board. So we're just going to need a couple cables for all the pins on the back. And then after that we can get started with the code. To keep the wiring simple, I'm going to put up a picture on the screen of the pinout, which tells you which port to use on the microcontroller and where to plug that in on your sensor and vice versa. If you're not using an Arduino, just Google the pinout for your microcontroller, but it's going to be the same type of code and everything. Just make sure you're using the right pins on your specific board. So in our case, in our case, we go SDA, SCC. In our case, we go SDA, SCK, MOSI, MISO. I think that one is IRQ. Then ground RST and 3.3 volt. We're not going to be using IRQ. So I'm just going to go in mine. Let's start with the easy ones. We're going to go with 3.3 volts and that's going to go into the 3.3 volt port on the microcontroller. After that, we have RST, which goes into digital nine. Next up, looks like we have our ground. That's just going to go into the ground port right next to the 3.3 volt port. After that, we have IRQ, which we're not using. And then after that, we have MISO, M-I-S-O. That's going into 12. So just going to grab the MISO, plug it into number 12. After that, we have MOSI. So I guess MOSI, MISO, I don't know. So MOSI goes into 11. After that, we have SCK, which is going to go into 13. And then we have one last to plug in, which is our SDA. And that's going to go into number 10. Let's just go over everything. Make sure you're using 3.3 volts. That's what it's rated for. That's what you need to use. Don't try and sneak around and use 5 volts. That can fry your board or just make everything not work. All right, let's plug it into the computer and we can get started with the code to make this thing work. To get started, we're going to have to import two different libraries that we're going to have to go and download since I don't have them on my computer. So we're just going to go into the library manager, type in SPI. And then I guess I have it installed already, the Adafruit one. Then we need to go and get MFRC522. And I'm pretty sure this is the one we have to install. We'll see in a minute when we try the code. So just install that and you should be good to go. Then we're just going to put three different things. We're going to declare our pins that we had earlier. So we have 10, 9, and then we're going to make our MFRC522 instance. Then we can go straight into the setup and start with serial.begin to display things in the serial monitor. SPI begin to initialize the SPI communication between Arduino and the reader. And then to initialize the RFID reader itself. Then we just put a simple little message in the console here that says, hold your card close to the reader. This is just a good way of letting you know that the reader itself is actually starting to read and listen to what's happening. So when you see that on the console, you know, okay, the program has started. This could be whatever you want. Then we go directly into our loop and we're going to put the first piece of code, which is just a little bit of logic to see if a new card is being scanned. This is a function within the instance of the new RFID reader that we made up. After that, we can do another one. And this time we're just going to check if we can read the information from the card. If we can't read any information from the card, maybe our scan wasn't good, maybe our card isn't good, something went wrong. So we're just going to exit that. Now the next part is going to get a little bit complicated and it's okay if you don't understand everything that's happening in here. This little piece of code, all it's going to do is just take our information from the card and write it out a bit cleaner, and then also store it in a little local storage that we're going to make over here. And because we do that, we can then write the second piece of code, which is going to uppercase our identification number. Then it's going to check if the new card ID that we just scanned up here, if that's going to be equal to this example one right here. Now let's say that equals this. So it's the right card. Let's say it's Mike's card and Mike scanned it. And we know now Mike is scanning a card. Then we can do the first piece of code right here, which is saying access granted welcome. Let's say I scan the card and it's not this one. The identification number does not equal BD31520, what is that? 2B. So if it doesn't equal that, it's going to skip this part of the code because it's an FL statement and then it's going to go down here and just say access denied unauthorized card. In here you could put whatever you want. You can put a door lock and when someone scans, if it's the right card, it unlocks the door. You can put a beer dispenser. You can have literally anything you want that you want to restrict to some people and open to others. You can use this kind of RFID technology with that code to make it work. You can also just use it to identify people. So if you want to know who's using something, like sometimes I think schools do this. They have a little card reader like this for the school printer and you just scan it on the school printer. And then when you use the printer, they know who printed 300 pictures of ELMA or whatever the fuck. Now we could run this right here, but none of the cards are going to be in the access granted welcome stage of the code because obviously this is a code that I just copied off of the internet. So one thing we could do is we go up here to file examples and then we got to look around until we see our, I think it was, what was it, MRC something, the library that we, this one, MFRC522. We're going to go in there and we're just going to see which one here is for reading. I think this one read ID. So we're going to open up that example. You can see this prewritten code. This is for every project we've ever done. If you go to file examples, you could find prewritten code if you're having issues with yours. And I'm pretty sure this one is just going to read out the card and print it to the console so we can give it a try. I'm just going to select my Arduino board and upload it to the board and I'm going to take this card right here and we'll see once it's done. We can open up our serial monitor and make sure it runs on the same thing using the following key. Okay, now what if I put this card close? Is it not scanning nothing? Okay, what if I put this close? Okay, so maybe this isn't the right one. Okay, so maybe we have a connection issue. Maybe that's why the previous one didn't work. Let's take a look. So back to that picture we had at the start. SDA goes into digital 10. In my case SDA is white and white is plugged into digital 10. SCK in my case is black and that's plugged into, ah, that's the problem. That was not plugged into the right port. Okay, so I guess it's human error in this case. We're going to reupload everything. We're going to open up a fresh serial monitor. Let's see what happens. Okay, now it seems to be working. See firmware version? We're on V2. So we're going to scan our card. Boom. And we can see here our card UID is 8201B951. So that's what this card is currently labeled as. That's its name. Oops. Then we have our two little gym tags here. We're going to try those out. So I'm just going to scroll down to the bottom. One thing I'm going to do and you should definitely do is copy paste this. So we're just going to copy that and we're going to go back into our original file that we wrote ourselves. And just for now I'll just do it like this. This is the card and then we'll read a gym card key tag. So that's our card. Let's go back into here. Scroll down to the bottom where you can clear it and scan one of our gym tags. DCFB822F. So now we're just going to copy paste this. I'm going to go into our original code that we wrote and we're going to paste it in there. So now we have our card ID and our key tag ID and we're going to use those over here. So we could go back over here. We can close this program. We don't need it anymore. And let's say right now I'm not looking at the camera. I'm going to mix up my two gym tags and we're going to use the RFID reader to figure out which one of these two tags is the one that we previously scanned. So we're just going to grab our key tag right here and you can use multiple of them. You just make this longer and add more. But I'm just going to use two. So that's our gym key tag. Let's upload this to the board. Open it up. No upload port provided. Maybe because of that. Just go to serial monitor. Clear the console. So I'm going to scan the first card that I picked randomly and we could see that's the right one. Now if I scan the other one, access denied. If I scan another one, access denied. And you can just keep going and, you know, I'm not even getting too close and probably like an inch away and it's still working. Now if I take the original one, access granted. Welcome. So that's how an RFID reader works. It uses radio waves to activate the little tiny computer inside of your key tags. And then by reading that information we can use it to identify, let's say in this case, three different individuals. I'm going to turn this video into two parts because it's very long. The first part is this one where we read off of these tags and then part two is going to be how do we write information to them. So what if someone has a key card and you don't want them to use it anymore and you want to change its name, you want to burn that ID and use a new one? That's what we're going to go over in part two, which is going to be the next video. If you enjoy this type of stuff, just do me a favor and give the video a like and subscribe to the channel because unfortunately that's the only way that you can support it. If you have any questions, anything that didn't make sense, anything that I maybe did wrong in this video, please let me know in the comments. And if you need help with your specific projects, we do have a discord channel with some people in there that can help you out with your stuff. I guess I'll see you in part two.