Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ Electronics ➜ Microprocessors ➜ RFID reader - HZ-1050

RFID reader - HZ-1050

Postings by administrators only.

Refresh page


Posted by Nick Gammon   Australia  (23,121 posts)  Bio   Forum Administrator
Date Fri 17 Apr 2015 12:39 AM (UTC)

Amended on Fri 17 Apr 2015 12:54 AM (UTC) by Nick Gammon

Message
I recently bought one of these readers from eBay for around $7.

The connection details were pretty sparse, so I thought I'd share what I deduced about it.

The reader comes with a plug-in loop aerial:



A close-up of the board with the pins identified:



Clearly it is using an Atmega8 processor to do its thing:



It also has an LM358 op-amp on it.

With all those pins on both sides it isn't obvious which ones to connect up to your Arduino for your access-control system / cat feeder or whatever you are building.

ICSP connector


Since it has an Atmega8 processor I deduced that the 6 pins on the left are for ICSP programming of the processor chip, and indeed they follow the standard signal names for doing that. Connecting those 6 pins to my chip detector sketch (http://www.gammon.com.au/forum/?id=11633) I got the following information:


Atmega chip detector.
Written by Nick Gammon.
Version 1.13
Compiled on Apr 17 2015 at 10:08:11 with Arduino IDE 106.
Attempting to enter programming mode ...
Entered programming mode OK.
Signature = 1E 93 07 
Processor = ATmega8A
Flash memory size = 8192 bytes.
LFuse = 3F 
HFuse = 99 
EFuse = FF 
Lock byte = FC 
Clock calibration = AF 
Bootloader in use: No
EEPROM preserved through erase: No
Watchdog timer always on: No
Bootloader is 2048 bytes starting at 1800


Since I could read all that, then it is definitely the ICSP connector on the left. Unless you are planning to reprogram it (and I don't know where the source is) I would leave those pins alone.

Data connector


On the right-hand side are 5 pins. The +5V and Gnd ones are self-explanatory, but what about D0/D1/TxD?

Well, it appears that TxD is all you need for an Arduino, as that is the "serial data out" which you can connect to a serial input pin on your Arduino (eg. digital pin 0).

Serial output


The baud rate is selectable by a jumper, either 9600 or 19200.

The serial data is simply four bytes, in binary, with no preamble or postamble. For example:



That particular card was code 00 31 E2 11.

I successfully read that by reading 4 bytes from serial, and assuming that if there was a gap of more than 300 mS then to reset the incoming data.

Example code:


const unsigned long TIMEOUT = 300;  // mS

// the most recent card, zero if none
unsigned long cardCode;

unsigned long timeLastSerialInput;
byte count;

void processNewCard ()
  {
  // do something with this card  
  }  // end of processNewCard
  
void processIncomingByte (const byte inByte)
  {
  unsigned long now = millis ();
  
  // if a long time has elapsed, assume new card
  if (now - timeLastSerialInput >= TIMEOUT)
    {
    cardCode = 0;
    count = 0; 
    }  // end of timeout
  
  timeLastSerialInput = now;
  cardCode <<= 8;
  cardCode |= inByte;
  count++;
  
  if (count >= 4)
    {
    processNewCard ();
    cardCode = 0;
    count = 0; 
    }  // end of having 4 incoming bytes
   
  }  // end of processIncomingByte
  
void setup()
  {
  Serial.begin (19200);
  }  // end of setup
  
void loop()
{
  // if serial data available, process it
  while (Serial.available () > 0)
    processIncomingByte (Serial.read ());

}  // end of loop


This simple example doesn't do anything with the data, but you could add your own code to the processNewCard function.

Wiegand protocol


The remaining two pins D0/D1 are for the Wiegand protocol. I presume they have put those there so you could connect the board to an existing system that expects that protocol.

From the same session with the same card, we see that it activates the D0/D1 lines somewhat later (around 640 mS later):



In this protocol both D0 and D1 are kept high, and then brought low briefly (around 2 mS), where D0 is low for a 0 bit, and D1 is low for a 1 bit.

In addition to the 32 bits of data there is an initial even parity bit of (I think) the first 16 bits, and then the data is followed by an odd parity bit of (I think) the second 16 bits.

According to the documentation I found the Wiegand 26 protocol applies the first parity bit to the first 12 bits and the second parity bit to the second 12 bits, so it seems logical that the Wiegand 34 protocol would similarly split the calculation of parity half-way.

You can select Wiegand 26 or Wiegand 34 with a jumper. If you use Wiegand 26 you only get 24 bits (3 bytes) plus the two parity bits. If you use Wiegand 34 you get 32 bits (4 bytes) plus the two parity bits.

More information


I found a post about something similar here: http://www.serasidis.gr/circuits/RFID_reader/125kHz_RFID_reader.htm.

This is not necessarily the same circuit or code, but from what he describes it sounds very similar. He uses an AtTiny85 and an LM358.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,121 posts)  Bio   Forum Administrator
Date Reply #1 on Fri 17 Apr 2015 04:53 AM (UTC)

Amended on Fri 17 Apr 2015 04:55 AM (UTC) by Nick Gammon

Message
In case you were wondering what is inside an RFID card (or button) I took a photo through a light box.



Sandwiched between the layers of plastic is a loop aerial, and in one corner a small processor chip.

When the card is in range of the RFID reader it receives the 125 kHz signal (or whatever frequency it is using) being transmitted by the reader, which provides enough power to run the processor. Thus, the processor rectifies the incoming 125 kHz signal, providing itself with power, so it powers up.

Then the processor responds by putting a load on the aerial, which makes it consume more power. This extra consumption is detected by the RFID reader, as it measures that the signal it is transmitting has dropped in amplitude slightly. This technique is also called backscattering (http://en.wikipedia.org/wiki/Backscatter).

By varying between load and no-load, the processor effectively can send 1 or 0 bits, which the reader detects and decodes.

The modulation method is PSK (phase-shift keying). http://en.wikipedia.org/wiki/Phase-shift_keying

More information on RFID: http://en.wikipedia.org/wiki/Radio-frequency_identification

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


21,023 views.

Postings by administrators only.

Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.