Shop OBEX P1 Docs P2 Docs Learn Events
World's simplest RFID reader? — Parallax Forums

World's simplest RFID reader?

scanlimescanlime Posts: 106
edited 2014-02-26 11:56 in Propeller 1
Update: The latest code and schematics are now have a home in the Object Exchange: obex.parallax.com/objects/374/.

I've been interested in building an RFID reader for a crazy project a friend of mine is working on (automated beer dispensing system [noparse];)[/noparse] and it was an excuse to do some analog tinkering, so I had a go at building an RFID reader with the Propeller. Why not use Parallax's fine RFID reader accessory? I wanted to be able to read any off-the-shelf card, including common proximity ID badges.

I just got it working. I'd love to be proved wrong, but as far as I know this is the world's simplest RFID reader design:

simple-rfid-schematic.png

Edit: All capacitances are in picofarads. C1 and C3 should be 1000 pF, not 1000 nF. Likewise, C2 is 2200 pF.

Yep.. just a propeller and a few passive components. To understand this circuit, it's helpful to know how RFID works first. Here's the 10-second RFID primer for those who aren't already familiar with it:

RFID tags work via magnetic fields, like a transformer. A coil in the reader generates a magnetic carrier wave, which is picked up by a coil in the tag or card. This carrier wave powers the card, and provides it with a clock reference. To send data, the card varies the amount of current it draws from the reader's field, attenuating the carrier wave slightly. This attenuation is usually used to send some kind of modulated signal. The card I've been testing with uses a 125 kHz carrier wave, and FSK (Frequency Shift Keyed) modulation. Zeroes and ones are attenuation waveforms with different frequencies.

So, step one: generating a carrier wave with the propeller. I use a counter, naturally, and I generate a differential-drive signal on two pins. This gives me 125 kHz at about 6.6V peak-to-peak. I use an LC tank tuned near 125 kHz to amplify this and shape it into a sine wave. Here's my carrier wave, measured at the junction between L1 and C1. Note the scale- it's about 20 volts peak-to-peak! (Also notice that my tuning isn't quite perfect. Sadness and despair!)

normal-carrier.png

When you bring a proximity card near the reader coil, you can see the attenuation waveform overlaying the carrier wave. This is at the same voltage scale, measured at the same point, but I zoomed out on the X axis so you can see the pattern clearly:

modulated-carrier.png

To detect this signal, I use D1, C2, and R1 as a peak detector and low-pass filter, to remove the majority of the high-voltage carrier wave. This is then AC coupled via C3. At this point, the left side of C3 has a "floating" low-voltage waveform that I can position anywhere I want, by changing the bias on C3.

To generate this bias voltage, I use CTRB in DUTY mode. I'll explain why I call this pin "threshold" later. R4 and C4 are a low-pass filter give me an analog output voltage from CTRB. This signal is usually DC- it's used for calibration.

R3 "pulls" the floating waveform toward the analog value output by CTRB. Now I take advantage of the Propeller's Vdd/2 input threshold, and use the "input" pin as a comparator. (R2 is just to limit high-frequency noise.) Now I can use the CTRB voltage to adjust the detection threshold- how much attenuation causes "input" to read 0 vs 1.

Now I have a digital signal, but it's still really noisy. I use an assembly-language cog to reject as much noise as possible, and time the resulting FSK pulses. This image shows the analog signal at the junction between R2 and C3, along with the digital pulse detector's output. The amount of time between pulses signifies a "1" or "0" bit. In this case, the detection threshold is at 9 carrier wave cycles. Less than 9, it's a 0. More than 9, it's a 1 bit.

proxcard-fsk-detect.png

End result: I can display the 512 bits of data from my corporate proximity badge. Neat.

I'd include more details on the actual data I've captured and the protocol, but so far I've only been able to test this with a couple ID badges from the office and I'd rather not share those bits [noparse];)[/noparse] I have a Parallax RFID starter kit on order, so I'll let you know if I can read any of those tags successfully.

Source code is attached, but be warned it's hugely messy.

Post Edited (Micah Dowty) : 9/8/2008 9:22:00 PM GMT
«1

Comments

  • Matthew HayMatthew Hay Posts: 63
    edited 2008-08-22 11:09
    My hat is off to you sir (not that I wear one but if I did).

    I've always wondered what it took to make an RFID reader.· I have an old badge from a place I used to work that I've always wanted to play with, just might have to make one of these.

    Thanks for sharing your work too.
  • RaymanRayman Posts: 13,799
    edited 2008-08-22 12:24
    Very neat!
  • Ken PetersonKen Peterson Posts: 806
    edited 2008-08-22 12:45
    Micah: Cool project. I'll have to try that sometime. How do you know what carrier frequency to use for a given card? Is the protocol the same for most of them?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"I have always wished that my computer would be as easy to use as my telephone.· My wish has come true.· I no longer know how to use my telephone."

    - Bjarne Stroustrup
  • parskoparsko Posts: 501
    edited 2008-08-22 14:15
    Micah,

    You're certainly my hero!!! I've thought of doing the exact same thing. When I was working on the project, I was using the EM4095 that I removed from the Parallax reader board. I had always thought that it could be done with only a Prop! But, I hadn't gotten around to starting it. You have proven this!!! For me, the problems were always the hardware (aka, the circuit you show in your first post). You have just placed this in my "drop what you're doing and do this" list. I think I'll have a go at it. I have a couple regular tags that I can use that aren't work related.

    Good work. My hat is off to you too (and I DO wear hats!).

    Man, you're my hero!

    -Parsko
  • parskoparsko Posts: 501
    edited 2008-08-22 14:23
    BTW, if you could get a picture of two of your setup, that'd be nice! And a schematic with pin connections??

    -P

    Post Edited (parsko) : 8/22/2008 2:30:26 PM GMT
  • scanlimescanlime Posts: 106
    edited 2008-08-22 17:20
    @Ken: RFID tags seem to be a little like consumer IR remote controls.. there are some oddballs that use different carriers, but most of them use the same frequency. 125 kHz is really common. I think the fancier ones, like the Visa PayWave credit cards, use higher frequencies. I seem to remember reading that they used a 5 GHz carrier, but I don't remember if that's correct.

    @parsko: The pins in the schematic can be any Propeller pin. In my setup, I used P1 for CARRIER+, P5 for INPUT, P6 for THRESHOLD, and P7 for CARRIER-. I did find that you really don't want the INPUT pin to be directly adjacent to either of the CARRIER pins, since they add a lot of electrical noise.

    Here are some pictures of my setup:

    rfid-1.jpeg

    rfid-2.jpeg

    --Micah
  • bambinobambino Posts: 789
    edited 2008-08-23 04:21
    Sweet!
  • PFloyd36069PFloyd36069 Posts: 135
    edited 2008-08-23 05:12
    so is that wooden thing that the card is sitting on< your coil? does it matter what gauge or how many turns? Nice job by the way!
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-08-23 07:11
    Micah,

    This is quite a coup and an excellent app to demonstrate the Prop's capabilities! Congratulations! (Is your bench always that neat, or did you tidy up for the photos? smile.gif )

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!
  • william chanwilliam chan Posts: 1,326
    edited 2008-08-23 07:36
    Can the coil be made smaller? like 4" x 3"?

    How do you arrive at the correct threshold voltage to be able to read?
    Is the threshold voltage auto adjusted by the propeller?

    Will the 20volts generated by the coil kill the IO pins of the propeller?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.fd.com.my
    www.mercedes.com.my
  • scanlimescanlime Posts: 106
    edited 2008-08-23 08:46
    @PFloyd36069: Yep, the wooden thing is my coil. The number of turns definitely matters, since this is the primary factor that determines the coil's inductance. I used about 30 turns, but ideally the coil should be tuned such that the LC circuit (L1 and C1) resonates at 125 kHz. This will give the best carrier wave amplitude. I don't think the wire gauge matters much. Regular hookup wire is probably too bulky to be practical, but any magnet wire should work well.

    @Phil: Thanks. The desk is actually a bit tidier than usual, since I recently swapped my gigantic Hitachi analog scope out for a Bitscope. More room for the mess to spread out [noparse];)[/noparse]

    @william: The coil can probably be made smaller if you compensate by adding more turns. I used this size just because I had a scrap piece of wood handy, and I didn't feel like cutting it. The threshold voltage is currently just something I had to manually tune. I plan to have the Prop automatically calibrate the threshold, I just haven't had a chance to write that code yet. The 20 volts across L1 is safe, since it isn't present on any I/O pins: The actual CARRIER+ and CARRIER- pins are just normal 3.3v outputs, and the peak detector filters the coil voltage into something much lower (much less than a volt) before it ends up at the INPUT pin.

    Some good next steps for this would be:

    - Try other coil geometries and sizes
    - Implement automatic threshold calibration
    - Try other flavors of low-frequency RFID devices
    - Clean up the code, make it more robust, and put it on the object exchange.
    - Figure out what all those bits on my prox card actually mean [noparse]:)[/noparse]

    I might have time to do some of these this weekend.

    --Micah
  • scanlimescanlime Posts: 106
    edited 2008-09-02 01:17
    I just did a substantial rewrite of the code for this reader. Using pretty much exactly the same hardware (some component values have been tweaked), I can get performance comparable with Parallax's RFID reader, *and* I can support multiple card formats. Currently it supports the EM4102-style tags sold by Parallax, and the HID 125 kHz access control cards used by many corporations and schools.

    Attached is my latest version of the "rfid-lf" object, as well as a simple access control example. It just needs two cogs, 6 I/O pins, and a handful of resistors and capacitors. It still uses no external ICs or active components at all. With the same coil I was using above, I can read the white plastic card RFID tag at a distance of a little over 4 inches.

    The software is now much more complicated, and it operates under slightly different principles. The object has header comments that explain in more detail, but it's basically using the duty cycle of the peak detector pulse as a way of doing A/D conversion on the carrier wave envelope, then it feeds that value into various software filters and decoders in order to extract the RFID tag's data.

    Try it out, and let me know if you have any luck using it. If it works well for others, I'll post it on the object exchange.

    --Micah
  • william chanwilliam chan Posts: 1,326
    edited 2008-09-02 02:53
    Automatic calibration of Threshold voltage?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.fd.com.my
    www.mercedes.com.my
  • PhilldapillPhilldapill Posts: 1,283
    edited 2008-09-02 03:25
    Do I smell another nugget of gold soon to be in the OBEX? [noparse]:)[/noparse]
  • scanlimescanlime Posts: 106
    edited 2008-09-02 05:51
    william chan said...
    Automatic calibration of Threshold voltage?

    Yep. It automatically calibrates both threshold voltage and carrier frequency, so you're always running at the peak of the LC tank's resonance. The threshold voltage is calibrated using a linear control loop, and there is a simple hill-climbing optimizer which tweaks the carrier frequency. As a result, it's much less sensitive to actual component values now. I've been pretty careless when winding antenna coils, and it will still work almost as well as with a perfectly tuned coil.

    As an aside, I just wired up my prototype as a garage door opener. Now I can put my wallet (with the ID card from work) up to the front of the house, and open the garage door while I'm on foot or on my bike [noparse]:)[/noparse]

    --Micah
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-09-02 06:24
    Tres cool! I've pretty much ignored RFID to this point, but I'm going to build one of these just because it's so neat. I think I've got a spare ChampionChip tag around here to try it on...

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!
  • Beau SchwabeBeau Schwabe Posts: 6,545
    edited 2008-09-02 06:48
    Micah Dowty,

    Cool project!! ... you'll like the (Garage Door-Foot/Bike) option.... [noparse]:o[/noparse]) .... And Kudo's to you for being a "coil" guy!


    When we first moved in, our house had a keypad entry ... without an instruction book, I did mange to figure out how to re-program the keypad, but
    after a few days it would not retain it's new code. My solution was to replace the keypad with one of our RFID readers. So far it's been in operation for just over a year.

    http://forums.parallax.com/showthread.php?p=655395

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • scanlimescanlime Posts: 106
    edited 2008-09-02 07:53
    Nice job on the installation, Beau. It looks very professional. I also like the buzzer- I thought about including a speaker in mine, but I was so thrilled that the RFID was working that I didn't have the patience to add any extra parts [noparse];)[/noparse]

    I'll have to take some pictures of mine once there's some daylight available. My house has pretty thin walls (maybe 1 inch of siding) on either side of the garage door, so I was able to duct tape my coil (about 60 turns of magnet wire around a 6x6" form, coated in epoxy and electrical tape) to the felt backing on the wall. So from the outside, it's completely invisible. Nothing to anger the homeowners' association...

    --Micah
  • scanlimescanlime Posts: 106
    edited 2008-09-02 15:50
    Some pictures, with links to larger versions. The yellow heat shrink tubing in the first picture holds a 3/4 amp fuse for the power supply. The circuit on the protoboard is exactly the same as the schematic in rfid-lf.spin, with the addition of a bi-color LED, TV output (for debugging), and reed relay. It's running an unmodified copy of rfid-door-control.spin. The IC sockets are unused; they were just left over from previous experiments. This is reading a HID prox card through the front of the house (and my wallet) with only passive components.

    IMG_0322.JPG IMG_0323.JPG IMG_0324.JPG IMG_0325.JPG IMG_0326.JPG

    --Micah

    (Edited to put some space between the pictures, so this isn't so wide...)

    Post Edited (Micah Dowty) : 9/2/2008 5:53:44 PM GMT
  • pgbpsupgbpsu Posts: 460
    edited 2008-09-02 17:05
    Micah-

    Congrats on a very cool project.

    Totally off topic. I see you're using BitScope software (and hardware?). What model and how do you like it for
    debugging/working with the prop?

    Peter
  • scanlimescanlime Posts: 106
    edited 2008-09-02 17:14
    pgbpsu said...
    Micah-

    Congrats on a very cool project.

    Totally off topic. I see you're using BitScope software (and hardware?). What model and how do you like it for
    debugging/working with the prop?

    Peter

    I have the new opto-isolated BS100U. I'm actually really happy with it. It's a big step up from my clunky old analog scope. I really like the mixed-signal mode, and the software is pretty decent. The design is also mostly open. They ship you schematics in the manual, and the protocol is documented online. My only real complaints: It's a little on the slow side (only 40 MSPS), it's kind of overpriced for what you get, and the web site is pretty outdated.

    --Micah
  • parskoparsko Posts: 501
    edited 2008-09-10 14:03
    Micah,

    What is your impression of these results?

    I have not debugged hardware. But, I made up an antenna, and this is the output of your latest file. Not sure what to make of it. Seems to me like it isn't latching on to any data from my key fob.

    My setup is on a breadboard. I know these kinds of circuits tend to like soldered connections, where even a perf board is much better. That is my next major hardware step. My breadboard setup was just to see if I could get it going. I put my scope in the area, and it does seem to be getting a 125kHz wave (8us from peak-to-peak), but I'm only gettting about 1V peak-to-peak. You suggest being able to get close to 20V p2p. I only had about 10 minutes to futz with it last night before bed.

    Also, my key fob's seem to have more digits in the ID number associated with them. I can't seem to match it up with yours. I will do some further investigations in the next few sessions I have. For now, I thought I'd shoot this out to see if you had any initial obvious reactions.

    Without (me) doing any homework, I'll ask the quick question of what the three columns of numbers are indicating?

    Thanks,

    -Luke

    First_run_01.jpg
  • scanlimescanlime Posts: 106
    edited 2008-09-12 03:42
    Hi Luke,
    parsko said...
    What is your impression of these results?

    Looks mostly like noise to me. You could be getting a really weak or noisy signal on the input pin, and occasionally the bit errors line up such that the receiver's parity check succeeds and you get a bogus packet value.

    To answer your other question too, the three numbers are:
    • The first long is the FORMAT constant, which identifies what type of RFID code has been detected. The value $00010002 is FORMAT_EM4102, which identifies the RFID protocol used by the tags that Parallax sells. The low word of this identifier also happens to tell you how many longs of data are present in each RFID packet.
    • The second long is the manufacturer ID from the EM4102 tag. In my experience, this should always be $36 for the key fobs that Parallax sells.
    • The third long is the 32-bit unique ID from the EM4102 tag. On the key fobs, this number is actually printed on the back of the fob in decimal.
    parsko said...
    My setup is on a breadboard. I know these kinds of circuits tend to like soldered connections, where even a perf board is much better. That is my next major hardware step. My breadboard setup was just to see if I could get it going.

    You might get better range from a perf-board prototype, but in my experience this circuit was actually fine on the breadboard. It will change the capacitances a bit, but the automatic tuning should be able to deal with it. I used this circuit successfully with the prototype area on my Demo Board.
    parsko said...
    I put my scope in the area, and it does seem to be getting a 125kHz wave (8us from peak-to-peak), but I'm only gettting about 1V peak-to-peak. You suggest being able to get close to 20V p2p. I only had about 10 minutes to futz with it last night before bed.

    Where are you measuring the voltage? If you're just laying the scope probe next to the coil, that's a good way to measure the shape of the wave and the actual field strength, but it won't give you the same high voltages that you see on the coil itself. If you're just sitting the probe next to the coil, 1V p-p is totally fine.

    If you're measuring at the L1-C1 junction, you should see a very high voltage sine wave. The higher the better. It should always be higher than 6v (which is what you'd get without any LC resonance). This voltage should be at least 20V or so, and preferably more like 100V. If this voltage is low, you can improve it by picking L1 and C1 to give you a higher Q ('quality') factor for the LC resonance. The Q factor is influenced by many things, but the two most important are (1) the type of wire you use for L1, and (2) how close you are to the LC tank's resonant frequency.

    You should be able to read RFID tags reliably at close range using fairly small wire. My first few coils used 32-gauge magnet wire. I did get better range (due to higher Q) using 24 gauge wire. It also may help to use stranded wire, which has a high surface area that decreases its resistance at high frequencies.

    The second factor, LC resonance, is the most important. The software can automatically fine-tune the resonance in order to track small changes in capacitance or inductance, but you'll need to manually tune it enough to get it in the right ballpark.

    As a first step, you can run some experiments to tell you how far off your resonance is. For these experiments, set the CARRIER_GAIN to zero, to disable the automatic calibration. Now try adjusting CARRIER_HZ up or down until you see the highest sine wave amplitude. If you have a pretty low-capacitance scope probe you can measure this at the L1-C1 junction, otherwise try just sitting the probe on top of the coil. Adjust the CARRIER_HZ up or down by 10 kHz at a time, at first, then when you get closer you can start changing it by smaller amounts.

    So, there are a total of three ways to tune the circuit: Change L, change C, or change CARRIER_HZ. You just did the latter. If the resulting frequency is pretty close to 125 kHz (close enough for your RFID cards- so probably +/- 15 kHz or so), you're done. Otherwise, you need to change L1 and/or C1. Changing C1 requires some care, because if you change it too much you can reduce the sensitivity of the peak detector circuit. So, it's best to change L1. If your resonant frequency is too high, add more turns to L1. If it's too low, remove turns.

    I usually try to wind the coil using more turns than I need, then I'll test it by scraping off a little of the insulating varnish and connecting it with alligator clips. You can repeat this, removing a few turns at a time until the resonant frequency is close to 125 kHz.
    parsko said...
    Also, my key fob's seem to have more digits in the ID number associated with them. I can't seem to match it up with yours.

    Hmm. It's possible that we have different brands of key fob. Mine has a 10-digit decimal number on the back, which matches the low 32 bits of the fob's unique ID. If you have one of the Parallax RFID reader modules, it should give you a 40-bit hex number which matches the last 40 bits of the number that rfid-lf gives you.

    Hopefully these hints help a bit. Good luck, and let me know how things go. If you're still having trouble after tuning your LC circuit, I can talk about ways to debug the input section of the circuit.

    --Micah
  • scanlimescanlime Posts: 106
    edited 2008-09-12 04:16
    Maybe this weekend I'll have time to whip up a "Build an RFID reader from scratch in 30 minutes" Instructable, with info on how to tune the coil and how to test each piece of the circuit [noparse];)[/noparse]
  • parskoparsko Posts: 501
    edited 2008-09-12 13:53
    Micah Dowty said...
    Maybe this weekend I'll have time to whip up a "Build an RFID reader from scratch in 30 minutes" Instructable, with info on how to tune the coil and how to test each piece of the circuit [noparse];)[/noparse]

    That is basically what I did the other night!

    Thanks for the response. It is quite thorough, and should also give the next guy some great insight into debugging. I've done enough of this that I'm mostly familiar with all the concepts you laid out.

    Yes, I have simply been placing the probe near the coil. In the past, with the Parallax reader, I found this technique quite effective. This time, not so much. Again, in my defense, I didn't put much time into it due to it being close to my bedtime.

    I'd recommend, in your objects, to update it with the info you provided here, or a link to this post. I was confused with your output, and putting that in the header would have resolved that.

    My key fobs are indeed Parallax fobs that work on the EM4102 format. This seems to be coming through in my picture, I guess.

    Also, if there were a way to debug this in your "Build an RFID reader from scratch in 30 minutes" guide, where someone without a scope could get good results, that would be cool. What I'm thinking is along the lines of: Go to Ratshack and get 30ga. wire, wrap it around a coke can 46 times, use a 1000pF cap, use pin 10, and the "debug cog", and you can sense if your coil is tuned right. I think you are doing this, somewhat, but you have only one coil. I have read that you could use a second coil as the "sense" coil that is tuned to your, kinda like this:

    fig14.jpg

    Maybe that would make debugging easier?

    Anyway, I'll try to play again this weekend and post my results. I don't think I'm far off.

    Thanks!

    -Luke
  • parskoparsko Posts: 501
    edited 2008-09-12 17:17
    Attached is a sample calculation for inductance, frequency, and Q factor. This is what I used to make my antenna. BTW, the picture I attached earlier was NOT the antenna I am using in this experiment. It is from this dude's very informative website!

    -Luke
  • jskajska Posts: 1
    edited 2009-11-16 19:02
    Micah,
    Congratulations on the design of such an elegant RFID reader. I have built one based on your design and it works beautifully with standard cards. I have also seen your posts on building RFID tags using only an AVR ATtiny85 controller (or a controller with an antenna and caps) and am in the process of trying to build some of these as well. My question is whether you think that the ATtiny85 could be modified to act as a sensor rather than just sending back a number, such that the number sent back could be modified by a detected voltage. I am hoping that with relatively simple modifications to your tag as designed, one could make remote sensing devices, still operating in the passive mode without the necessity for battery power. Thanks again for sharing your designs.
    jska
  • RS_JimRS_Jim Posts: 1,751
    edited 2009-11-20 11:37
    Micah,

    Did you ever get your "How to .." Manual written?
  • asadasad Posts: 3
    edited 2010-04-08 10:31
    hi,

    am not sure if you still answer here but wonderful project. i am also working on reader prototyping. i wanna know if the response at the reader antenna from the tag gets superimposed on the carrier being originally generated by the reader?. or else one should stop the generation of the carrier at the reader and wait for a tag response?


    regards
    asad
  • scanlimescanlime Posts: 106
    edited 2010-04-08 22:02
    asad said...
    hi,

    am not sure if you still answer here but wonderful project. i am also working on reader prototyping. i wanna know if the response at the reader antenna from the tag gets superimposed on the carrier being originally generated by the reader?. or else one should stop the generation of the carrier at the reader and wait for a tag response?


    regards
    asad

    It's superimposed. The tag "transmits" data back by modulating the amount of power it uses, really. So the signal will appear as small changes in the voltage you read across the reader coil.
Sign In or Register to comment.