If you're like me, then you have a small pile of clothes on the floor that may or may not be dirty. This could include jeans, dress shirts, and barely worn shorts. So how can you tell which clothes are clean or dirty? I came up with a way to track various articles of clothing using NFC and a Raspberry Pi. You simply insert the NFC card into a pocket and then scan it, which bring up information about that clothing item along with an ability to change it.
Gathering ComponentsDFRobot reached out to me to sponsor this project, so they sent a Raspberry Pi 3 and PN532 NFC Module, along with 5 NFC cards. The NFC module uses UART to communicate with a host device, so I tried using a Raspberry Pi at first, but I ran into several issues. The libraries were complex and hard to interface with Python, so I opted to use an Arduino Mega for communicating with the NFC module. The Arduino Mega was necessary because it takes two UART ports, one for the NFC module and one for outputting information.
I went to the Raspberry Pi Downloads page and downloaded the most recent version of Raspbian. I then extracted the file and put it into a convenient directory. You can't just copy/paste a .img file to an SD card, you have to "burn it" onto the card. You can download a burning utility like Etcher.io to easily transfer the OS image. After the .img file was on my SD card I inserted it into the Raspberry Pi and gave it power. After about 50 seconds I unplugged the cord and removed the SD card. Next I put the SD card back into my PC and went to the "boot" directory. I opened up Notepad and saved it as a blank file named "ssh" with NO extension. There was also a file I added called "wpa_supplicant.conf" and put this text into it:
network={
ssid=<"SSID">
psk=<"PASSWD">
}
Then I saved and ejected the card and put it back into the Raspberry Pi 3. This should now allow for the usage of SSH and connecting to WiFi.
The wiring for this is pretty simple. I connected the Rx pin to the Tx1 of the Mega, and the Tx pin to the Rx1 pin of the Mega. 5v goes to 5v, and GND goes to GND. I also connected the Arduino Mega to the Raspberry Pi 3 via a small USB cable.
ProgrammingThere are two files, one for the Arduino Mega and one for the Raspberry Pi. The Arduino Mega first sends out a handshake request to the module and then waits for a response. Once the response has been given the Mega starts polling the device to see if any cards have been scanned. If so, the ID of the card is read. In order to send concise information to the Pi, I used a pseudo-checksum algorithm to combine the five bytes into one number. The first four bytes get added together once, and the last byte gets added twice. There is also an array that contains the numbers of each card. When a card is scanned its checksum gets compared to the ones in the array and then matched. Lastly that data gets sent over serial to the Raspberry Pi for further processing.
The Raspberry Pi waits for new serial information and then prints it. A dictionary is created at the beginning of the code that defines how each clothing item corresponds to each card. Each has a name, the card number, the color, and the status (clean or dirty). There is an option to change the status once the clothing item is scanned.
I began by inserting cards into the pockets of my clothes and checking their IDs, recording the information into the dictionary. If I want to see if they're clean or dirty I simply hold them up to the RFID reader which then displays the information via SSH.
Here is a video demonstrating the usage:
Comments