 In this video, we're going to build our own RFID door lock system. I'll show you how to build it yourself, how to wire it all up, and how to write the code to make it work. In the last couple of videos, we went over how RFID works and how to use it. We also went over how servos work and how to use those. And in the RFID video, I mentioned that an RFID sensor can be used on door locks. So you would scan a key, the door would unlock, you could scan it again, you would lock the door, etc. And people seem to be really interested in seeing a project like that. So that's exactly what we're going to build today. The goal is to combine the RFID reader and the servo together to make a door lock that opens or closes depending on the tag being used. One thing before we get started is if you enjoy these type of videos, all you got to do to support is watch all the way to the end. And if you'd like, subscribe to the channel to get notified when these things are posted. If you're not exactly sure on how RFID or servos work, I'm going to recommend that you go into the description and watch the two videos where we went through how these work, how to write the code for them, how to wire them all up, what everything does, and how to make it work on your own projects at home. If you watch those, whatever we're going to do in this video is going to make a lot more sense and be easier to follow. If you don't know how RFID sensors work or how servos work, I'm going to recommend that you go to the description and watch the two videos that we made on these two things. It's going to make it a lot easier to follow along in this video and understand how these things work and what they do. To get started, we're going to need a couple different things. We're going to need our RFID reader, a microcontroller, a servo, and then I added this thing right here. It's kind of like an LED bar. It's just three LEDs, one red, one yellow, one green. I'm hoping we can do maybe green for when the door is being open, red when it's being closed, and something for yellow in the middle. Just something to display information so we don't have to look at a computer or guess if the card is working or not. Since this is a demo video, we're not actually going to take apart my real life door and start putting electronics in it. That's way too complicated. We're just going to build our own little demo here so we can show you how everything works on this table. So I 3D designed a little door here, and then I 3D designed a wall around it right there. It's going to hold our LEDs, our RFID reader, it's going to have a door, and then a hole for the servo to go into, and then kind of a little locking mechanism over here. After about a day of printing, this is what we're left with. We have our little door here that still needs to be processed. We need to remove some stuff off of it. And then we have our wall and our little servo that I was just testing to see if it fits. So the idea is the door would go in here like this, and then the servo can close and lock in the door like that, and then our LEDs would go through here, and the RFID reader would go through there. So everything can be displayed in the front. The lights I'm going to have to put something like this. This is just a little demo to show you how everything works. To get started, let's just clean up the prints first. So when you print things that have supports, we're just going to do this right here. That's gone. So that's what the door looks like. It's kind of hard to see on the camera, but there's kind of this ledge that comes off here. On this side, it's just an empty door. And then over here, we have the hinges that are going to go inside of our thing here. So ideally, it would kind of fit like this. And that's what the door looks like. So you can just open it and close it. But if the servo was to lock it, it shouldn't open. We can install the LEDs since that's going to be super easy, just like that. So the LEDs are installed, RFID is installed. And I'm guessing now we're just going to have to finish off the servo and make sure it's mounted nice. So here's what the final build looks like. We've got our LEDs up here, our RFID reader right here, and our servo right here. And when you flip it over, this is the door side, I guess, or the outside. Flip it over. We've got our little servo here, which is going to lock behind this door, which can't be opened or closed. We have our RFID reader, which was bolted in here, and then our LED. For the wiring, I'm going to put a picture up on the screen. Just pause the video here if you want and just do all the connections or you can follow along with me. For the servo, we have a three pin cable. We're going to be putting, in our case, the orange, which is the signal control in digital pin number three on the Arduino. Then the red and the brown or the red and the black will be going into five volt and ground. For this little LED panel, we have four pins. That's because we're connecting the grounds of all the lights together and then we're just setting a individual power line to each one. So you can kind of make this on your own if you don't have the same one as me. Anyways, in my case, we got three LED cables, one ground, so each LED cable is going to go into digital pin and ground is going to go into ground. For red, we're going to put it in number five, yellow number six and green number seven. So green was number seven. That's right here. Then we have yellow, which is going to go into number six. Then we have our red, which is going to go into number five. And then our black, which is going to go into ground. Now we need to plug in our RFID reader, which we've done before in previous videos. And there's a lot of cables we're going to have to do for this. It's also going to be a little bit hard because we have to read which pin is what. Starting with SDA. SDA is going to be going into digital pin number 10. After that, we're going to have our SCK. SCK is going to plug into digital pin number 13. Then we have MOSI, which is plugging into digital pin 11. After that, we have MISO, which is plugging into digital pin 12. Then we're going to skip IRQ and we're going to go straight to the ground pin. Ground is obviously going to go into ground. We're going to have to use all the grounds on this Arduino board. Hopefully we don't have to mix them together. RST is going to go into number nine. Slide that through. And then the last one is our power, which is going to be the 3.3 volt pin right over here, next to the five volt pin, next to the two grounds. So now we connected up our LED bar or servo and the RFID reader and we're ready to start with the code. You can see we're getting power on the RFID board. That's why the LED where my finger is is turning on. The first thing you need to do is declare your library as you're going to be using. If you haven't done this before, like in the videos that I sent earlier, you're going to need to go over here in library manager and go and download all these. After that, we're going to declare the pins for the RFID reader and we're going to make an RFID reader object. After that, we're going to do the same thing for the servo. We're going to make a servo variable. And then down here, we're going to set our LED lights. Then one thing we need to do is do a Boolean variable, which is going to hold true or false and that's going to tell us if the door is locked or unlocked. In the setup, we're going to need to open up a serial monitor we're going to activate SPI, we're going to activate our RFID reader and do the same thing with the servo. Then down here, we're telling the Arduino that this is an output pin, output pin, output pin for the three LEDs that we connected. So we're going to be outputting data or outputting electricity, which is going to be turning on those LEDs. Now for the loop, I kind of have an idea on how I want this to work. I want it to constantly check for a card. While it's listening for a card, I want the yellow LED to flash yellow. Then when you scan the card, I want it to go either into the green or into the red. Green meaning your card is good, you're welcome to come inside, unlock the door and door moves. But if it's the wrong card, I want it to flash red and then I want that door to stay locked. So just like we did in the RFID video, we first have to check any information off of the RFID sensor. So we're checking for an RFID card. Once we do that and we actually capture the card, we're going to move it to uppercase. In the if statement, we're going to do a couple of different things. First off, we're going to take the card UID that we just turned to uppercase and we're going to check if that equals this. This is where you would put your specific card identification number so that when you scan a card, you would be checking if it equals that. If that's true, we're going to open up the door, we're going to show the green LED, we're going to move the servo and we're going to put a delay and then we're going to lock it after. And then down here, we're going to show the green LED again. So you kind of have a two second thing to open the door and then the lock will go down. If your card that you scan does not match the card that you put down as your authentication card, you're going to get shown a red LED, a little bit of a delay, a red LED again, and then that's it, the door will not open. Now, if the door is locked and we're waiting for a card, we're just going to flash the yellow LED on and off, on and off just so we know that the program is working and we're not just staring at a blank piece of plastic or a door. Just something that tells us the program is running. If we ever see that a yellow LED is not flashing, is not on, anything but flashing, we know something is wrong with electronic. That's pretty much it for the code, but before we run this, I do want to check what my card is because I do not remember, I have a tag over here and I don't remember what the code is off this tag. So we're going to read it quick, we're going to check what it is and we're going to copy paste it and put it in the authorized section. So we go down to MFRC in our examples and we're just going to read, I think it was the dump info. We're just going to read the dump info in the console. So we're going to connect our Arduino board, we're going to upload the code to the board and then we're going to open up our serial monitor right here. Clear that out. Now I should be able to put the card there and let it scan and we can see card UID 90954C58. So now if any tag we scan doesn't match 90954C58, this door should never unlock and we should get a red light that starts to flash. Also the servo is currently open and I'm not sure if there's any code. I don't remember if we wrote any code to make sure that it's closed. Cause we could see here, we write servo write 90, open door and then back to zero. So it's assuming it's at zero. So one thing I would like to do is grab this and in our setup here, we did do it. We're going to put the door at zero. The thing is zero is probably going to keep it open. So if I flip it over, this is probably zero and then this is probably 90. So we might have to reverse those. Let's see what happens. So I'll leave it upside down like that. Or actually we'll leave it upright. We'll look at the LEDs first. We're going to upload that to the Arduino board. Well, that goal is that these LEDs up here will start flashing. Oh, no port provided. We've got to select our board. Let's try that again. Oh, there we go. We have a yellow flashing LED in the middle. And if we flip it over, our servo is at what it thinks is zero. Now let's try and set the servo and maybe, I don't know, 60 just so we can get it nice and centered. I think 60 might even be too much. I'm going to lower that down a little bit. Perfect. So now you can see that if I take my finger and try to open the door, it's currently locked. Obviously it's not the best, but it's locked. I cannot open the door technically. And we have a yellow flashing light. Let's see what happens when we take our card and we put it on that scanner. Actually, let me see. I think this card I have here shouldn't work. So we're going to take that, put that over there. Oh, look at that. We're getting red. Put that again. We're getting red. So our security system is working. We know that if we put a card, it isn't the right card. We're getting red. Every time we're getting red and every time I push the door, it's staying locked. Now let's take that key tag. Let's put it on there. Oh, we got red again. So maybe we did something wrong over here. Also, we do have to change this to zero. I forgot to do that. So 90, 95, 4C58 was what we got for this tag. I wonder why it didn't work. Okay, maybe we missed something. So let's go to our serial monitor. So we're just going to add serial dot print line card UID and I'm just going to tap the card and we're going to see what is coming through. Oh, so it doesn't put spaces and we put spaces up here. Okay, so that's simple fix. Okay, upload that to the board. Now let's take our tag. The wrong one doesn't work. We see red, we see red. Now we're taking the right one. We can see that now the door opens. Now our servo auto locks, which is probably not the best feature. So we're just going to go and take our tag and scan it and that servo is not going to go back to its position. So we do have to fix that in the code to make sure the servo closes on the next tab. Okay, that was weird. I'm not sure why, but for some reason my RFID scanner just stopped working. I kind of feel like this metal tag might have shorted it. So I'm going to try not to touch it on there, but let's give it one more try. So click on serial monitor, clear that. We should see green. Okay, nice, we're back. And now the door is unlocked. And now because we don't have the code to fix it, we have to restart the program, which will lock the servo and then re-scan the card. Let me see if I can bring this. So now we have everything working. We have our light that flashes when the system is on. And then we have our card reader and servo connected together. So when we take a card that is not valid and we scan it on there, we see that we get red. Scan it again, get red. And if we go to open our door, it's locked. But if we take a key tag that should work, put it on there, we get green. And now our door, even though it's super tight, opens. Then we just put the door back. And then in our case, because we don't have the code yet, we just restart the program and now our door is locked once again. And I guess that's it for the RFID door lock. I hope this video helped you out. I hope it showed you a cool way to connect these two things together to make a project. If you like this kind of stuff where we kind of make bigger projects and not just boring sensors every day, let me know in the comments so that I can start making more of these. If you have any questions or things you wanna ask, let me know in the comments and then check out the Discord where we have people that can help you with your electronics problems. I guess that's it for this one. Like the video if you like the video and I guess I'll see you tomorrow.