How to Build Raspberry Pi RFID Attendance System
by sarful in Circuits > Raspberry Pi
3635 Views, 4 Favorites, 0 Comments
How to Build Raspberry Pi RFID Attendance System
In this tutorial, I will show you How to build Raspberry pi RFID attendance system complete process, Below are some of the things you need to know to complete this project
How to Setup MYSQL Database and PHPMyAdmin on the Raspberry Pi and I will try to give you an idea on this subject after which I will go to see the main projectFor Raspberry pi RFID attendance system project, you have to need flowing Equipment
- Breadboard
- Breadboard Wire
This book will help you to gain more knowledge about Raspberry Pi
Setting up MYSQL on a Raspberry pi RFID attendance system Project:Before we get started with installing MySQL to our Raspberry Pi, we must first update our package list and all installed packages. running the following two commands.
sudo apt update sudo apt upgradeThe next step is to install the MySQL server software for your Raspberry Pi.
sudo apt install mariadb-server
Now you have to need to secure it by setting a password for the “root” user.
By default, MySQL is installed without any password set up meaning you can access the MySQL server without any authentication.
Run the following command to begin the MySQL securing process.
sudo mysql_secure_installationJust follow the prompts to set a password for the root user and to secure your MySQL installation. For a more secure installation, you should answer “Y” to all prompts if you want to access your Raspberry Pi’s MySQL server and start making changes or something work your databases, you can enter the following command.
sudo mysql -u root -p
You can now enter MYSQL commands to create, alter, and delete databases. Through this interface, you can also create or delete users and assign them the right to manage any database. There are two different ways you can quit out of the MYSQL command line, the first of those is to type “quit” into the MySQL interface. The other way of quitting out of the MYSQL command line is to press Ctrl + D. Ok great, you will now have successfully set up MySQL on your Raspberry Pi.
<span style="font-size: small; font-weight: normal;">sudo apt install phpmyadmin</span>
You have to need to configure PHPMyAdmin to connect to our MYSQL server. We will also need to set up some details so that we can log in to the PHPMyAdmin software.
To do this select “<Yes>” at them all next prompt.
It will now ask you to set a password for PHPMyAdmin itself. It is best to set this password to something different to your root SQL password. Doing this will help secure the server. This password is what PHPMyAdmin will use to connect to the MySQL server.
To do this, we will need to first login to the MySQL command-line interface using the “root” user with the password you set up.sudo mysql -u root -p
Now time to run the command below to create a user and permit it to access all databases on the MySQL server.
Make sure you replace “username” with the username of your choice.
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;You can exit out of the MySQL command-line interface by typing “quit” in the terminal. Configuring Apache for PHPMyAdmin Before you can load the PHPMyAdmin interface on our Raspberry Pi, we will need to make some configuration changes to Apache. entering This the following into the terminal.
sudo nano /etc/apache2/apache2.confNow we need to add the following line to the bottom of this file.
Include /etc/phpmyadmin/apache.confOnce done we can save and exit by pressing CTRL + X and then pressing Y then ENTER. Now we need to restart the Apache service on our Raspberry Pi by running the command below.
sudo service apache2 restartConfiguring PHPMyAdminTo do this, we need to run the following command on our Raspberry Pi.
<span style="font-weight: normal;">sudo ln -s /usr/share/phpmyadmin /var/www/html</span>
now you able to access your Raspberry Pi’s PHPMyAdmin interface from a web browser using your IP address.
In my case http://169.254.219.186/phpmyadmin
Now time to build your Raspberry Pi RFID Attendance SystemNotice
You have to need read this tutorial for how to Building the RFID RC522 Reader Circuit and how to Enabling the SPI interface go to
How to interface RFID-RC522 with Raspberry Pi
The first thing you need to do is move on from the link above and gain an idea about the RFID.
Raspberry pi to RFID-RC522 wiring
- SDA connects to Pin 24.
- SCK connects to Pin 23.
- MOSI connects to Pin 19.
- MISO connects to Pin 21.
- GND connects to Pin 6.
- RST connects to Pin 22.
- 3.3v connects to Pin 1.
Now your job is to create a database for the RFID attendance system. I will now show you how to create a database.
RFID attendance system
Now it is time to load up into the MYSQL command-line tool by running the following command
sudo mysql -u root -p
We will be naming this database, “attendancesy_stem“. To create this database, run the following command
CREATE DATABASE attendance_system;
Make sure you set the password for this to something unique and hard to guess. For our example, we will be just using “your_password” as the password
CREATE USER 'attendance_admin'@'localhost' IDENTIFIED BY 'your_password';
Now that we have created our user we need to give it the rights to access our “attendancesy_stem” database.
GRANT ALL PRIVILEGES ON attendance_system.* TO 'attendance_admin'@'localhost';
Before we create our tables, we need to utilize the “use” command so that we are directly interacting with the “attendance_system” database.
Begin interacting with the database by running the following command.
use attendance_system;
Now that we are dealing directly with the database that we want to utilize we can now start creating the tables where all our data will be stored
Install the connector library by running the following command on your Pi.
sudo pip3 install mysql-connector-python
Recording a User in the Attendance System Code
import time import RPi.GPIO as GPIO from mfrc522 import SimpleMFRC522 import mysql.connector db = mysql.connector.connect( host="localhost", user="username", passwd="your_password", database="attendance_system" ) cursor = db.cursor() reader = SimpleMFRC522() try: while True: print('Place Card to\nregister') id, text = reader.read() cursor.execute("SELECT id FROM users WHERE rfid_uid="+str(id)) cursor.fetchone() if cursor.rowcount >= 1: print("Overwrite\nexisting user?") overwrite = input("Overwite (Y/N)? ") if overwrite[0] == 'Y' or overwrite[0] == 'y': print("Overwriting user.") time.sleep(1) sql_insert = "UPDATE users SET name = %s WHERE rfid_uid=%s" else: continue; else: sql_insert = "INSERT INTO users (name, rfid_uid) VALUES (%s, %s)" print('Enter new name') new_name = input("Name: ") cursor.execute(sql_insert, (new_name, id)) db.commit() print("User " + new_name + "\nSaved") time.sleep(2) finally: GPIO.cleanup()
Recording Attendance
#!/usr/bin/env python import time import RPi.GPIO as GPIO from mfrc522 import SimpleMFRC522 import mysql.connector db = mysql.connector.connect( host="localhost", user="username", passwd="your_password", database="attendance_system" ) cursor = db.cursor() reader = SimpleMFRC522() try: while True: print('Place Card to\nrecord attendance') id, text = reader.read() cursor.execute("Select id, name FROM users WHERE rfid_uid="+str(id)) result = cursor.fetchone() if cursor.rowcount >= 1: print("Welcome " + result[1]) cursor.execute("INSERT INTO attendance (user_id) VALUES (%s)", (result[0],) ) db.commit() else: print("User does not exist.") time.sleep(2) finally: GPIO.cleanup()
Now you can check your Database for update
My Previous project
- PIR Motion Sensor using Raspberry Pi4 | Interfacing Tutorial
- PIR Sensor -Email Sending Movement Detector using IFTTT
- Controlling a DC Motor with Raspberry Pi4
- How to Use the Raspberry Pi4 Camera And PIR Sensor to Send Emails
- Raspberry Pi Distance Sensor using the JSN-SR04T
- How to connect 16×2 LCD with Raspberry pi
- How to interface RFID-RC522 with Raspberry Pi