In this DIY Gadget build, we’ll be building a secure door entry system using a Raspberry Pi.
You already may be familiar with two-factor authentication for logging into secure systems like your online banking or your Facebook or email accounts. This door entry system goes one step further and uses THREE factor authentication. To unlock the door, you require;
- An RFID keyfob
- A 6-digit PIN
- A random one-time access code which is generated and sent as a text to your phone.
To build this project for yourself, you will need…
- A Raspberry Pi. I’m using a Raspberry Pi 3 with built in WiFi and a case which helps with protection and mounting in the wall
- A USB RFID reader. This one simply plugs in via USB and acts like a keyboard inputting the code from the RFID fobs and cards
- A touchscreen LCD for the Raspberry Pi.
- A GPIO expansion board
- A ribbon cable to attach the expansion board
- A female to male ribbon cable for attaching the touchscreen
- A 5V single channel relay switch
- An electronic door strike
- A computer power supply and power lead (to power both the Raspberry Pi and the Electronic Door Strike)
- Some dupont cables for attaching the relay switch
You’ll also need a few tools, so make sure you’ve got all of the following before you get started:
- A multimeter, for checking voltages
- Various sizes of screwdrivers
- Some wire strippers and wire cutters
- A soldering iron
- Some choc blocks, for connecting wires together
- A glue gun
- A cordless drill/screwdriver
- A jigsaw
Step 1: Install and Configure the LCD Touchscreen for the Raspberry PI
The very first thing we need to do is get our LCD touchscreen working. Depending on which model you purchase for your build, it may just come with drivers to install or it may come with its own Operating System image for you to write to your Raspberry Pi’s SD card. That’s the case with my one, so I need to use Win32 Disk Imager to write the image to my SD card. Make sure you select the correct device to write to, so you don’t accidentally erase any external hard drives!
Once that’s complete, pop the microSD card back into the Raspberry Pi and fit the LCD to the GPIO ports like this, starting at the top end which is by the SD card slot and away from the USB and ethernet ports. Next, take the microUSB power lead and plug it in to boot up the Rapsberry Pi to confirm that the screen – and the touchscreen element of it – are working correctly.
As you’d expect, the orientation of the display is in landscape as standard, but for our virtual keypad we want the display to be portrait so we need to change some config files to achieve this. With your Raspberry Pi connected to your network either via WiFi or an Ethernet cable, shell into it and open up the config.txt file inside the boot directory:
$ sudo nano /boot/config.txt
This file determines the orientation of the display. We’re looking for the line towards the bottom which contains “dtoverlay=waveshare35a” and to that we’re going to add a semicolon followed by “rotate=180”. Save and exit.
Next, we need to rotate the touchscreen to match the display, so we need to open up the “99 calibration” config file:
$ sudo nano /etc/X11/xorg.conf.d/99-calibration.conf
Inside this config file, we first need to change the SwapAxis option from one to zero, and then enter in the following base values for the Calibration options. Once you’ve done that, Save and Exit. Then, you can reboot your Pi, and once it boots back up your display should be rotated to portrait.
Step 2: Install MySQL Database & Apache Web Server on the Raspberry Pi
Whilst we’re in the shell, now’s as good a time as any to install the database, which will hold the access control list for our door entry system, as well as record a log of all successful and unsuccessful access attempts. We’ll install a full LAMP stack so that we can use phpMyAdmin to access the database, and this also means you can create your own web interface using PHP to add and delete users to the system easily in the future.
First off, we’ll install the Apache web server with this command:
$ sudo apt-get update $ sudo apt-get install apache2
Once that’s set up, we’ll install PHP, and then MySQL.
$ sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql $ sudo apt-get install mysql-server
As part of the MySQL server installation process it’ll ask you for a nice secure password for the “root” user, so enter one in and make sure you don’t forget it.
Finally, once MySQL is installed we’ll restart Apache and then install phpMyAdmin.
$ sudo service apache2 restart $ sudo apt-get install phpmyadmin php-mbstring php-gettext
As part of the installation process it’ll ask us which webserver we want to configure to use it, so make sure Apache is selected and select OK. We’ll allow phpMyAdmin to install and configure its own database automatically, and then enter the root password we chose when install MySQL to allow phpMyAdmin to create its own database and user. Next, we’ll create a secure password for that user.
Once that’s installed you can type your Pi’s IP address in your web browser, followed by “/phpmyadmin” and then login with the root account you created when installing MySQL.
Step 3: Install Python Script and Set up Database Tables
Now it’s time to install the Python script, which is like the glue that binds everything together. It receives the user input from both the keyfob and the touchscreen, it talks to the database to see who’s allowed access, and it uses Twilio to send a SMS to the user.
The Python script and blank database tables can be downloaded from GitHub at: https://github.com/paulfp/Three-Factor-Security-Door
Once you’ve imported the database file via phpMyAdmin you’ll see the database contains 3 tables. The first is called access_list and this table contains the details of everyone with access to the area secured by our locked door. Here you can see I’ve added a couple of users with their name, the RFID code number of their fob, their PIN and their mobile number for the SMS two-factor authorisation code to be sent to. We also include an image file so that the welcome screen can show a headshot. Make sure this is a GIF file and store it in the same directory as the Python script.
Second, we have an access_log table which records all attempts – successful and unsuccessful – to access the system. This records any RFID codes presented to the scanner, whether they were granted at the time, what PIN was entered, which mobile number a one-time code was sent to, and whether it was entered correctly etc. This logging information would be very useful in the real-world both for diagnosing problems with legitimate users accessing as well as gathering evidence of anyone trying to gain unauthorised access.
The last table contains our Twilio account details, which we use to send the text message which enables the final part of the authentication process before the door is momentarily unlocked allowing access to an authorised party.
With the Python script downloaded to the Raspberry Pi user’s /home directory, make sure you install all the dependencies required by the script.
Step 4: Make the Python Script Autoload when Your Raspberry Pi boots up
We need to make the script autoload whenever the Raspberry Pi starts up. To do this, we need to add a line to the autostart config file. Type this into your terminal:
sudo nano ~/.config/lxsession/LXDE-pi/autostart
Then add a line like this:
@sudo python lock.py
Save and exit.
Step 5: Connect GPIO Expansion Board and Relay Switch
With everything set up on our Pi, it’s now time to disconnect the screen and put the Pi into its protective case. To maintain access to the GPIO ports we use a short 26-pin female to male ribbon cable, and we also need to add in a GPIO expansion board, too. This is because the touchscreen LCD uses up some pins that we need to use in a moment for our relay, namely the 5V pins. If you prefer, you could also power the relay from another 5V plug from the power supply unit, instead. To connect the screen to the board we need another long ribbon cable, and you’ll need to carefully bend a couple of unused pins out of the way in order to make this fit. Then, connect the touchscreen and power up the Pi again just to make sure everything is still working.
The next step is to connect our relay to the GPIO ports. It’s a 5V relay, so the positive pin needs connecting with a dupont cable to a 5V pin on our GPIO expansion board, and the negative can of course go to any ground. The signal pin needs to go to any numbered GPIO pin, and make sure you choose one which isn’t in danger of also being used for anything by the touchscreen; as you can see, I went for Pin 13 here which is well out of the way.
Step 6: Connect RFID Reader and Test
Now it’s time to connect everything up, including the RFID reader, and see if it works! Take your RFID fob and hold it to the reader. It recognises that as me, and displays my name and photograph. I then enter my PIN, 1 2 3 4 5 6 and it then generates a random one-time access code to send to my phone as a text message.
As soon as I enter this code you’ll hear the “Click!” of the relay switch coming on, and after a few seconds it “clicks” again to turn off. Later on when we install this into our doorway, the relay switch will be connected to the electronic door strike so will unlock the door.
Step 7: Prepare Dual-Voltage (5V / 12V) Power Supply to power Raspberry Pi and Electronic Door Strike Simultaneously
Next up, we need to prepare our power supply to provide power both to the Raspberry Pi (which requires 5V) and to the door lock which requires 12V and is triggered using the relay switch. We want the whole system to be powered using just a single power lead, so we need a single power supply which can provide both 5V and 12V simultaneously, so we’re using a Desktop computer power supply.
At this point it seems prudent to point out that we’re about to be dealing with live electrical voltages. Low voltages, mind you, and not mains current – but the power supply itself does plug into the mains, obviously. Therefore, proceed at your own risk and only if you are confident and sure about what you’re doing. If you are in any doubt whatsoever, do not continue and instead consult an experienced, qualified and competent professional. I can accept no liability whatsoever for your actions! Got that? Right, as we were…
Step 7b: How to Make the ATX Power Supply Turn on When Not Connected to a Computer Motherboard
As you’ll know, computers don’t immediately turn on when you plug them in, even with the little switch on the power supply itself in the “on” position – you have to press the “On” button on the front of the computer tower first. Well, in this case we do want our power supply to turn on using just its own switch, so we need to do some electronic whizzardry. Of the myriad cables coming out of the PSU box, you’ll find just one green one; this is the signal cable and it needs to be permanently shorted-out to a black ground cable. Take the green cable and any black cable then snip them with a pair of scissors, then strip a short length from each end to expose the bare wires inside. Twist them together so they don’t fray, and then take a choc block and cut one from the end. Connect the green and black cables together and then test it works by plugging in the mains power and turning on the PSU. Yay, it works!
Now, we need to take one of the SATA power cables which usually provides 5V and 12V to a hard drive, and test the contacts with a multimeter to check which is which. Place your multimeter’s black contact on the black ground wire and then test both the yellow and red contacts to check which is which. As you can see, the yellow is giving us 12V, and the red is the 5V.
Chop off the SATA connector to reveal two pairs of cables; a 5V with ground, and a 12V with ground. Strip the ends off each wire, twist them to prevent fraying and then chop of a 4-way section of chocblocks. Connect the 4 cables into the chock blocks like so, giving us a handy source of both 5V and 12V power.
Step 8: Connect Raspberry Pi to Dual Voltage 5V Power Supply
Next, take the power supply which came with your Raspberry Pi. Although it’s a microUSB plug on the end, as it’s only supplying power and there’s no data transfer going on, the cable only has two cores; positive and negative. Snip the cable off the power supply and then separate the two cores for a couple of centimetres. Strip and twist the ends, and then look for the marking on the cable to determine which is the negative. If there aren’t any obvious markings, you’ll have to use your multimeter to do some detective work. Connect the USB power cable into the chocblock we just prepared, making sure you connect it to the 5V supply, which is red in my case.
We can check this works by connecting the power cable to our Raspberry Pi and then turning on our power supply unit. As you can see here, it works just great!
Step 9: Test & Connect Electronic Door Strike
Now it’s time to turn our attention to the electric door strike – this is the catch which sits in the door frame and is normally closed, so won’t allow the door to open unless 12V is supplied to the strike, in which case it allows itself to be opened, effectively unlocking the door.
If we open up the strike you can see the two very thin wires which were meant to be soldered to contacts on this black plastic top. On this one, the wires are so thin and flimsy that they’d broken off in transit, so to remedy this we’ll remove the black plastic clip holding the contacts and solder some longer pieces of wire on. We’ve got some handy as we just chopped it off the power supply, so let’s take a couple of lengths of wire from that, snip them and then strip and twist the ends.
Now it’s time to get your soldering iron out and tin the exposed ends of the wires with some solder before bringing over the door strike and soldering our new lengths of wire to the two very fragile exposed wires up top.
Now it’s time to test the door strike so let’s wire it directly into our 12V power supply that we created before and watch what happens when we switch on the power.
Step 10: Install Electronic Door Strike into Frame & Electronic Components into Wall
The door strike now needs to be installed into your doorway, in place of your existing Striker Plate. Here, I’m installing the system into this mock-up of a door frame that I’ve knocked together as a demo, so you’ll have to excuse the slightly shoddy woodwork! On mine, the electronics are going to be located within the stud wall, but make sure you comply with all building regulations for your region before continuing.
The first step is to drill a reasonably-sized hole to allow cables to be poked through the timber to the power supply which will sit below. Run the cables for our dual-voltage supply up the vertical beam and drill a small pilot hole through the centre of the choc block and then screw in place. Then, poke the USB power cable up through the hole to provide power to the Raspberry Pi. Next, we need to decide on the arrangement of our components within the stud wall, and I’m using a spare block of wood from a previous project to create a little platform onto which I can mount the GPIO expansion board. The relay switch will sit just here on the vertical beam, next to the electronic strike.
The Raspberry Pi’s case has mounting points on its base, so measure the distance between them and then transfer that measurement to the horizontal beam, marking two points to insert some small screws, nearly all the way down but not quite. With those in place, the Raspberry Pi can be placed on and slid back, holding firmly in place. The power cable reaches neatly to the socket, and can now be plugged in.
Step 11: Connect Up Relay Switch, Raspberry Pi & Electronic Door Strike
Secure the mounting block in place, and try not to split the wood like I did, oops! Drill a pilot hole if necessary to avoid that. Then, screw down the GPIO Expansion Board and secure the relay switch in place near the electronic strike. Next, wire in one of the cables directly from the door strike to the NORMALLY OPEN terminal on the relay. Either one will do, as it’s not a polarised component. Then connect a length of cable to the GROUND terminal, poke it through the hole we drilled and then connect it to the negative terminal of our dual voltage power supply. Finally, connect the door strike’s other wire to the 12V positive supply.
Step 12: Cut Holes in Wall for RFID Reader & LCD Touchscreen
Next we need to cut the holes in the wall to mount the RFID reader and the LCD touchscreen. I marked the holes out first on a cereal packet to get the placement just right, before using that as a guide to mark out the holes on the wall. Drill a hole in the centre of the area to be cut away, then use a jigsaw to cut out both squares. I used some insulation tape to make the edges look a bit neater on my demo unit, you can of course make yours look much better than mine!
To mount the RFID reader, I’m using some hot glue on the half of the front that doesn’t contain the infographic, and then pressing that up against the wall. I also used some gaffer tape to help secure it in place, as this USB model isn’t one which is specifically intended for wall mounting. I’m mounting my LCD in the same way, which isn’t ideal and I wouldn’t recommend this method in the real-world, but it should work just fine to demonstrate for this build.
Next, connect up the miniUSB cable to the RFID reader and boot up the Pi to test it’s working.
Now it’s just time for the finishing touches, so let’s use some blocks to hold the power supply in place, and then trim down the excess length on all of our cables. Carefully disconnect them one by one, cut to the appropriate length, strip and twist the ends and then reconnect. Then, use tacks to hold them neatly in place.
And we’re done! To summarise our build we have an electronic door strike which is activated by the relay switch here, which in turn is controlled by the output from our Raspberry Pi which denies or grants access using the RFID reader and touchscreen input. It also connects to the internet via WiFi to use a web service to send the one-time passcodes via SMS to the user’s phone, acting as THREE factor authentication. The whole thing is powered by a computer power supply which sits down here inside the wall
So there we are, a ridiculously secure door entry system for that most secret of rooms in your home or office. If you’re going to build one yourself, there are links at the start of this article for all the low-cost components you’ll need to buy, as well as a link to download my Python script to load onto your Raspberry Pi. Make sure you send me a picture or video of your working setup – I’m @paulfp on Twitter.
======
YouTube video description:
In this video Paul shows you how to build the ultimate door lock system, effectively turning your office or bedroom into a high-security vault! To be granted access and open the door, visitors will require not just two but THREE factors of authentication; an RFID keyfob, their unique PIN, and a one-time passcode sent to their phone via SMS. It’s all built using readily-available low-cost components built around a Raspberry Pi.
Build this project yourself! You’ll just need to buy the following components and tools…
Raspberry Pi 3 Complete Starter Kit
UK: http://amzn.to/2sdq9lK / http://ebay.to/2zmJIuO
US: http://amzn.to/2tgtXCB / http://ebay.to/2yiBfFq
Raspberry Pi touchscreen (4inch RPi LCD (A))
UK: http://amzn.to/2uIWWfl / http://ebay.to/2AuAlak
US: http://amzn.to/2tPEuW9 / http://ebay.to/2yiGkO1
USB RFID Reader & Tags
UK: http://amzn.to/2sikupH / http://ebay.to/2j8PCJt
US: http://amzn.to/2tgrqIM / http://ebay.to/2m7iWRY
5V Single Channel Relay Switch
UK: http://amzn.to/2udy92H / http://ebay.to/2Au2LB5
US: http://amzn.to/2si83dT / http://ebay.to/2zsEnlk
Electric Strike / Lock Release
UK: http://amzn.to/2udLpEG / http://ebay.to/2yGzENJ
US: http://amzn.to/2tSiMNR / http://ebay.to/2AllCNU
ATX Power Supply (for 5V & 12V supply)
UK: http://amzn.to/2tMe0ly / http://ebay.to/2zsbRy6
US: http://amzn.to/2uhKhnH / http://ebay.to/2heoWCO
Dupont Cables (Male to Male, Male to Female, Female to Female)
UK: http://amzn.to/2tM6Rll / http://ebay.to/2zmYXDV
US: http://amzn.to/2u8lPVn / http://ebay.to/2znSqc5
GPIO Expansion Board
UK: http://amzn.to/2tn1uYG / http://ebay.to/2hfmL2b
US: http://amzn.to/2vrwlEK / http://ebay.to/2AkNPV1
Multimeter
UK: http://amzn.to/2AtjMeD / http://ebay.to/2hmQ32h
US: http://amzn.to/2hntE50 / http://ebay.to/2hkHTHI
Precision Screwdriver Set
UK: http://amzn.to/2zGLlUF / http://ebay.to/2iEgs8F
US: http://amzn.to/2zsxWwu / http://ebay.to/2zs846e
Wire Strippers / Cutters / Crimpers
UK: http://amzn.to/2hfLaVn / http://ebay.to/2zmzcE3
US: http://amzn.to/2zsnxBb / http://ebay.to/2zEskCg
Soldering Iron
UK: http://amzn.to/2AslE7H / http://ebay.to/2he81jV
US: http://amzn.to/2AslOMl / http://ebay.to/2zsSG9w
Choc Blocks
UK: http://amzn.to/2jaN91e / http://ebay.to/2AtiEHR
US: http://amzn.to/2hpU5Hf / http://ebay.to/2AtxK0b
Glue Gun
UK: http://amzn.to/2tgUekp / http://ebay.to/2zr265r
US: http://amzn.to/2rXVi8C / http://ebay.to/2AkAwnr
Cordless Drill
UK: http://amzn.to/2AlnVR7 / http://ebay.to/2iEfRUo
US: http://amzn.to/2zGmHno / http://ebay.to/2hSuSCr
Jigsaw
UK: http://amzn.to/2AtqCRq / http://ebay.to/2zGBUVs
US: http://amzn.to/2hkwWGe / http://ebay.to/2j9ALi1
*** Config file paths ***
– Rotate Display: /boot/config.txt
– Rotate Touchscreen: /etc/X11/xorg.conf.d/99-calibration.conf
– Autoload Python Script on Bootup: ~/.config/lxsession/LXDE-pi/autostart
Download the Python Script and blank database file at https://github.com/paulfp/Three-Factor-Security-Door
Facebook – https://www.facebook.com/SwitchedOnNetwork/
Twitter – https://twitter.com/SwitchedOnNet
Instagram – https://www.instagram.com/switchedonnetwork/
Google+ – https://plus.google.com/112924836454795429890
YouTube Channel – https://www.youtube.com/SwitchedOnNetwork?sub_confirmation=1
Visit our website at https://www.switchedonnetwork.com/
What happens when the Pi crashes? It may take a few years but will happen be it a failed SD card or disturbance in the Force. At the very least you need a option to powercycle it from outside.
A very valid point 🙂 The electronic striker plate I used works with a standard Yale-style Nightlatch (which you’ll see towards the end of the video) allowing easy opening from the inside, but I just chose not to fit the keyhole bit on the front. Fitting that would give you an instant key override.
I guess to force a powercycle you could kill the power to it at the property’s fuse box, if that’s accessible. If this was being done for more than just a bit of fun, a full and proper assessment of all this stuff would be needed.
Thanks for commenting and I hope you enjoyed the video, please subscribe!
I suppose the ‘simple’ fix would be to put an Arduino in actual control of the lock looking to the Pi for instructions, if the Pi dies it could failover to a one factor authentication.
Love the project!
In an ideal world, I’d love to use a 2FA app such as Google Authenticator or Authy instead if using an SMS.
How would you recommend tailoring the project to achieve this? ?
Thanks, Dan
Yes, nice idea. There should be some guides and tutorials online for implementing those in Python, then just modify my code accordingly ?
can i ask , if the extension GPIO is 2 instead of 3 use in this video, can it work ?
also can i have the link for your raspbian image file thank you
Yes, you’ll be fine with an expansion board with only 2 additional rows. In fact that’s all that is required and would be slightly neater.
We don’t have a download link for the custom Raspbian image, as it’s bespoke to your specific LCD touchscreen so whichever one you buy will have a mini CD or maybe its own download link. If you buy the one we’ve linked in the video description it comes on a CD, or you can download the stock Raspbian image from the Raspberry Pi website.
Thanks for your comments and hope you enjoy the videos! 🙂
after changing the rotation of the screen, my pointer screen is opposite to what i touch. do u know why ?
Did you also change the orientation of the touch, too? Be sure to change the display rotation and the touch rotation (both config files).
for twilio account, do i have to insert their sdk ?
To use the code for this project as shared on GitHub, yes. You can install it using pip. For more info see this video: https://www.youtube.com/watch?v=knxlmCVFAZI
the programe for checking the token is not coming out. i’ve followed ur steps well, is there any command to run the file. ? i’ve put the github coding into the home file and run the code for its to run as soon the raspberry pi is boot
If you open the terminal and change into the directory where your python script is located, you can then type “python lock.py” (or whatever you’ve called your script) to run it manually. Any errors should show up in the terminal window, allowing you to debug as necessary. Ensure any dependencies that you need are installed, too.
Traceback (most recent call last):
File “lock.py”, line 3, in
import MySQLdb
ImportError: No module named MySQLdb
i got this error
You’ll need to install the MySQL module. I don’t have a guide on that, but if you Google it there are plenty online ?
i’ve run the code succesfully, but when i touch the rfid card, the face wont come out. i run the code in python3 . sorry for disturbing you
sir, how about import error: no module named ‘evdev’
Pay close attention to the text of the error message. In general terms, if the error message is complaining of a particular module being missing then the solution is to install that module. If you’re unsure how, Google this: “how to install evdev module for python on a raspberry pi” ?
sorry sir.. i already install “sudo apt-get install python-pip “and
“sudo pip install evdev “butthe lock.py script still showed importerror: no module named ‘evdev’ but then when i check the usb port by writting this code “python /usr/local/lib/python2.7/dist-packages/evdev/evtest.py” it show all the input device. Can you help me, sir
hye, if there are no module named ordered dict what should i do?
Hi! Really nice project! Congratulations!
My question would be how to implement a simple keycode that opens the door directly, so that you can use just the NFC card or the keycode insted of sending an SMS. Which part of the code should I avoid or change?
Thank you in advance!
Hey Miquel, thanks for your kind comments and glad you liked the project! Have you subscribed to the channel on YouTube yet? 🙂
If you want to remove the SMS part of the process, then in the codeInput function (which starts on line 196 of the code), remove the bits of code which go about sending the SMS (starting on line 228) and just skip straight to the unlocking the door (look at lines 293 onwards to see which lines to move into the codeInput function…)
That would make it 2-factor, ie you’d need the fob then the code. If you want fob OR code, then you’d have to do a bit more work to change the default waiting screen to have a code input, whilst also be listening for RFID. Then just set it up so either “trigger” fires the code to unlock the door. Don’t worry if that sounds daunting – have a really good read through the code and make sure you understand it fully and what it’s doing, then making changes will be simple 🙂 There are lots of good guides online for learning Python, and the GUI in use is Tkinter so you know what to Google 😉
Hey Paul!
Thank you so much for your fast replies!
I’ll try to do it, cause I want to base my degree project on that.
Also, I was wondering if it’d be any difference on using a GPIO RFID Sensor, instead of using a built-in USB one. Would that change the code?
Thank you very much!
Already subscribed to the Youtube channel, by the way! ?
Great stuff! I’m excited to see your degree project so do post more when you can ?
Yes, you could use a GPIO RFID reader instead. Look up RC522 for more info. It would fundamentally change that part of the code, though, so bear that in mind. There will, of course, be pros and cons so in your use case it may well be beyter!
Hey Paul! How are you?
First of all, thank you so much for the help you’ve given to me during the last coments! I really appreciate it!
I’ve been working on the project for the last weeks. It’s quite hard for me to separate the autentication factors, so I think that I’ll have to deal with it… This is what I have now:
2-Factor autentication, fully working. I was able to remove all the SMS part in the code and also in the data base. So everything’s working great!
Since I’m working on it exhaustively, I’ve noticed 2 things that are not working properly, even using the original code:
– When you use the RFID card and you are in the PIN CODE Entry step, If you try to use the RFID card again, it just breaks. The objects are mixed and the GUI interface stops working properly til the next execution of the script.
– I tried to add an image in the main page ‘WelcomeLabel’ (Also tried at the end of the script, when the acces is granted.), by using the same syntax that is used for the user image:
self.image = tk.PhotoImage(file=”rfid.gif”)
self.photoLabel = ttk.Label(self.tk, image=self.image)
self.photoLabel.grid(columnspan=1)
The image is shown properly, but once you use the RFID card to acces to the next step, everything is mixed up.
I tried to look for the “screen clear/destroy frame” syntax for python. Apparently, it’s already used with the .grid and .grid_forget method! But the frame is not being cleared properly!
Could you please help me or give me a piece of advice about that?
Once I finish the project, I’ll make a video to present it in my university. I’ll be happy to send it to you, if you wish!
Thank you so much in advance!
Miquel
hye, sir what should i do if there no module named ordered_dict ? I read in python script there is no ordered_dict. what should i do?
I ran across this while looking at how to replace our existing door control at the office. We’re trying to figure out how to scale your solution using multiple doors and anti-pass back.
Hi Charlie – That sounds interesting – it would be fairly easy to take this and scale it to work with multiple doors if you install the hardware on each door and instead of installing the database on the Raspberry Pi within the doors themselves, install one single database in a centralised location. This could either be another Raspberry Pi on the network or even another full-blown server. Then just assign each door an ID (1, 2, 3 etc.) and you can include which door they entered in the logs, or even add another database table authorising registered users to specific doors (or even specific doors and specific times – many possibilities!)
If you know that it takes at least X minutes to walk from door A to door B, for example, then you could place a temporary lock on that user being able to unlock door B until X minutes have passed since they unlocked door A, as a bit of a fail-safe to prevent abuse.
In terms of anti-passback this isn’t something I’ve got much experience of, but I guess one way would be to require something the user can’t easily remove from themselves, by using a retina scanner or something. Or you could place another RFID reader on the inside of the door and require the fob to be scanned on that (with the door closed) on exit and not allow it to be used for entry until it’s been used for exit. A bit like the “touch in and touch out” on public transport networks.
Anyway, I hope that is helpful and gives you some guidance. I’m by no means an expert at all! Keep in touch and let me know what you end up implementing, I’d be really interested to see it and it’s great to see my crazy ideas and creations helping people in the real-world!
Good luck with it and all the best,
Paul
Hi, I need a similar project but there I need to use a webcam to read the QR code automatically, that is generated by the system if the QR code matches, the door should be automatically opened else not. any help in this regard is highly appreciated
That sounds an interesting use case! I’m guessing you’re storing an access code in the QR code which isn’t secret in your scenario. You’ll need to research some image recognition software and how to pipe the results from that into a QR reading library.
A quick Google search has found this: https://pypi.org/project/pyzbar/
I can’t vouch for it though as I’ve never used it! Good luck with your project.
HI Paul, This looks like a great project, a little too much authentication for me as all I need is a key fob, but i like the fact that it is based on mysql.
On the topic of mysql, when installing as per instructions, I was not prompted for “root” password as you describe. As a result when install the phpmyadimn, it asks me for a password when trying to access, but I dont have one, so the project for me stops there.
Is this a common issue, as I am a real noob on this, I really need some help in either adding a password or changing it once install has completed.
Thanks again for great project.
Hi Philip, thanks for your comment and I’m glad you liked it!
On more recent versions you may need to run MySQL Secure Installation. See this link for more info: https://dev.mysql.com/doc/refman/5.7/en/mysql-secure-installation.html
I’d also encourage you to look into SQLite as it might be all you really need!
Hi Paul
Thanks for that, I did try this but still no results.
I did however manage to get this working by following the guide in the below link and apparently it turns out you can’t use the root user in 5.7 anymore without becoming a sudoer.
https://stackoverflow.com/questions/36864206/sqlstatehy000-1698-access-denied-for-user-rootlocalhost-tried-everythi
Now I am going to move on to attach a RC522 RFID reader and to reduce the default option on my deployment to single factor authentication with the option to upgrade it later as i have the code already.
Any help or advice you can give me on the above would be greatly appreciated.
Thanks.
Glad you got it working!
Ah yes the RC522 boards are a little bit more complex to get working than a simple USB reader – but more flexible. I have one knocking around somewhere so I might make a video about it in the future…
HI Paul
I have been struggling all day today and yesterday with the dependencies.
Please can I ask for some help as a real noob to python……… How do I install all the dependencies you require. I am using Python3.5.3 (IDLE) and it keeps failing on line 3 (import MySQLdb) and I fear this is due to a dependency that is not installed, but once I solve this one i fear i may just stop at line 4 or 5.
I have executed sudo apt-get install python-mysqldb but still no joy……..
PLEASE HELP THIS NOOB!!!!!!
Thanks
Philip
Hi,
very nice your project,
can you please tell me where i can get the current circuit for this?
Thabks
Hi, do you mean the power supply that supplies current? If so, I used a standard desktop computer power supply.
If you mean the main circuit board, that’s a Raspberry Pi computer.
Hope that helps – let me know if you didn’t mean either! ?
hi I have a few questions
If I build this with a Raspberry Pi 2 will it still connect? or will i require an Ethernet cable and if so does it connect to the expansion board?
Also can the software be programmed to send the personal identification code to multiple numbers?
Hi Sephy!
Yes you can build this project with your Raspberry Pi 2 no problem. As it doesn’t have built-in WiFi, you can connect an Ethernet cable or for more flexibility you can add WiFi via USB. I’d recommend this one as it’s compatible with Raspberry Pi: https://amzn.to/2P6AKKI
To send the codes to multiple numbers, you would just need to change the database table structure a little bit. Rather than having a single mobile phone number in the users table, create a new table with fields like “phone_number” and “user_id”, so that you can have multiple entries for user ID 1, for example. Then modify the Python code to retrieve all those numbers in an array, and loop through it sending out the codes to each number. Or, depending on the provider you’re using, you might be able to do just 1 request and submit an array as the “to:” field.
Hope that helps! Send a picture of your setup once it’s finished so I can see how you get on 🙂
Whilst this may be a nice project, it is not entirely true to call it a 3FA (3 factor) solution.
Multi-factor authentication (MFA) is a method of confirming a user’s claimed identity in which a computer user is granted access only after successfully presenting two or more pieces of evidence (or factors) to an authentication mechanism: knowledge (something the user and only the user knows), possession (something the user and only the user has), and inherence (something the user and only the user is).[1][2]
Two-factor authentication (also known as 2FA) is a type, or subset, of multi-factor authentication. It is a method of confirming users’ claimed identities by using a combination of two different factors: 1) something they know, 2) something they have, or 3) something they are.
This is still 2FA, you just happen to “have” two of the three things (the RFID tag and authentication app are two things you have; the PIN is something you know).
Perhaps using biometrics to unlock the keypad when you have the RFID card near in order to enter the PIN would achieve the 3FA.
Biometrics – Something you are
RFID Chip – Something you have
PIN – Something you know
Thanks, yes you’re right and also the millionth person to point that out to me ? If only I could edit a YouTube video to insert an explanation in the intro ?
The code is easily modifiable to include either fingerprint or retina scanner either instead of, or as well as, one of the other options.
Thanks for your comment though! ?
sir, can you give some advice on me about import database file into phpmyadmin? im not understand whether where to run the database file is it in i need to install xampp in raspberry Pi or install xampp in laptop?
You don’t need xampp anywhere. Install a LAMP stack on Raspberry Pi and then phpMyAdmin on top of that. Access via laptop if you like. Import database via phpMyAdmin, and Bob’s your uncle.
Thank you sir for you advice, i will try it.
sir, can you give advice on why i get access denied after rfid reader scan my rfid card? i really appreciate your advice.
Hello, i just want to ask the rfid usb that you use in the video need to install in raspberry pi ?
Hi Paul,
Firstly, Great concept and tutorial!
I’ve tried to install your python script, installed and configured the database; it all seems to be going very, but i have stumbled upon a problem that i’m not sure how to overcome and wondered if you would be able to help? – After scanning my ID card/ fob the system shows ‘Welcome Tom’ in the header but the keypad doesn’t display….. Any ideas?
Thanks in advance,
Tom
Thanks, glad you liked it! If you launch the script manually from the terminal, any errors should be output there, helping you to debug. Good luck!
Is this one only compatible with this USB card reader or it supports many other usb card readers too?
Hi, Very nice project. But we came across a problem with that rfid reader when we were trying to DIY this.
So is this entire system compatible with any USB RFID reader or only the one mentioned above??
Thanks
Hi, thanks for your comments and I’m glad you liked it! It should be compatible with any so long as it works as a keyboard input. If not, you may need to modify the code and write your own new function to read the RFID code, then use that instead. But the beauty of an open source system like this is you can hack it any way you like. Good luck and enjoy!
Hi Paul, thanks for this very good project. At the moment I’m stuck at the same installation step than Siti Zaleha – error message “no module named ‘evdev’, I already installed evdev module but it doesn’t fix the problem…. Any help would be more than welcome.
Thanks, Laurent
Hey Paul do you have a block diagram for this project?
No sorry, just what’s on this page, YouTube and GitHub.
Hi,
Great tutorial; if I have two doors and two locks, and a 2-channel relay module, could 1 power supply (12v / 5v) still work?
Thanks and take care
Great tutorial; if I have two doors, two locks and a 2-channel relay module, can 1 12v / 5v power supply still work?
Yes, they have multiple outputs at each voltage ?
Cool! Thanks for the quick reply!
Hello. i just want to ask this project is running the uuid value of usb rfid in decimal or hexadecimal?
Hi! Really nice project! Congratulations!
I have a problem: I read the badge, the system enters the PIN entry screen, I read the badge again by mistake. The new welcome message is placed under the pin keyboard and the screen is not reset properly. How can I handle this error?
Thanks, glad you like it! That might be a bug with my script, I’m not sure as it was so long ago ? you’d just need to ensure that whenever a recognised fob is presented, it stops listening for fobs until it’s reset again… hopefully that makes sense!
Hi sir how to create database in phpmyadmin any suggestions
If we complete the procedure how can we make changes in database
I’m not sure what you mean? Could you elaborate as to what you’re trying to do and what your question is?
You can make changes (eg. enter your specific fob code and update name, etc.) to the database via phpMyAdmin (easiest method) or if you’re familiar with the shell and command line prompts, you can do it there also.
How to cancel autoboot and how to changes in database.
Please help me on procedure in twilo and how to import python script in and blank database table in phpmyadmin
Probably a long shot asking this now, but does anyone have the specific changes to the python script to make this a 2 factor authentication. Looking for RFID and PIN only. When i make what I think are the correct changes the script freezes after the pin is entered. Unfortunately it does not generate an error for me to track down. I know the changes are needed in line 196 (i think the smscode can just be deleted) But I am not sure what to delete and move from lines 228-end. Any help would be greatly appreciated.
Hello Miquel. Have you finished the project?
Sir which version rasberry os used
I don’t recall the exact version number in afraid as this was 3 years ago now. If you’re attempting to build this now, I’d aim to use the most up to date possible.
Thanks for replying ….but sir my server not change maria DB to my sql
are you using raspbian for this project
I was yes… I used the image that came with the Touchscreen LCD as it had all the drivers etc. already set up on it. Depending on what hardware you use, you may want to do the same or just install separately.
How do you add multiple rfid fob codes to this to allow multiple tags
Just add additional rows to the database table, one for each fob. It’s designed to work with an unlimited number of key fobs as long as they have unique codes 👍
Yes what to do and to the code exactly could you please send it in a comment of how it should look please
I’m also talking about the one where you don’t use Mysql
Sir I’m was asking about how to add more rfid tags to one without Mysql
Why don’t you want to use MySQL? You could use SQLite instead if you like, as it’s a very lightweight database requirement. You can read about how to use that in another tutorial I wrote in Issue 12 of HackSpace magazine. Download the PDF free from here: https://hackspace.raspberrypi.org/issues/12 – start on page 102.
Ok thank you
sir want to use MySQL but your code doesn’t work when I do it
How to pass values from one thread to another thread Python?
I begin to code the python and I am not have more experience in syntax of python
1. I want to send a value from the RFID reader. If it saves successfully, the PIR Motion Sensor will be disabled in a moment. and reworking within the specified time.
2. If the temperature is measured And send the value to the function RFID Reader to record the temperature and the PIR Motion Sensor stops working as well.
https://www.rapidtables.com/tools/notepad.html?fbclid=IwAR39SSpM4sxZdnEI3pCKTTMPP8lLVwqPbsOtkbETvXBXMG9QQzLXVFmyBeA
Hello! I only have 1 small problem with the code, for some reason the rfid reader doesnt do anything when running the program. Reader works and it types to code but for some reason it wont type it to the program when it is asking rfid
hey can you tell how to add a camera and face recognition instead of rfid reader.