Sponsor Run With C# and Arduino + RC-522

by yves.vanhal in Circuits > Arduino

2707 Views, 4 Favorites, 0 Comments

Sponsor Run With C# and Arduino + RC-522

SponsorRun.jpg

Sponsor runs are quite common. However, managing them is not always an easy task.
It involves registering how many laps each team runs in an efficient way. I decided to use RFID's to use as a token for identifying each team. Combined with the fact you can pick up an RC-522 RFID reader card and an arduino quite cheap, it makes it possible to construct this system quite easily.

List of Materials Needed

  • Arduino board: any board will do. I use Arduino Nano for its size
  • Arduino development environment
  • RC-522: can be bought/ordered locally or abroad
  • MiFare 13.56 MHz tags. Normally some samples may come with your RC-522 board. The type of tag does not matter. Just check they are the right frequency.
  • A PC running Windows and having Visual Studio installed, if you want to modify the code.

Preparing the Arduino + RC-522

RC522 wiring.jpg

The picture above shows the wiring of the RC-522 module to the Arduino. Any Arduino will do. So, if you have an Arduino Nano available, you might consider using that. On thingiverse you can find some cases for boxing it all together. I tried one out, but its margins for printing it were too small, ending up with an unusable 3D-print.

I'm still working on a good case for that.

In order to make use of your RC-522 board, you'll have to add a library to the Arduino editor. Unfortunately, it is not a library which is managed by the Arduino editor, so you will have to add it the "old school" method of downloading it and copying it to the libraries folder. Don't forget to restart the Arduino editor to make it accessible.

The library can be found at https://github.com/miguelbalboa/rfid.

By now, you have the editor ready. It's time to upload the script to your Arduino. If you analyze the code, you will find there is an interval of 5000 milliseconds in which it is avoided printing out the same key multiple times. You can vary that interval, but if you set it too small, the same key will be shown multiple times after each other.

So, now it's time to check if this part works. The RFID's I use are standard MiFare 1Kb fobs at 13.56 MHz, which are also very cheaply available.

Open up the Serial monitor of the Arduino editor and watch the keys appear as you bring them to the RC-522 module.

Downloads

The Windows Interface Written in C#

SponsorRun.jpg

You find included a compressed folder containing the C# project. Download it and unpack it. The code was written in Visual Studio 2017 targeting .Net framework 4.6.1. Any updated computer should have this and be able to execute it. You don't necessarily need to install Visual Studio. The code is provided for those who want to modify or examine it. Without modifications to the program, the duration of the run is set to 1 hour and 30 minutes. The normal lap time is set to 50 seconds which is for a 400 meter track.

The executable can be found in the Debug folder which is located under the SponsorRun\SponsorRun\bin folder.

In that folder are also the text files which are used in this project to store the data.

The text files are:

  • rfidKeys.txt: containing the keys for the different teams. The first key is for the first team, and so on. You can remove this file and add your own keys (look below for how the program works)
  • teams.txt: containing the names for the different teams. The first name is for the first team, and so on. Edit this file with a common plain text editor (notepad might do).
  • results.txt: a CSV-formatted file containing the results of the various laps of the teams (may be absent, when no laps have been registered so far)
  • fraude.txt: a CSV-formatted file containing teams trying to cheat (may be absent, when no cheating has been detected yet)

The way the program functions is as follows:

  • On initialization the program detects the various COM ports on your computer. You should select the COM port assigned to your Arduino in order to make the communication possible. By default, the COM speed rate should be 9600 bps, which corresponds to the speed set in the Arduino code.
  • Click the "Start listening" button to activate the communication
  • From that point on, you can choose between two functions:
    • Read RFID keys: this adds new keys to the rfidKeys.txt file
    • Register lap (default option): registers a new lap to the results.txt file. Each time a valid key is read, a message will appear and a beep tone will be sounded to confirm the registration. A line will be added to results.txt. In case of an attempt to cheat, the message will appear in a separate textbox, another beep will sound and the result will be written to fraude.txt. In that case, the time for the lap will be set to the moment the cheating was detected.

Downloads

Possible Improvements

I created this project for a specific situation in my school. It is obvious some of the parameters used may not suitable for your project. For now, you will have to adjust the parameters in the C# code and recompile the program, which necessitates the installation of Visual Studio (a hefty 3.5 GB installation). If there is a reasonable amount of response, I may consider reading these parameters from an external file.

The 3D-cases I found for housing the Arduino project are not usable. I started on one, but had some setbacks, which is the reason, I have not added them yet. Anyone wishing to share one can contact me, so I can refer to your work in this Instructable.

Give Thumbs Up !!!

I hope you can use this project and I'm looking forward to hear from you.