Practical Arduino Cool Projects for Open Source Hardware- P30 pot

10 136 0
Practical Arduino Cool Projects for Open Source Hardware- P30 pot

Đang tải... (xem toàn văn)

Thông tin tài liệu

C H A P T E R 14    RFID Access Control System RFID technology (pronounced “Arr-Eff-Eye-Dee” or “Arr-Fid”) is used for a wide variety of applications including access control, package identification, warehouse stock control, point-of-sale scanning, retail antitheft systems, toll-road passes, surgical instrument inventory, and even for identifying individual sheets of paper placed on a desk. RFID tags are embedded in name badges, shipping labels, library books, product tags and boxes; installed in aircraft; hidden inside car keys; and implanted under the skin of animals or even people. RFID systems work on a wide range of frequencies, have a variety of modulation and encoding schemes, and vary from low-power passive devices with range of only a few millimeters to active systems that work for hundreds of kilometers. With such a vast range of applications and related technologies it’s no wonder that most people are confused about what RFID actually is! Part of the problem is that the term “RFID” is a generic label for any technology that uses radio communication to check the identity of an object. All sorts of radically different systems fall under the broad banner of RFID. However, all RFID systems have the same basic two-part architecture: a reader and a transponder. The reader is an active device that sends out a signal and listens for responses, and the transponder (the part generally called the “tag”) detects the signal from a reader and automatically sends back a response containing its identity code (see Figure 14-1). Figure 14-1. Reader challenge and tag response One of the earliest RFID systems was developed in England in 1939 to solve the problem of Allied aircraft being targeted by friendly antiaircraft guns as they returned to base. Unfortunately, friendly aircraft returning home look pretty much the same as enemy aircraft approaching to attack, so radio 269 CHAPTER 14  RFID ACCESS CONTROL SYSTEM transponders called IFF systems (Identification Friend or Foe) were installed that would allow aircraft to automatically send out a coded “I’m a friend— don’t shoot me!” signal in response to challenges from defensive emplacements. Despite the age of the technology, it’s really only since the 1990s and the proliferation of inexpensive passive tags that RFID has gone from exotic to ubiquitous. Right now there are probably a dozen or more RFID tags within a few meters of you, and you might not even be aware of most of them. Different types of RFID tags fall into one of three broad categories: active, passive, and battery- assisted passive. Active tags are physically large because they require their own power supply such as a battery. They can also have a very long range because the availability of local power allows them to send high-powered responses that can travel from tens of meters to hundreds of kilometres. An active tag is essentially a combination of a radio receiver to detect the challenge, some logic to formulate a response, and a radio transmitter to send back the response. They can even have the challenge and response signals operate on totally different frequencies. The downsides are the size of the tag, a high manufacturing cost due to the number of parts required, and the reliance on a battery that will go flat eventually. Passive tags can be much smaller and cheaper than active tags because they don’t require a local power supply and have much simpler circuitry. Instead of supplying their own power, they leach all the power they need from the signal sent by the reader. Early passive tags operated on the “Wiegand effect,” which uses a specially formed wire to convert received electromagnetic energy into radio-wave pulses. Some early passive RFID tags actually consisted of nothing more than a number of very carefully formed wires made from a combination of cobalt, iron, and vanadium, with no other parts at all. Modern passive tags use a clever technique that uses current induced in their antenna coil to power the electronics required to generate the response. The response is then sent by modulating the reader’s own field, and the reader detects the modulation as a tiny fluctuation in the voltage across the transmitter coil. The result is that passive tags can be incredibly small and extremely inexpensive: the antenna can be a simple piece of metal foil, and the microchips are produced in such large quantities that a complete RFID-enabled product label could cost only a few cents and be no thicker than a normal paper label. Passive tags can theoretically last indefinitely because they don’t contain a battery to go flat, but their disadvantage is a very short operational range due to the requirement to leach power from the reader’s signal, and lack of an actively powered transmitter to send back the response. Passive tags typically operate over a range of a few millimeters up to a few meters. A more recent variation that combines active and passive technologies is BAP, or battery-assisted passive. BAP tags are designed to overcome the short life limitation of a normal battery-powered active tag. A BAP tag sits in an idle passive state most of the time and receives challenge signals in the same way as a normal passive tag, but then uses the tiny amount of power leached from the signal to charge a tiny capacitor and wake up the system enough to then activate a local power source, such as a battery, to transmit a very strong response signal before going back to idle mode. A BAP tag could sit passively for years using no power at all and emitting no signal, only drawing on its battery reserves when woken up by a challenge and sending a response. Although BAP tags have the long life advantage of a passive tag (limited only by the shelf-life of the battery), they still have many of the disadvantages of active tags, including high price and physically large size. BAP tags are still very rare and you’re unlikely to come across them at a hobbyist level. Common passive tags that you’re likely to find are generally classified as either low-frequency (LF) or high-frequency (HF) tags. LF tags commonly operate at either 125kHz or 134.2kHz, which is close enough that it’s sometimes possible to have a reader designed for one frequency communicate with a tag designed for the other, but that’s the exception rather than the rule. If you are buying LF tags, it’s always wise to check the actual frequency they are designed to operate at and make sure your tags and reader match. 125kHz tags are currently the most common in the U.S., but that frequency is now slowly being phased out in favor of tags that match the 134.2kHz international standard used pretty much everywhere else in the world. 270 CHAPTER 14  RFID ACCESS CONTROL SYSTEM Tags can also have a variety of different modulation schemes, including AM, PSK, and ASK, and different encoding systems. With so many incompatible variations, it’s sometimes hard to know if specific tags and readers are compatible. Generally speaking, each type of tag will only function on one specific frequency, modulation scheme, and communications protocol. Readers, on the other hand, are far more flexible and will often support a range of modulation schemes and comms protocols, but are usually still limited to just one frequency due to the tuning requirements of the coil. Apart from the specific requirements for communicating with them, tags can also have a number of different features. The most common passive tags simply contain a hard-coded unique serial number and when interrogated by a reader they automatically respond with their ID code. Most tags are read- only so you can’t change the value they return, but some types of tags are read/write and contain a tiny amount of rewritable storage so you can insert data into them using a reader and retrieve it later. However, most uses of RFID don’t rely on any storage within the tag, and merely use the ID code of the tag as a reference number to look up information about it in an external database or other system. RFID tags are produced in a wide variety of physical form factors to suit different deployment requirements. The most commonly seen form factor is a flat plastic card the same size as a credit card, often used as an access control pass to gain access to office buildings or other secure areas. The most common form by sheer number produced, even though you might not notice them, is RFID-enabled stickers that are commonly placed on boxes, packages, and products. Key fob tags are also quite common, designed to be attached to a keyring so they’re always handy for operating access control systems. Some of these are shown in Figure 14-2. Figure 14-2. RFID tags in a variety of form factors including access cards, key fobs, and a surgically implantable pellet Another common form factor is surgically implantable tags encased in a special biologically inert glass called “soda glass” and shaped to be approximately the size of a large grain of rice. Implantable tags are often coated with a special sleeve that is slightly porous to allow protein strands to grow into it and prevent it migrating under the skin after implantation. They are commonly used to tag domestic 271 CHAPTER 14  RFID ACCESS CONTROL SYSTEM animals such as cats and dogs so they can be identified by a vet or pet shelter using a special RFID reader if they are lost. Some people, including one of the authors of this book, have even implanted RFID tags in themselves so they can operate access control systems without having to carry anything!Tags also come in more exotic form factors such as inside special nails that can be hammered into objects that need to be tagged. They are also available as a ceramic bolus designed to be swallowed by cattle so it will sit in their stomach indefinitely for external scanning, and in tags attached to the ears of livestock. Several companies are also experimenting with producing paper that has a passive RFID tag embedded inside every individual sheet: by building an RFID reader into a pad that sits on a desk or on shelving, it’s possible for your computer to track the location of every single page individually. No more problems with a misplaced sheet in a big pile of paper.This project uses a prebuilt RFID reader module to interrogate commonly available passive tags, looks up the tag ID in an internal database, and releases a lock using an electric strike plate if the tag is authorized. You can also combine this project with the Speech Synthesizer project in Chapter 9 for audible feedback, or fit it into a handheld case and add an LCD to create a portable RFID reader. By combining it with flash memory for datalogging and a GPS module to log the location at which each scan was performed, you could build a reader with more features than just about any commercial device on the market today, but at a lower cost than even the most basic commercial readers. The required parts are pictured in Figure 14-3 and the complete schematic in Figure 14-4. Parts Required 1 Arduino Duemilanove, Arduino Pro, or equivalent 1 Prototyping shield 1 4-pin PCB-mount header with 90 degree bend 1 4-pin line header socket 2 2-pin PCB-mount screw terminals 1 12V electric strike plate 1 LM7805 voltage regulator 2 100nF capacitors 1 22uF electrolytic capacitor 2 1N4001 or equivalent power diodes 1 4K7 resistor 1 100K resistor 1 BC547, BC548, 2N2222, or equivalent NPN transistor 1 Red LED 1 Green LED 2 680R resistors 1 12V 1A power supply or plugpack 20cm Ribbon cable 272 CHAPTER 14  RFID ACCESS CONTROL SYSTEM 1 125kHz RFID tag 1 Small PVC box 1 ID-12 RFID reader module (www.id-solutions.com) 1 ID-12 breakout board or custom PCB, as explained in the text OR 1 RDM630 125kHz RFID module (UART version) from Seeed Studio For optional manual-release exit button: 1 Single-pole, single-throw (SPST) momentary pushbutton 1 2-pin PCB-mount screw terminal Lightweight two-core cable, such as figure-8 speaker cable Source code available from www.practicalarduino.com/projects/rfid-access-control-system. Figure 14-3. Parts required for RFID Access Control System 273 CHAPTER 14  RFID ACCESS CONTROL SYSTEM Figure 14-4. Schematic of common section of RFID Access Control System. Schematics for specific RFID modules included later Instructions For this project you have several options for compatible RFID reader modules, all of which communicate using a serial interface with RS-232–style comms at a 5V logic level— perfect for interfacing with an Arduino. The two we have listed are the ID-12 module from ID Innovations (available from online retailers, including SparkFun) and the RDM630 module (available from online retailers, including Seeed Studio), which both read a variety of 125kHz low-frequency tags. You can also substitute other modules if your requirements are different. For example, to read 13.56MHz MiFare-type tags you could use an RDM880 module, also available from Seeed Studio, which uses the exact same host interface. Whatever module you go for, look for one with a “UART“ interface rather than a “Wiegand” interface. The UART interface is designed for serial communications with a host such as an Arduino, so you can just treat the module as another serial device. The Wiegand interface requires a little more work to process from the host side. It’s not difficult to do and you can use a Wiegand module and modify the 274 CHAPTER 14  RFID ACCESS CONTROL SYSTEM code to suit if that’s all you have available, but the example code we present here assumes you are using a UART RFID module. So, which to use—ID-12 or RDM630? Both modules have pros and cons. The ID-12 is neatly packaged in a robust plastic container filled with resin to make it very strong, but has the downsides that the package uses nonstandard 2mm pin spacing so you can’t fit it to a standard prototyping board, and it’s more expensive. The RDM630 is cheaper and has a larger coil that’s separate to the module so the read range might be slightly better, but the module itself is physically larger than the ID-12, and because it’s an exposed PCB you have to be a bit more careful about mounting it. In the parts shown in Figure 14-3, you can see both an ID-12 module (the black square on the right) and an RDM630 (the PCB and separate coil just above the ID-12). You can choose for yourself based on your mounting requirements. Whichever module you use, the prototyping shield needs to be assembled in exactly the same way. Assemble the Prototyping Shield Because this project runs the Arduino as a stand-alone system independent of a host computer, it needs a regulated power supply to keep it running. The Arduino itself contains a built-in voltage regulator but it tends to run very hot if it’s given more than about 9V. Because the electric strike plate requires a large jolt of 12V power to unlock it, we’ve included a simple 5V power supply circuit on the shield so both the Arduino and the strike plate can run from the same 12V supply. That same supply is also switched through to a pair of output terminals for connection to the electric strike plate, so everything is as self- contained as possible with minimal cabling. One optional step before going on with the rest of the assembly is to install a 100K resistor between Arduino digital pin 0 (RX) and ground on the shield. You might not need it depending on your Arduino, but without it you might find the Arduino doesn’t boot properly when USB is disconnected. The resistor biases the RX pin to 0V while still allowing it to be pulled to +5V if required, rather than floating randomly between 0V and +5V. With a USB cable in place, the RX pin is asserted either high or low all the time and everything is fine, but if you power your Arduino from an external power supply and don’t have USB connected, the RX line could see random data and prevent the Arduino from booting. Biasing it to ground prevents this happening and makes sure it will start up reliably when it’s mounted in some inaccessible place such as under the floor or inside the ceiling while still allowing a USB connection to function normally. Power Supply The 5V power supply on the shield consists of an LM7805 linear voltage regulator, a 1N4001 or equivalent power diode, and a 22uF electrolytic capacitor (see Figure 14-5). Start by fitting the 2-pin screw terminal that will be used to connect the 12V plugpack, with one terminal connected directly to the ground rail on the shield. Use a felt-tip pen to clearly mark that terminal “–” and the other terminal “+” so you know which is which when it comes time to connect the external power supply. Then fit the LM7805 regulator so that the OUT pin is connected directly to the +5V rail on the shield. The 1N4001 diode can then be fitted between the “+” connection on the screw terminal and the “IN” connection on the LM7805. The diode is not strictly necessary and the + input could be connected directly to the voltage regulator’s IN pin, but including the diode is a good safety precaution just in case the power is ever connected up backward. Current will only flow through the diode in a forward direction so it acts as a one-way valve to prevent things from being damaged if the power supply is reversed by mistake. 275 CHAPTER 14  RFID ACCESS CONTROL SYSTEM Figure 14-5. 5V power supply assembled on shield Insert the 22uF electrolytic capacitor so that the positive lead connects to the joint between the regulator and the diode. Electrolytics normally have a long lead for positive and a short lead for negative, and the negative lead will also be marked on the body with a line and a minus symbol so you can tell which is which even after the leads have been cut to the same length. With the positive lead connected, bend the negative lead all the way down to the ground bus on the shield and solder it in place. If the lead isn’t long enough, use a short length of hookup wire or a component lead off-cut. The purpose of the capacitor is to provide smoothing of the input voltage since typical cheap plugpacks contain a tiny transformer that generates a rectified sine-wave output that varies between 0V and the maximum output voltage. Putting a capacitor across the input has the effect of holding the voltage high during the downswings of the sine wave, and provides a cleaner supply to the voltage regulator. The 22uF value isn’t anything special and was simply picked because it was high enough to provide a decent amount of filtering, while being low enough for the capacitor package to by physically small. If you have a different value handy that’s fine— you could use a 1uF or a 470uF capacitor, or anything in between. The final step in assembling the power supply is to connect the COMMON (center) pin of the voltage regulator to ground. Depending on the layout of your shield, you can probably connect it to the negative lead of the smoothing capacitor using a short length of component lead. Before doing anything else it’s a good idea to test the power supply section of the project to make sure you’re providing the correct voltage to the shield. Without connecting the shield to an Arduino, connect up a 12V plugpack to the input terminals and put a volt meter (such as a multimeter in voltage mode) across the ground and +5V rails of the shield. You should see a voltage between 4.95V and 5.05V, which means the voltage regulator is working as expected. 276 CHAPTER 14  RFID ACCESS CONTROL SYSTEM Doing an isolated test of the power supply circuit before continuing with construction is a good habit to get into with all your projects because if you made a mistake, you won’t damage anything else on the board. For example, an easy mistake to make is to forget to link the COMMON pin of the voltage regulator to ground. The result is that the voltage regulator runs in an unregulated state with no 0V reference voltage and, therefore, provides the full input voltage on the output—very dangerous to your Arduino! Testing the power supply in isolation helps you discover problems like this before any damage is done. You can see in Figure 14-5 that the prototyping shield we used for this project includes a couple of general-purpose LEDs that are connected to +5V through current-limiting resistors. We therefore put in a link from one of the LEDs to the adjacent ground bus so that it would provide a handy power-on indicator. RFID Serial Connection To make it easy to connect different RFID modules we used a 4-pin PCB-mount male header. If you’re doing the same, fit the header so that one end is connected to the +5V bus on the shield and then link the pin on the other end to ground. There’s no real standard for serial interface connections, but just out of habit the authors have commonly used headers that connect as shown in Figure 14-6. Figure 14-6. Serial connection pin assignments on an oriented 4-pin male header Both of the RFID modules recommended for this project use serial communications at 9600bps, so our example program uses the SoftwareSerial library to run a serial connection on digital I/O lines 4 and 5. We used line 4 as RX and line 5 as TX from the Arduino (see Figure 14-7). If all you want to do is power the device from an external power supply and read RFID tags then that’s all you need to do on the shield itself, but we’re going to use a relay to control an electric strike plate so we also need to connect a transistor-switched output. 277 CHAPTER 14  RFID ACCESS CONTROL SYSTEM Figure 14-7. Serial connection mounted shield for RFID module Relay Output The outputs of an Arduino are only rated to 40mA of current each, with a total limit of 200mA across all outputs combined. A relay big enough to activate an electric strike plate is likely to exceed the limit, so we use a digital output to control a transistor which in turn controls the relay (see Figure 14-8). Figure 14-8. Transistor output driving a relay 278 . such as figure-8 speaker cable Source code available from www.practicalarduino.com /projects/ rfid-access-control-system. Figure 14-3. Parts required for RFID Access Control System 273. to then activate a local power source, such as a battery, to transmit a very strong response signal before going back to idle mode. A BAP tag could sit passively for years using no power at all. section of RFID Access Control System. Schematics for specific RFID modules included later Instructions For this project you have several options for compatible RFID reader modules, all of which

Ngày đăng: 03/07/2014, 20:20

Mục lục

    Contents at a Glance

    About the Technical Reviewers

    Practical Electronics for Software Developers

    Current, Voltage, and Power

    Ohm’s Law and Current Limiting

    Test and Investigate Appliance Remote

    Assemble Reed Relay Shield

    Connect Reed Relay Shield to Remote Control

    Create Reed Relay Control Program

    Test Reed Relay Shield and Sketch

Tài liệu cùng người dùng

Tài liệu liên quan