Home > Other >Special Application Circuits > How to use RFID to create an automatic roll call attendance system

How to use RFID to create an automatic roll call attendance system

Source: InternetPublisher:睡不醒的小壮 Keywords: RFID Attendance System Updated: 2024/08/06

As a teacher, traditionally attendance (roll call) is a time-consuming task, and if automated, teachers can focus on other teaching activities. In this project, RFID reader modules and RFID cards will be used to implement an automated attendance system.

Classes are conducted in confined spaces and it is difficult to follow the lectures if the environment is too hot or too cold. For effective learning, the correct physical environment in the classroom should be maintained. This project will use a Relative Humidity and Temperature Sensor (DHT11) to monitor the temperature and humidity and notify when the values ​​are out of range.

Libraries and Definitions

Before starting the code, the library needs to be included in the program. The pin numbers that are physically connected to the Arduino board are defined. Instances of the RFID receiver (mfrc522) and DHT sensor (dht) that will be used for data acquisition are created. A variable called student is created which is a two-dimensional string array to store the student names and the associated RFID tag IDs.

set up

The setup() function is executed only once when the board is powered on or the reset button is pressed. The serial connection is initialized at a baud rate of 9600. The DHT sensor acquisition calls the begin() function to start the acquisition.

Calls some ArduinoIoTCloud functions to initialize properties, start a connection, set the debug message level, and print any debug information.

Main function - loop

The loop() function in Arduino includes the start of SPI communication and initialization of the mfrc522. Originally, these two initializations were done during the setup phase, but were moved to the loop due to a bug during an ArduinoCloud update. It changed pin 10 to input, interrupting SPI communication. The solution is to initialize SPI communication on each loop to reset pin 10 to output mode.

void loop() {
SPI.begin();
mfrc522.PCD_Init();
if ( mfrc522.PICC_IsNewCardPresent()) {
if (mfrc522.PICC_ReadCardSerial()) {
 String content = "";
 byte letter;
 for (byte i = 0 ; i < mfrc522.uid.size; i++)
 {
  content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
  content.concat(String(mfrc522.uid.uidByte[ i], HEX));
 }
 //Serial.println(content.substring(1));
 content.toUpperCase();
 for (int i = 0; i < 6; i++) {
  if (content.substring(1) == student[i][0])
  {
msg_Attendance = "Attendance Recorded for Student: " + student[i][1] ;
  }
 }
 Serial.println(msg_Attendance);
}
}
dht_sensor_getdata();
delay(500);
ArduinoCloud.update();
}

After the mfrc522 is initialized, the PICC_IsNewCardPresent() function is called. If a new card is detected, the PICC_ReadCardSerial() function reads the ID information from the RFID card. The ID is a variable of type string, called content. It is converted to uppercase to be compared with the array of student IDs stored in the program definition section. When the ID read from the card matches the student in the record, the attendance is recorded and stored in the variable msg_Attendance.

The dht_sensor_getdata() function is called, more details in the next section. A short delay of 500 milliseconds is introduced before the ArduinoCloud.update() function is called. This function sends all four variables to the cloud: temperature, humidity, msg_Attendance, and msgTempHum.

DHT sensor function
The function dht_sensor_getdata() is created to read humidity and temperature data from the DHT11 sensor. The dht.h library imports the functions readHumidity() and readTemperature().

The if-else condition checks the thresholds for low (20ºC) and high (27ºC) temperatures and then sends a message to the dashboard. This could be implemented as an actuator (turning the air conditioner on or off) or an alarm in a real classroom.

void dht_sensor_getdata()
{
float hm = dht.readHumidity();
Serial.print(F("Humidity "));
Serial.println(hm);
float temp = dht.readTemperature();
Serial.print(F("Temperature "));
Serial.println(temp);
humidity = hm;
temperature = temp;
if (temp > 27) {
msgTempHum = "Temperature = " + String (temperature) + " Humidity = " + String(humidity) + " - > High ";
}
else if (temp < 20) {
msgTempHum = "Temperature = " + String (temperature) + " Humidity = " + String(humidity) + " -> Low ";
}
else {
msgTempHum = "Temperature = " + String (temperature) + " Humidity = " + String(humidity) + " -> All ok ";
}
}

Preparation - Setting up the cloud

To connect to ArduinoIoTCloud, first we need to create an account or log in.

To use the web-based editor with all the core and libraries already installed, we need to install the CreateAgentPlugin. This agent will recognize the board connected to the computer via USB.

Once in the web editor page we can see the board connected/disconnected, edit our code and upload it when finished.

However, there are two other options available:

Classic offline Arduino IDE 1.8.13 (Integrated Development Environment) as – for local sensor troubleshooting.

The new Arduino IDE 2.0 - with new features like debugging, code highlighting and auto-completion, is currently in beta (at the time of preparing this project).

To select IoTCloud menu or web editor, we can click on the top right button near our profile picture.

Once we select the IoT Cloud menu, there will be a few options available, but in this project we will focus on creating things, associating devices, and preparing dashboards.

After clicking on "Create Thing" as shown in the image above. We followed the steps in this project:

Step 1 - Devices - Associating devices with our Things

Step 2 - Add Variables

Step 3 - Change Network Settings

Step 4 - Edit the Sketch, Connect to the Serial Monitor

Step 5 - Prepare the Dashboard

Step 6 - Get data from the board sent to the cloud and export

Step 1 - Equipment

The first step is to click and select the device.

Any device previously used in the IoT cloud can be associated, and new devices can also be set up.

For this project, we associated the device ArduinoMKR GSM1400 with the Thing, but any other board can be used, such as the ArduinoMKR WiFI1010 or NodeMCU.

Step 2 - Variables

The second step is to add variables:

After clicking Add Variable, you need to select the variable name, type, permissions, update policy, and threshold. In this project, 5 variables are created:

Humidity - stores and displays relative humidity values ​​on the dashboard

Temperature - stores and displays room temperature on the dashboard

msg_Attendance – Displays student attendance, name and time

msgTempHum – Displays temperature and humidity and any warnings

LED - This LED is used for quick troubleshooting to check board/cloud connectivity

Variable permissions can be:

Read and Write - variables can be used as both input and output, data can be sent from the device to the cloud and vice versa

Read-only - variables can only be used as outputs, and data can only be sent from the device to the cloud

The variable update strategy can be:

OnChange: As long as the value changes greater than or equal to the set threshold, the variable will be updated to the cloud

Periodically: Every time the set number of seconds passes, the variable will be updated to the cloud

The basic variable types used in this project are:

Boolean - True or False (LED)

Floating point numbers - numbers with decimals (temperature and humidity)

Strings - words and sentences (msg_Attendance and msgTempHum)

Step 3 - Network

After setting all variables, the third step is to add network credentials in configureNetwork

In this project we used an ArduinoSIM card with the following credentials:

If you are using a Wi-Fi device, the network configuration will be different. The local Wi-Fi name must not contain spaces.

Step 4 - Sketch

A small portion of the code is automatically updated by the Arduino IoT Cloud based on the information added in the first three steps. You can edit the sketch and the full code is shown at the bottom of this page.

Check the serial monitor tab to troubleshoot the connection. If not connecting to the cloud, I recommend using the local Arduino IDE in your computer and looking at the messages on the serial monitor.

Step 5 - Dashboard

The dashboard is the last part of the IoT Cloud setup, we can click on Build Dashboard in the Dashboard tab:

To populate our dashboard, we need to add widgets.

Then we link a variable to the widget in the setup. In this project, we added seven widgets, LED Button, Humidity and Temperature Meter, Humidity and Temperature Chart, Temperature and Humidity Message, and Attendance Message.

Another way to do the above steps is to add a thing (this project's thing is called SIM):

Then select the variable from Thing:

There are two types of dashboard views: Mobile View

and the desktop view:

Step 6 - Download Historical Data

Data can be exported from the cloud using the "Download Historical Data" option on the dashboard (i).

Downloading historical data allows you to select the variables and time period we want to download.

You can view a sample of the attendance data you received via email and downloaded as a CSV file.

The readme.txt file contains the variable name, the requested time period, and a message hoping we "have fun!":

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号