Using RFID with an Arduino

in #steemstem6 years ago (edited)

Introduction

This is a video I made demonstrating the use of a RFID module with an Arduino development board. The demonstration shows how to detect a specific tag and control a RGB LED. In my example the keychain RFID turns the LED Green, and all other tags, or no tag present will turn the LED red.

As seen in the video, I started with sample code from Arduino, and modified it with the code provided in this post.

Considerations

The embedded Arduino code is based on C/C++. Memory management is relative working with any micro-controller but I did not run into memory issues even with the 2kB RAM available in the ATmega328.

The RFID Reader uses serial, and I am using Hardware Serial (RX and TX pins). Software serial can be used provided the proper baud is set. The link below has examples of both (See Source).

Theory of Operation

The RFID module energizes the tags with radio frequency, and the tags report the ID. RFID Tags do not require batteries and use the RF energy from the module as the power source. This module transmits the the RFID of the tag over the serial port and is received by micro-controller as a string of characters. I used the Arduino with ATmega328 and Parallax RFID module.

Hardware

Parallax 28140
Arduino UNO or equivalent with ATmega 328
The LED is a RGB (Red, Green, Blue) common anode.

Software

The String Compare strcmp () function was used for the task of finding a specific TAG. The strcmp() function requires string.h and while I included the library in the code, Arduino will find the library by default.

if (strcmp(code, "InsertYourTAGID_here") == 0) { //detects specific tag id 
     // do this is specific tage is detected } 
else { 
     // do this if the tag is not correct }

Source
Sample Code and connection detail: https://playground.arduino.cc/Learning/PRFID
The example provided with module enabled the RFID module and reads the TAG, and then displays the TAG ID on the serial monitor. I modified the example with string compare function using the details above to detect a specific tag ID.

Coin Marketplace

STEEM 0.28
TRX 0.12
JST 0.033
BTC 69747.29
ETH 3747.51
USDT 1.00
SBD 3.78