RFID Reader #1: Parallax's RFID Reader Module
In this example, I'll show you how to use Parallax's RFID Reader Module
. This low-cost RFID reader ($39) reads passive RFID transponder tags and uses serial communication to transmit the tag IDs. As you can see in Figure 3
, the reader has four pins at the bottom (from left to right):
|Figure 3: The Parallax's RFID Reader Module.|
- VCC - +5V DC power
- /ENABLE - Enable (Ground) or disable (+5V DC) pin
- SOUT - Serial output
- GND - Ground
The effective read range of Parallax's RFID Reader module is between 1¾" and 3" inches (depending on the tag). When the Reader Module acquires a tag ID, it sends data through the serial port using a 12-byte ASCII string. The LF
(Line Feed) serves as the start byte and the CR
(Carriage Return) serves as the stop byte. The ten digits in between serve as the unique tag ID.
The Parallax's RFID Reader Module reads the following tags:
Setting Up the Reader
To connect the reader to your computer, you need to perform a TTL-to-RS-232 level shifting so that the data can be read via a serial port. One way would be to connect the reader to the RS-232 DCE AppMod
For my project, I used the Javeline Demo Board
($119.00) to connect to the reader.
|Figure 4: The wiring on the Javeline Demo Board.|
|Author's Note: Either board will work well. I just happened to have the Javeline Demo Board, which is the more expensive option. If you are a modder, you can wire up the reader yourself using an RS232 level shifting IC.
shows the wiring on the Javeline Demo Board. After that, you need to:
- Connect a 5V power source to the power connector
- Connect your RS-232 serial cable to the serial port at the top of the board.
- Connect the reader module to board using the pins shown in the diagram
Be sure to use a "straight" serial cable to connect the board to your computer, or you will not be able to get any data from the reader.
|Figure 5: The Parallax RFID Reader and the Javeline Demo Board connected and ready to go.|
If you do not have a serial port on your computer, you can use a USB-to-serial converter to convert a USB connector into a serial port. You will also need a DB9 straight serial cable.
shows the assembled reader and board.
Building the Application User Interface
Using Visual Studio 2005, create a new Windows application and name it C:\Attendance
. You will use the Northwind sample database provided by SQL Server 2000 with SQL Express (see the sidebar, "Installing the Sample Database
"). To simplify data-binding, you will use the drag-and-drop data-binding feature that is new in Visual Studio 2005.
In addition, you will also add a new TagID
field to the Employees
table in the Northwind database. To do so:
- Go to Server Explorer (from the View menu choose Server Explorer).
- Right-click on Data Connections and select Add Connection
- Select the Microsoft SQL Server (SqlClient) data source and in the server name field, enter .\SQLEXPRESS (assuming you have SQL Express installed on your local computer). Select Northwind as the database name and click OK.
|Figure 6: Adding a new TagID field to the Employees table.|
- In Server Explorer, expand the Northwind database and then the Tables item. Double-click Employees and add the TagID field (see Figure 6).
|Author's Note: Ensure that the data source selected is "Microsoft SQL Server (SqlClient)". If it is not, click "Change..." and select Microsoft SQL Server.
First, add a new data source to your project by selecting "Add New Data Source" from the Data menu. In the Data Source Configuration Wizard dialog box, select "Database" and click Next. Click the New Connection button to specify the database to use. You will see the Add Connection dialog box (see Figure 7
). As before, enter .\SQLEXPRESS
as the server name and select Northwind as the database. Click OK.
|Figure 7: Adding a new connection to the Northwind database.|
|Figure 8: Choosing the fields to use in the Employees table.||
Back in the Data Source Configuration Wizard, click Next. In the next screen, select the table and fields to use. Expand the Tables and Employees item and then check the following fields (see Figure 8
From the Data menu, choose "Show Data Sources" to view the newly added data source. Figure 9
shows the Employees
data source. By default, the Employees
table is bound to a DataGridView control and all its fields (except the Photo field) are bound to TextBox controls. You should change the bindings to those as shown in Table 2.
Table 2: Change the Employees table bindings as shown in this table.
data source should now look like the right side of Figure 9
Drag the Employees
data source onto the default Form1. Figure 10
shows the controls that automatically populate the form. For the PictureBox control, set the Size
property to 95,110
and the SizeMode
: Move the TagID
label and its accompanying Label control (on the right) to the top.
Testing the Data Binding
To test that the data-binding works, you can now press F5
to debug the application. Figure 11
shows the application displaying the records in the Employees
|Figure 11: Testing to ensure that the data-binding works.|
|Figure 12: Populating the form with the various controls.||
Next you'll add controls to the form to allow an administrator to assign a RFID tag to a user. Figure 12
shows the controls to add.
For the txtTagID
control, set both the ReadOnly
and the Multiline
properties to True
In addition, drag a Timer control from the Toolbox onto the form. This control will ensure that the displayed employee record will be cleared after three seconds.