Silicon ChipKickStart - April 2021 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Subscriptions: PE Subscription
  4. Subscriptions: PicoLog Cloud
  5. Back Issues: PICOLOG
  6. Publisher's Letter
  7. Feature: The Fox Report by Barry Fox
  8. Feature: Techno Talk by Mark Nelson
  9. Feature: Net Work by Alan Winstanley
  10. Project: DIY Solder ReFLow Oven with PID Control by Phil Prosser
  11. Project: Programmable Thermal Regulator by Tim Blythman and Nicholas Vinen
  12. Project: Frequency Reference Signal Distributor by Charles Kosina
  13. Feature: KickStart by Mike Tooley
  14. Feature: Max’s Cool Beans by Max the Magnificent
  15. Feature: Max’s Cool Beans cunning coding tips and tricks by Max the Magnificent
  16. Feature: AUDIO OUT by Jake Rothman
  17. Feature: Circuit Surgery by Ian Bell
  18. Feature: Make it with Micromite by Phil Boyce
  19. PCB Order Form
  20. Advertising Index

This is only a preview of the April 2021 issue of Practical Electronics.

You can view 0 of the 72 pages in the full issue.

Articles in this series:
  • Techno Talk (September 2020)
  • Techno Talk (September 2020)
  • Techno Talk (October 2020)
  • Techno Talk (October 2020)
  • (November 2020)
  • (November 2020)
  • Techno Talk (December 2020)
  • Techno Talk (December 2020)
  • Techno Talk (January 2021)
  • Techno Talk (January 2021)
  • Techno Talk (February 2021)
  • Techno Talk (February 2021)
  • Techno Talk (March 2021)
  • Techno Talk (March 2021)
  • Techno Talk (April 2021)
  • Techno Talk (April 2021)
  • Techno Talk (May 2021)
  • Techno Talk (May 2021)
  • Techno Talk (June 2021)
  • Techno Talk (June 2021)
  • Techno Talk (July 2021)
  • Techno Talk (July 2021)
  • Techno Talk (August 2021)
  • Techno Talk (August 2021)
  • Techno Talk (September 2021)
  • Techno Talk (September 2021)
  • Techno Talk (October 2021)
  • Techno Talk (October 2021)
  • Techno Talk (November 2021)
  • Techno Talk (November 2021)
  • Techno Talk (December 2021)
  • Techno Talk (December 2021)
  • Communing with nature (January 2022)
  • Communing with nature (January 2022)
  • Should we be worried? (February 2022)
  • Should we be worried? (February 2022)
  • How resilient is your lifeline? (March 2022)
  • How resilient is your lifeline? (March 2022)
  • Go eco, get ethical! (April 2022)
  • Go eco, get ethical! (April 2022)
  • From nano to bio (May 2022)
  • From nano to bio (May 2022)
  • Positivity follows the gloom (June 2022)
  • Positivity follows the gloom (June 2022)
  • Mixed menu (July 2022)
  • Mixed menu (July 2022)
  • Time for a total rethink? (August 2022)
  • Time for a total rethink? (August 2022)
  • What’s in a name? (September 2022)
  • What’s in a name? (September 2022)
  • Forget leaves on the line! (October 2022)
  • Forget leaves on the line! (October 2022)
  • Giant Boost for Batteries (December 2022)
  • Giant Boost for Batteries (December 2022)
  • Raudive Voices Revisited (January 2023)
  • Raudive Voices Revisited (January 2023)
  • A thousand words (February 2023)
  • A thousand words (February 2023)
  • It’s handover time (March 2023)
  • It’s handover time (March 2023)
  • AI, Robots, Horticulture and Agriculture (April 2023)
  • AI, Robots, Horticulture and Agriculture (April 2023)
  • Prophecy can be perplexing (May 2023)
  • Prophecy can be perplexing (May 2023)
  • Technology comes in different shapes and sizes (June 2023)
  • Technology comes in different shapes and sizes (June 2023)
  • AI and robots – what could possibly go wrong? (July 2023)
  • AI and robots – what could possibly go wrong? (July 2023)
  • How long until we’re all out of work? (August 2023)
  • How long until we’re all out of work? (August 2023)
  • We both have truths, are mine the same as yours? (September 2023)
  • We both have truths, are mine the same as yours? (September 2023)
  • Holy Spheres, Batman! (October 2023)
  • Holy Spheres, Batman! (October 2023)
  • Where’s my pneumatic car? (November 2023)
  • Where’s my pneumatic car? (November 2023)
  • Good grief! (December 2023)
  • Good grief! (December 2023)
  • Cheeky chiplets (January 2024)
  • Cheeky chiplets (January 2024)
  • Cheeky chiplets (February 2024)
  • Cheeky chiplets (February 2024)
  • The Wibbly-Wobbly World of Quantum (March 2024)
  • The Wibbly-Wobbly World of Quantum (March 2024)
  • Techno Talk - Wait! What? Really? (April 2024)
  • Techno Talk - Wait! What? Really? (April 2024)
  • Techno Talk - One step closer to a dystopian abyss? (May 2024)
  • Techno Talk - One step closer to a dystopian abyss? (May 2024)
  • Techno Talk - Program that! (June 2024)
  • Techno Talk - Program that! (June 2024)
  • Techno Talk (July 2024)
  • Techno Talk (July 2024)
  • Techno Talk - That makes so much sense! (August 2024)
  • Techno Talk - That makes so much sense! (August 2024)
  • Techno Talk - I don’t want to be a Norbert... (September 2024)
  • Techno Talk - I don’t want to be a Norbert... (September 2024)
  • Techno Talk - Sticking the landing (October 2024)
  • Techno Talk - Sticking the landing (October 2024)
  • Techno Talk (November 2024)
  • Techno Talk (November 2024)
  • Techno Talk (December 2024)
  • Techno Talk (December 2024)
  • Techno Talk (January 2025)
  • Techno Talk (January 2025)
  • Techno Talk (February 2025)
  • Techno Talk (February 2025)
  • Techno Talk (March 2025)
  • Techno Talk (March 2025)
  • Techno Talk (April 2025)
  • Techno Talk (April 2025)
  • Techno Talk (May 2025)
  • Techno Talk (May 2025)
  • Techno Talk (June 2025)
  • Techno Talk (June 2025)
KickStart b y M ik e T o o le y Part 2: Getting started with RFID – working with cards and tags Our occasional KickStart series aims to show readers how to use readily available low-cost components and devices to solve a wide range of common problems in the shortest possible time. Each of the examples and projects can be completed in no more than a couple of hours using off-the-shelf parts. As well as briefly explaining the underlying principles and technology used, the series will provide you with a variety of representative solutions and examples, along with just enough information to be able to adapt and extend them for their own use. Fig.2.1. Widely available RFID tags (left) and cards (right). R adio Frequency IDentification (RFID) is a technology that allows stored data to be interrogated by radio without physical contact. An RFID system comprises two basic components: an RFID card or tag, and an RFID reader. The latter device is fitted with a small antenna and the tags or cards can also contain their own miniature antennas. The two devices communicate wirelessly by means of high-frequency radio signals. The signal returned to the reader is modulated with data stored in nonvolatile memory within the card or tag. The received and demodulated data stream is then passed from the reader to a host computer or a microcontroller system. Low-cost plastic enclosures protect cards and tags from their external environment. Popular cards (such as those manufactured by NXP) conform to a standard credit-card size, while tags are often designed to be used with key rings. RFID systems can be either passive or active. Passive RFID systems are smaller and cheaper than active systems 40 This second instalment shows you how to use low-cost RFID devices and, in keeping with the KickStart philosophy, we’ve provided sufficient information – including some simple Arduino sketches – for you to be able to incorporate RFID into your own projects. Fig.2.2. A popular MFRC522-based RFID module. because there is no need for the card or tag to incorporate its own power source. Active systems can operate over greater distances but are more complex and expensive than their passive counterparts. Note that passive cards and tags must derive their power from a reader (which must be present and in close proximity) before data can be returned to the reader. The widely available NXP MIFARE Classic RFID card is available at lowcost (around 25p when purchased in quantity) and it measures 85.5 × 54mm (ISO credit card size). The most widely available cards incorporate 1KB of nonvolatile memory and the PVC laminated surface can be printed on using a desktop photo ID printer (note that they are not compatible with standard inkjet printers). Data storage time is quoted as, ‘a minimum of ten years’. What can you do with RFID? In recent years, low-cost modules have become available to the enthusiast and hobbyist making it possible to use them in a wide range of applications. The reading and writing is achieved using a compact low-power wireless transceiver which, Fig.2.3. Pin assignment for the MFRC522-based RFID module. Practical Electronics | April | 2021 To ensure versatility, the MFRC522 provides support for three different host interfaces: n Serial Peripheral Interface (SPI) at up to 10Mbit/s n I2C-bus interface (at up to 400kBd in fast mode and up to 3,400kBd in high-speed mode) n Serial UART (similar to RS232 but with voltage levels dependant on the supply voltage). Fig.2.4. A simple RFID application based on an RC522 RFID module and an Arduino Uno microcontroller. together with a modest microcontroller chip, allows you to read data from and write data to cards and tags (see Fig.2.1). Depending on the envisaged application, an RFID reader can be fixed or portable. In use, the reader is placed close to the card or tag and held briefly while the data is being read. Note that only one card or tag can be read at a time. Furthermore, care must be taken to ensure that communication between the reader and tag is not compromised and the data being read is valid. Commercial applications of RFID include asset tracking, inventory management, personnel tracking, access control, maintenance, counterfeit prevention, and supply chain management. When compared with barcode scanning, a significant advantage of RFID technology is that there is no need for precise alignment because the wireless data stream can be read from a tag or card in random orientation. The MFRC522 chip’s internal clock operates at 27.12MHz and the chip requires a supply voltage of between 2.5V and 3.3V at typically up to 50mA. In applications where power consumption Fig.2.5. Wiring for the simple RFID application. An RC-522 RFID module A commonly available low-cost RC522 RFID module is shown in Fig.2.2. This handy device will provide you with a means of adding RFID facilities to any SPI, I2C or UART-based microcontroller. The RFID module is based on an MFRC522 chip from NXP. This device is a highly integrated reader/ writer designed to support contactless communication conforming with relevant ISO/IEC standards. The chip’s internal transmitter provides sufficient output to drive a reader/writer antenna without the need for any additional active circuitry. The internal receiver incorporates circuitry for demodulating and decoding 64-byte signal blocks from compatible cards and transponders, and its internal logic manages framing and error detection (parity and CRC) functionality. Speeds of up to 848kBd (kilobaud) are supported in both directions at an operating frequency within the high-frequency (HF) range at 13.56MHz. Practical Electronics | April | 2021 Fig.2.6. Interstage piezo sounder driver circuit. Table 2.1 Wiring an RC522 RFID module with the Uno’s SPI interface RC522 module Arduino Uno Wiring colour (see Fig.2.5) 3.3V 3.3V Red 3.3V power RST DIO9 Brown Reset line GND GND Black Common ground / 0V Notes IRQ N/C MISO DIO12 Orange Not used SPI data from the Uno to the RC522 MOSI DIO11 Yellow SPI data from the RC522 to the Uno SCLK DIO13 Green Serial clock for SPI SDA DIO10 Blue SPI SS chip enable 41 operation up to 240V AC at 2A. Both of these boards require a 5V supply of around 150mA and both are available at very modest cost from on-line suppliers (see Going Further). Coding the RFID module Coding is straightforward using the Arduino IDE (see Going Further) but will require the appropriate library Fig.2.7. Semiconductor pin connections for Fig.2.6. must be minimised, it is possible to use the RC-522 in low-power standby mode to reduce battery current. In this mode, the module requires a mere 10µA of supply current. A signal applied to the IRQ pin can then be used to wake the module ready for normal read/write operations. A simple RFID application To give you an idea of just how easy it is to incorporate RFID in your own projects, here’s a simple example in the form of a basic RFID entry control application based on an RFID-RC522 module and an Arduino Uno, as shown in Fig.2.4. The wiring from the RFID module to the Arduino is shown in Fig.2.5. The required connections based on the Uno’s SPI interface are shown in Table 2.1. An extra driver stage is needed to supply adequate current to the piezoelectric sounder (thus reducing the load on the Arduino’s digital output port). The circuit of the interstage driver is shown in Fig.2.6, and the semiconductor pin connections are shown in Fig.2.7. Listing 2.1: This code (PE_KS_2-1.ino) reads the data stored on an RFID card or tag when held close to the reader. // MRFC522 Card Infodump V1.1 // Reads card or tag UID and dumps contents of memory // Include the library routines #include <SPI.h> #include <MFRC522.h> // Define the pins #define RST_PIN 9 #define SS_PIN 10 // Create an instance of the MFRC522 MFRC522 mfrc522(SS_PIN, RST_PIN); // Set-up code void setup() { Serial.begin(9600); // Initialize serial port communication SPI.begin(); // Initialise the SPI bus mfrc522.PCD_Init(); // Initialise the MFRC522 Serial.println("Card Information Dump V1.1a"); Serial.println("Place the card or tag close to the reader and wait until all data is read ..."); } void loop() { byte i; Testing the RFID application Since both audible and visual indications are provided by the interstage relay driver, our sample RFID system can be tested without the external relay module and door electronics. The external relay module can be a low-cost module (see Table 2.2, Going Further) and should be suitably rated. Typical relay boards are shown in Fig.2.8 and Fig.2.9. The relay board in Fig.2.8 is rated for switching AC of up to 250V at 10A and DC of up to 30V at 10A. The solid-state relay board shown in Fig.2.9 is suitable for AC Fig.2.8. Off-the-shelf relay board. 42 // Is a card detected? if (mfrc522.PICC_IsNewCardPresent()) { // Can the serial number be read? if (mfrc522.PICC_ReadCardSerial()) { Serial.println(); Serial.print("Card detected : "); mfrc522.PICC_DumpToSerial(&(mfrc522.uid)); } } } Fig.2.9. Solid-state alternative relay board. Practical Electronics | April | 2021 Fig.2.11. RFID tags labelled with unique 64-bit identifiers. Fig.2.10. The data stored on a card or tag can be read using code like that in Listing 2.1. which can be downloaded from the web. Start the Arduino IDE and select Tools and then Manage Libraries. From the Library Manager enter ‘miguelbalboa’ (the library’s author) in the search box. You should then see a library called: MFRC522-spi-i2c-uart-async Select the file and click on Install. The new library file will then be downloaded and installed, and the library list will be updated accordingly. Click on Close and return to the main IDE window. Enter the sample code from Listing 2.1 (available for download from the April 2021 page of the PE website). Make sure you save the file when you have finished editing. Next, ensure that you have the correct board type selected (ie, Arduino Uno) and also that the correct serial port has been selected (note that both of these options are selected from the IDE’s Tools menu). Finally, select Sketch from the main menu and Verify/Compile and Upload. Table 2.2: Going Further with RFID cards and tags, and the Arduino Uno Topic Source Notes RFID technology Atlas RFID Store have a useful beginners’ guide to RFID: http://bit.ly/pe-apr21-ks2-1 Another general introduction is at: http://bit.ly/pe-apr21-ks2-2 For innovative 13.6MHz RFID tags and applications: http://bit.ly/pe-apr21-ks2-3 MFRC522 chip The MFRC522 data sheets can be downloaded from NXP at: http://bit.ly/pe-apr21-ks2-4 RC-522 RFID module RC-522 modules are available from several suppliers, including: HobbyTronics at: http://bit.ly/pe-apr21-ks2-5 AZ-Delivery at: http://bit.ly/pe-apr21-ks2-6 Low-cost kits are available which include readers, tags and cards. Cards and tags can be purchased very cheaply in large quantities. Arduino Uno A detailed introduction to the hardware and software of the Arduino Uno can be found in PE’s Electronics Teach-In 8. http://bit.ly/pe-apr21-ks2-7 Arduino IDE For a useful introduction and relevant theory see Part 1 of Electronics Teach-In 8. The latest version of the Arduino IDE can be downloaded from: https://www.arduino.cc/en/software Versions are available for Windows Linux and macOS. The current IDE version is 1.8.13. http://bit.ly/pe-apr21-ks2-7 Interfacing The author’s book, Electronic Circuits: Fundamentals and Applications (5th Ed, 2020, Routledge) provides a general introduction to microcontroller interfacing (Ch.15) and the Arduino Uno (Ch.19). RFID library The RC522 Arduino library can be downloaded from GitHub at: https://github.com/miguelbalboa/rfid The library can be downloaded using the IDE’s built-in library manager (which is supported). Note that this library works with Arduino IDE 1.6 (and later) but previous IDE versions are not supported (causing potential compiler errors). Relay boards Relay boards can be purchased at low cost from many suppliers, including: AZ-Delivery, HobbyTronics, CPC/Farnell, Mouser, RS and online suppliers. Relay boards can be purchased with one, two, four or eight relays, the latter is ideal for multi-channel operation. Practical Electronics | April | 2021 43 Sample code listings Our two sample listings show the simple code necessary to test the application. Listing 2.1 can be used to check a card’s unique identifier (UID) and view the stored data. Listing 2.2 provides an example of how the reader can be used in a simple access control system (see Fig.2.4). Note that it is possible to write data as well as read data and this feature makes it possible to store and subsequently update information on a card or tag. Several useful and liberally commented examples are provided in Miguel Balboa’s library file. The data returned from Listing 2.2 reveals the UID, which in this case is 79 2F 1D B5 (see Fig.2.10). Data is organised in blocks and sectors. Each block comprises 64 bytes of data and there are 16 sectors on the 1K MIFARE tag. The UID is contained in the first four bytes in Sector 0, Block 0 (not shown in Fig.2.10, which only shows the last three data blocks). Note that the UID is written during manufacture and cannot normally be changed (for test purposes I found it useful to write a tag’s UID on the tag, as shown in Fig.2.11). Finally, Fig.2.12 shows the frequency spectrum of the signal produced by the RFID application. Note that the signal is centred on approximately 13.56MHz and it occupies a bandwidth of around 100kHz. Going further Table 2.2 lists sources to help you locate components, information that will help you with your own RFID applications and links to useful background reading. Fig.2.12. Spectral analysis of the 13.56MHz RFID signal. Teach-In 8 CD-ROM Exploring the Arduino This CD-ROM version of the exciting and popular Teach-In 8 series has been designed for electronics enthusiasts who want to get to grips with the inexpensive, immensely popular Arduino microcontroller, as well as coding enthusiasts who want to explore hardware and interfacing. Teach-In 8 provides a one-stop source of ideas and practical information. The Arduino offers a remarkably effective platform for developing a huge variety of projects; from operating a set of Christmas tree lights to remotely controlling a robotic vehicle wirelessly or via the Internet. Teach-In 8 is based around a series of practical projects with plenty of information for customisation. The projects can be combined together in many different ways in order to build more complex systems that can be used to solve a wide variety of home automation and environmental monitoring problems. The series includes topics such as RF technology, wireless networking and remote web access. PLUS: PICs and the PICkit 3 – A beginners guide The CD-ROM also includes a bonus – an extra 12-part series based around the popular PIC microcontroller, explaining how to build PIC-based systems. EE FR -ROM CD ELECTRONICS TEACH-IN 8 £8.99 FREE CD-ROM SOFTWARE FOR THE TEACH-IN 8 SERIES FROM THE PUBLISHERS OF INTRODUCING THE ARDUINO • Hardware – learn about components and circuits • Programming – powerful integrated development system • Microcontrollers – understand control operations • Communications – connect to PCs and other Arduinos PLUS... PIC n’MIX PICs and the PICkit 3 - A beginners guide. The why and how to build PIC-based projects Teach In 8 Cover.indd 1 04/04/2017 12:24 PRICE £8.99 Includes P&P to UK if ordered direct from us SOFTWARE The CD-ROM contains the software for both the Teach-In 8 and PICkit 3 series. ORDER YOUR COPY TODAY at: www.electronpublishing.com 44 Practical Electronics | April | 2021 Listing 2.2: The code (PE_KS_2-2.ino) checks the unique data on a card or tag and will operate the relay and piezoelectric sounder if (and only if) the correct card identifier (UID) is detected. // MRFC522 Card Access Checker V2.1a // Reads and checks card UID before activating relay and sounder // Include the library routines #include <SPI.h> #include <MFRC522.h> // Define the pins #define RST_PIN 9 #define SS_PIN 10 #define sounder 7 #define relay 6 // Create an instance of the MFRC522 MFRC522 mfrc522(SS_PIN, RST_PIN); // Set-up code void setup() { Serial.begin(9600); // Initialize serial port communication SPI.begin(); // Initialise the SPI bus mfrc522.PCD_Init(); // Initialise the MFRC522 digitalWrite(relay, LOW); // Relay non-energized digitalWrite(sounder, LOW); // No sound Serial.println("Card Access Checker V1.1a"); Serial.println("Pleace your card or tag close to the reader ..."); } void loop() { byte i; // Is a card detected? if (mfrc522.PICC_IsNewCardPresent()) { // Can the serial number be read? if (mfrc522.PICC_ReadCardSerial()) { // We have a card and its serial number so we can now format and verify the UID String content = ""; for (byte i = 0; i < mfrc522.uid.size; i++) { content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ")); content.concat(String(mfrc522.uid.uidByte[i], HEX)); } Serial.println(); Serial.print("Card detected : "); content.toUpperCase(); if (content.substring(1) == "83 1D 3F 03") // Change this UID to suit the card { Serial.println("Access granted"); Serial.println(); // Beep door opening digitalWrite(sounder, HIGH); delay(500); digitalWrite(sounder, LOW); // Activate door relay digitalWrite(relay, HIGH); // Relay energized delay(2500); digitalWrite(relay, LOW); // Relay non-energized } else { Serial.println("Access denied"); Serial.println(); delay(2500); } } } } Practical Electronics | April | 2021 45