Skip to main content

86. RFID Health tag (Arduino and Python)

 Hey everyone,

Sorry I have not uploaded in a while. Today, I will be sharing an interesting project with all of you. This RFID Health tag project is useful when it comes to keeping track of vaccinated individuals, their biodata and their health conditions and medications. For this project, you will be needing Arduino and Python. Read on further to see how I did this project.

Hardware components used in this project



  • Arduino Uno
  • Solderless Breadboard - Half+
  • MRFC522 RFID reader
  • RFID key tags (x5)
  • Push-buttons (x2)
  • Male-to-Male Jumper wires (x12)
  • USB Type A/ B cable (for Arduino Uno)

Software required

  • Arduino IDE - latest version recommended
  • Python 3.8

Schematic

MFRC522 RFID reader

  • SDA/ SS - D10
  • SCK - D13
  • MOSI - D11
  • MISO - D12
  • IRQ - Not connected
  • GND - Ground
  • RST/ RESET - D9
  • 3.3V - 3.3V

Push-buttons

  • Submit button - D4
  • Retrieve button - D5

Coding

Arduino

For this project, you will be using the following libraries:
Please connect your RFID module to your Arduino Uno microcontroller accordingly and to check if your connections are correct, I would recommend you to upload the DumpInfo example sketch from the MFRC522 library. Open the serial monitor and if your connections are correct, the RFID tag will be scanned properly. 

The basics of the DumpInfo example sketch will be used in this project's sketch. Make sure that only the 'content.substring(1)' is printed in the Serial Monitor. You will understand why when you move to the Python coding. Make sure you use Serial.println for this. You will also need to create variables for your push buttons and declare them as INPUT_PULLUP as we have connected them without the 10k ohms resistor. When you press the push button, it will send a LOW signal so you have to program your Arduino microcontroller to print the 'Submit' and 'Retrieve' when you press the respective push buttons. Use Serial.println for this purpose too. Set a delay period of 1 second before exiting void loop.

Python

Install the python software and open command prompt. Change the directory to the folder where you have installed the software. PIP is a packet management system that lets you install and manage software packages written in python. You will need to upgrade PIP before you install these modules. In order to do this, you will need to use the following function:
python - m pip install - upgrade pip
Install the Pyserial module after the update is done. You will be needing the following function for this:
python - m pip install pyserial
You will also need to install the tkCalendar module.
                                                        python - m pip install tkCalendar
The next step is to check whether these modules are successfully installed. Open the Python IDLE and type 'import serial'. If the installation is perfectly done, you would not see any errors.

You will need the tkinter library but it is an in-built library so you do not have to install them. If you are unfamiliar with tkinter, I would recommend you to refer to a few beginner projects with Tkinter to understand this project. I have not used any advanced techniques so if you are a beginner, you will be able to understand this easily.

Open the Python IDLE and open a new file. Import the modules which we installed in the first step along with the time and date (from timedate) modules. If you want to beautify your text, you can use tkinter.font. Please refer to this link to learn how to use this module. You will also need messagebox module from tkinter library to create the warning and exit message box. Please feel free to read more about this module here to explore the variety of options available in this widget. You could even try to improve this project by coming up with your own message box ideas.

You will be needing the time module to use delay function. Create serial port object and open serial port. You can find pg.11 of this documentation useful for this process. Wait for 3 seconds while the communication establishes.

Create an empty dictionary called details and this is where you will be storing the data. You might encounter some issues due to memory availability when it comes to dealing with huge amounts of data so I would recommend you to use a database system if you want to try this project with greater amount of data. Otherwise, this method is fine.

The ID will be the dictionary key whereas the value will be the list that contains the biodata and the vaccination details of the individual.

Create an empty list for the vaccination dates and two other variables named state and ID. Create a variable named today and assign today's date to it - use date.today( ) so that the variable will be updated when you run the program.

After the communication is established, read the serial data and print it. Do not that the serial data is UTF-8-encoded so you have to decode it and convert it into a string before you move further into this project.

When you print a line in your Serial Monitor (Arduino IDE), it will be sent to your Python program, so if the incoming string is 'submit', then you have to create a tkinter window where the user can enter his/ her biodata and vaccination details. If the string is 'retrieve', then you have to create a tkinter window where the data stored in the ID (dictionary key) is displayed completely. If the string is neither 'submit' or 'retrieve', then the string must be assigned to the ID variable.

If the ID variable has no values stored, then an error/ warning must be displayed when the submit or retrieve button is pressed. If the ID key has no values in the details dictionary, then an error message must be displayed, when the retrieve button is pressed, saying that the submit button should be pressed and the data must be stored first.

Please watch the video to see how I designed my submit and retrieve tkinter windows. It would give you an idea before you start designing the tkinter window. Please feel free to use your own ideas as well. 

First off, I created labels named ID, Name, Date of Birth, Age, Gender, Blood type, Health conditions, Medications, Vaccination Status, Vaccine, No. of doses, and Vaccination dates and entry fields for the name, gender, blood type, health conditions, medications, vaccine and number of doses. I created radio buttons for vaccination status by following this tutorial: https://www.tutorialspoint.com/python/tk_radiobutton.htm.

Then I created five message widgets - 3 blank ones, one named Vaccination details and another for the ID variable. The blank ones can be configured later and they are for Date of Birth, Age and the error message that is displayed when you try to submit incomplete details.

I created the calendar widget using this tutorial: https://www.geeksforgeeks.org/create-a-date-picker-calendar-tkinter/

Then, I created four buttons which were 'Submit', 'Exit', 'Pick dates' and 'Get Date'. Each button's command was assigned to four different functions. 

The 'Get Date' function retrieves the date from the calendar widget using get_date method and as it is a string, I have split it by using '/' as the separator so that I can obtain the day, month and year of the person's date of birth. This returns a list with the month, day and year as the elements and using this, along with the value stored in today variable, I was able to calculate the age of the person. The message widgets for date of birth and age are then configured.

The 'Exit' button's function displays a message box using the messagebox module and askquestion method. If the user's answer is yes, the current tkinter window must be destroyed.

The 'Pick dates' function should open up another tkinter window where there is another calendar widget from where the user can pick their vaccination dates. This window will have two buttons, one for selecting the dates and the other for displaying them. The dates should be stored in a list and make sure that the number of elements in the dates list must be equal to the number of doses entered, only then should the display button work properly and display the dates or else it should display an error message saying the user to try again. To retrieve the number of doses entered, apply get method to the respective Entry field.

The 'Submit' button should only work when the Entry fields for name, gender and blood type is not empty and when one of the radio button is clicked. Please try experimenting with the radio buttons to see the values they return when selected and when not selected. If the radio button for vaccinated is selected, then the submit button should only work when the vaccination details are also entered. As the information is submitted, the values stored in the entry fields must be extracted using the get method and stored in their respective variables. The variables should then be stored as the elements of a list which is the value of the ID key (details dictionary). On successful submission, the state of the submit button should be configured to 'disabled'. If the any widget mentioned above is empty, then an error message should be displayed.

Retrieving the details is an easy task, if 'retrieve' is in incoming, then a tkinter window should be created with the appropriate title and dimensions, you can try to add a background image if you wish, and the labels should be created to display the biodata and vaccination details. As the values are stored in dictionary keys, you can try to get the values stored in the ID key and as the details are stored as a list, you can access the respective data by using the index values. It may not be practically possible when it comes to handling large amount of details but in this case, this can work. The number of elements of the list can differ when it comes to a person being vaccinated and when they are not. So you have to use len( ) to calculate the number of elements in the list and then you can code accordingly. You also have to consider the Health condition and Medication data, and None should be displayed if the get method for their respective entry fields return a null string. You have to loop through the elements of the dates nested list to display each vaccination date as a label.

Please watch the Youtube video in the Final Look section to have a clear understanding of how this works.

If anyone has any questions with the codes, please feel free to comment below.

Final Look


If anyone has any questions or suggestions, please feel free to comment below.

Comments

Popular posts from this blog

51. Buzz wire game using Arduino

Hello everyone! This is my first Arduino project in 2020 and it is going to be a fun and simple project. You would have heard of the Buzz Wire, a steady hand game, and today you will be learning to make one using Arduino. Hardware components used in this project Arduino Nano USB Type A to mini B cable (for Arduino Nano) Solderless Breadboard - Mini and Full-size LEDs (x2) - Green and Red Resistors (x2) - 220 Ω  Active Buzzer module (KY-012) LCD display module with I2C interface - 16x2 Male-to-Male Jumper wires (x4) - 10cm Female-to-Male Jumper wires (x5) - 20 cm Jumpers (x5) - to reduce the usage of wires Copper wire  Tape (or any form of insulation)  Setup Your hardware setup must look somewhat similar to the ones in the images above. The beginning and end of the copper wire maze must be taped to prevent conductivity between the wire loop and maze. Connections LCD display module with I2C interface GND - Ground VCC - 5V SDA - A4 SCL - A5

71. Buzz Wire Game ( Version 2.0 ) using Arduino

Hey Everyone! I hope that everyone's safe during this pandemic. Today I am going to explain you about the second version of my Buzz wire game. People who are bored of staying indoors can find this game pretty interesting and fun to play.  If you are a beginner, you can start off with my first version of this project :  51. Buzz wire game using Arduino   Hardware components used in this project Arduino Uno Solderless Breadboard (x2) - Full/ Full+ LCD display module with I2C module - 16x2 Potentiometer - B20K Push-buttons (x3) Resistor - 220 Ω Active Buzzer module (KY-012) LED - Red Copper Wire - 19/ 20 gauge thick Male-to-Male Jumper wires - 10cm and 20cm Wire - Long enough to connect the loop of copper wire to ground Other tools required for this project Cutting pliers - To cut the right amount of copper wire Round-nose pliers - To bend the copper wire and make a maze and loop Hardware setup Connections Wire Maze - D2 Wire loop - Ground (GND) B20K Potentiometer S - A0 (+) - 5V (-)