XBee Active RFID
From Digi Developer
Contents |
Active RFID with XBee 232 Serial
Everyone should be familiar with the concept of RFID (or Radio-Frequency Identification):
- major retail chains use RFID to detect theft (aka: those door alarms which go off too often)
- many companies use an RFID badge or key-fob to manage door access.
- automated highway tolls use an RFID signal from the car to charge tolls.
The basic concept is simple and consists of three distinct parts.
- The RFID tag sends out a code at a fixed time interval - generally every few seconds. Most RFID tags are transmit-only devices which have no concern if any reader received the 'message'.
- Passive RFID tags are normally without power, thus normally quiet. They physically harvest power from a field generated by the reader, so can only send out codes when within a few inches of a suitable reader. Most door access and retail theft devices use passive tags. The tags are cheap and there are no batteries to fuss with.
- In contrast, Active RFID tags use a small battery to constantly transmit a code, giving them a much larger range - commonly dozens or even hundreds of feet. Active RFID is often used in vehicle or out-of-door systems where close-proximity with a reader is impractical.
- The RFID reader, which acts as a bridge between radio-frequency and 'the application'. Most readers do little more than announce to the central application when tags are seen.
- The Application is responsible to match up the actual presence or absence of tags with required actions. For example, the application might signal a door to open when a correctly coded tag is seen, or it might notify security if tags disappear from a controlled location.
Example Projects
In this project we'll use ACTIVE RFID tags because we want to detect the presence or movement of people - specifically allowing a 'work-space' to know when you leave, then turn off unrequired accessories like computer monitors, lamps and so on. A passive tag with the range of a few inches would force a change in user behavior, which would get tiresome and thus the system would not be used for long. Also, an active RFID tag with a range of 20-plus feet means the equipment starts powering up before you actually sit down in your chair.
In addition, a larger active RFID tag placed in your car would allow your house to know when you are out. It could for example text-page your cell phone if the garage door is still open 5 minutes after you leave, or text-page you if the garage door opens when you are not home. You can also have the outside lights turned on to greet you when you come home late at night.
A note on security/privacy
Remember that an active RFID tag is broadcasting to your environment "I - unit XYZ - am here". Literally, someone who knows which brand of tag you use can place readers to track your movement. A modern update of the old story where the mice wished to place a bell on the cat would have them placing an RFID tag on the cat instead, allowing the mice to locate the cat even when it slept!
In fact, most product brands allow the creation of DUPLICATE TAGS, so do not use this simple design to automatically open your home door! These products are not suitable for home security - they are for home automation and hobbyist fun!
Obtaining Hardware
You will find very few RFID products on sale for consumers - most large manufacturers only sell directly to OEM companies which customize the products to be sold as a total solution including the large central application. You will also find several source for hobbyist-style RFID components - raw boards which you can place in your own enclosure. Most brands would work. What you desire is a simple reader which sends the tag codes out as they are received.
The RFID devices being sold by http://cliste.sailwhatcom.com/ were selected for this project. You will require at least:
- Active RFID Receiver (the RS-232 version - NOT the USB version)
- Active RFID Transmitter (this model has a range of about 25 feet - there is another model with a range of 120 feet)
- Digi XBee ZB RS-232 adapter with the appropriate power supply
Again, most brands of RFID equipment will work - you need an RS-232 reader and a tag to read.
Embedding the XBee 232 Adapter into the reader
The first hurdle you will discover with this particular RS-232 RFID reader is that it expects to draw 12vdc power from the RS-232 port of a traditional IBM PC-class computer - this is a trait shared by many 'self-powered' RS-232 devices.
However, the EIA/RS-232 standard permits operation with any voltage between +3vdc and +15vdc. A Digi gateway such as the ConnectPort X4 and the Digi Xbee 232 Adapter both put out roughly 5 to 6vdc only, so while you'll find the RS-232 RFID reader works fine on your desktop, it won't function on either of those Digi products.
Fortunately, the XBee 232 Adapter offers an (almost) perfect solution - it will supply up to 50mA of 12vdc power on the DB9 pin #9 (this would be perfect if the power was the pin 4/DTR output instead of pin 9!). However, since we'll be hiding the XBee adapter inside of the RFID reader box, we will need to create a short custom cable anyway. So we'll run the pin #9 of the XBee 232 Adapter to the DCE DTR 'input', which provides the RFID reader with far more reliable power than any standard RS-232 port can offer. Another nice thing about this output power is it remains 12vdc even if the XBee 232 Adapter is being powered by 4vdc or 30vdc.
Make a 2 or 3 inch long, 4-wire cable with these pin-outs:
| XBee 232 DTE DB9 male, so cable is female | RFID Reader DCE DB9 female, so cable is male |
|---|---|
| Pin 2 - Rxd input | Pin 2 - Rxd output |
| Pin 3 - Txd output | Pin 2 - Txd input |
| Pin 5 - Signal Ground | Pin 5 - Signal Ground |
| Pin 9 - Auxilliary power output | Pin 4 - DTR input (this is DCE port!) |
You need to keep the custom cable small and flexible, so do not use 'hoods' or 'shells', plus use individual wires, not a multi-core cable. The entire cable will be hidden within the RFID reader housing. You could loop the pin #9 back to the XBee 232 Adapter's pin #6 (DSR Input) to create a
Configuring the XBee 232 Adapter
Review the full, up-to-date information on the page Digi XBee RS-232 Adapter
In summary, configure the XBee 232 Adapter to forward all data to another node. Most likely this is to your gateway, but you could also send it to another XBee 232 Adapter. You need to configure the following settings:
- set the PAN Id and other operational settings
- set DH/DL to the MAC address of the destination for the RFID data
- set the baud rate to 9600,8,N,1 (is the default for most XBee Adapters)
- set D2 to 5 to assert (turns on auxiliary power)
- although none of the control signals are required, you should probably set them as digital outputs and inputs as indicated on Digi XBee RS-232 Adapter
- setting IR to non-zero will cause the status of the digital I/O to be automatically sent on a time cycle to the address in DH/DL (aka: send you the RS-232 control signal status)
Parsing the Incoming Data
Here is an actual packet from an RFID tag read - the data is the five bytes "31 61 4b 6f 20".
7e 00 17 91 00 13 a2 00 40 52 18 99 19 14 e8 e8 00 11 c1 05 01 31 61 4b 6f 20 35
Review the standard PDF manual for your XBee flavor to fully decipher this message, which is a frame type 0x91 or Explicit Rx Indicator. Without going into detail, is can be parsed as:
| XBee 232 DTE DB9 male, so cable is female | RFID Reader DCE DB9 female, so cable is male |
|---|---|
| 7e 00 17 | Start and length of the API Frame |
| 91 | Frame Type |
| 00 13 a2 00 40 52 18 99 | MAC address of the XBee+Reader (you can have multiple) |
| 14 e8 e8 00 11 c1 05 01 | } |
| 31 61 4b 6f 20 | Serial Payload - 5 bytes of data |
| 35 | Checksum of the frame |
Additional Discussions
The fuzzy nature of RFID range
Unless you have metal-lined walls, you won't be able to use RFID to turn lights on or off on a room by room basis. An RFID tag with a 25-foot range means you can at best know if someone is a certain part of a house - for example if someone is in 'the garage area' or the 'bedroom area'.
You can play with the antenna wire of the reader or tag in an attempt to reduce range, yet then you risk creating dead spots where the user is in the room, but the signal is lost and the lights turn off. You'd also experience all the room lights needlessly turning on then off as you walk along a hallway.
I have used this Active RFID tag in my 'cube' at work for over a half-year. At times my equipment powers up when I am a good 50 feet way. At other times it powers up only when I am about to sit at my desk. If I walk past my cube on the way to someplace else - or I fill the bird-feeders outside of my office window - then my equipment powers up. So ideally, the application should use multiple sensors to detect my presence or absence.
If the RFID tag is in my pocket, then my keys or cell phones can block the signal, causing my computer displays to power off. In addition, some day the battery in the RFID tag will die. Make sure you have an easy way to manually override the powering off of your displays! In my design I have manual push-buttons which allow me to turn the equipment on or off without any intelligent XBee control
Noisy Data
Since the RFID tags send out a faint signal, low-cost units may return bad values (tags which do not exist). If two tags transmit at the same instant, the reader might merge them into one bad message. So if you expect 8 bytes of data, be prepared to see more or less than 8 bytes. Your neighbor might also buy the same Active RFID systems, and then you'll see frequent unexpected tag values.
Secondary Values
The RFID reader must be fully awake and powered - the RFID tags blindly 'chirp' out their code so the reader has to ready at every second. This makes them nice general-purpose routers in your mesh.
If you buy the 3-6vdc version of the XBee 232 Adapter, then you can couple it with an XBee LTH Sensor (the light, temperature, humidity device). Although by design it operates on 3 'AA' batteries (so 4-5.5v) you can easily modify it to run on 5vdc by soldering a linking wire to the XBee 232 Adapter. Then you have not only the RFID reader, but a light and temperature input at that site.
Making the RFID detection more directional
Mounting the RFID reader on a metal plate is an easy way blind the reader in one direction. Mounting the RFID reader inside a metal 'wall outlet box' or mounting it on a metal plate on a closet wall can easily make it more directional - to for example only detect tags in one of the three bedrooms of your home, but not the rest of the house.
Since RF is RF, this would interfere with the use of the XBee attached as a general purpose router, but you could mount the XBee adapter externally in this case.
