Chapter 21 of 22 Part V: Artificial Intelligence and Intelligent Devices

NFC: The Secret Power of a Tap

Each project below is tailored to a specific algorithm and scientific question from Chapter 21, with concrete inputs, verifiable numerical outputs, boundary cases, and links to the related lab and pioneer.

Project 1 of 3 · v1-c21-p01 Intermediate · ~25 min

13.56 MHz Inductive Coil Coupling Model

Lab activity: 1. Model two coils · Related code: block-01.js · Pioneer: View profile

Real-World Problem: Transit cards and museum tags work with zero battery by harvesting energy from a reader's magnetic field.
Scientific Question: Why does NFC work at 2 cm yet fail completely at 15 cm?

Objective: Model near-field magnetic coupling vs. coil separation d and find the exact activation cutoff distance.

Hypothesis to Test: Because near-field dipole coupling decays rapidly (~1 / (1 + (d/R)^2)^(3/2)), induced voltage falls below chip threshold within a few centimeters.

Step-by-Step Implementation

  1. Evaluate the normalized inductive coupling curve across distances 0 to 10 cm.
  2. Find the maximum operating distance where induced voltage >= chip turn-on threshold.
  3. Test tilting the tag coil by angle θ (multiplying coupling by cos θ); observe 90° null.
  4. Explain why short physical range provides an intentional physical-proximity boundary.
Concrete Input: Coil radius R = 2.0 cm, activation threshold = 2.5 V; sweep distance d from 0 cm to 10 cm.
Expected Output: d=1 cm -> active; d=3 cm -> marginal; d>=5 cm -> unpowered (below 2.5 V threshold).

Test Cases: d=0, θ=0° -> max coupling; θ=90° -> 0 induced voltage; d=10 cm -> below threshold.

Boundary Condition: Metal surfaces behind a tag induce eddy currents that detune 13.56 MHz antennas unless shielded with ferrite.

Common Mistake to Avoid: Confusing NFC's 13.56 MHz magnetic near-field with 2.4 GHz far-field Bluetooth/Wi-Fi radio.

Interpreting Results: Physics (Faraday's law of induction) directly sets NFC's tap-distance user experience.

Show Hint, Extension Challenge & Reflection

Hint: Review the worked example and equation in Chapter 21 before testing the boundary case: Metal surfaces behind a tag induce eddy currents that detune 13.56 MHz antennas unless shielded with ferrite.

Extension Challenge: Compare coil radii R = 1 cm (smart ring) vs. R = 3 cm (transit card) on activation distance.

Reflection Question: Why is tapping a transit card at 2 cm more practical in a crowded station than a 10-meter wireless link?

Project 2 of 3 · v1-c21-p02 Intermediate · ~25 min

NDEF Tag Byte-Budget Packer

Lab activity: 2. Count the message bytes · Related code: block-02.js · Pioneer: View profile

Real-World Problem: Inexpensive passive NFC tags (like NTAG213) hold only 144 bytes of user memory.
Scientific Question: How do NDEF record headers and URI prefix codes pack useful links into tiny tag memories?

Objective: Encode a URL into NDEF URI record bytes, compute exact byte overhead, and validate against a 144-byte tag limit.

Hypothesis to Test: Using NDEF prefix code 0x04 ("https://") saves 7 bytes compared to storing the full scheme string.

Step-by-Step Implementation

  1. Match known URI prefixes ("https://www." -> 0x02, "https://" -> 0x04, "http://" -> 0x03).
  2. Encode remaining UTF-8 bytes and add NDEF header byte, type length, payload length, type "U", and prefix byte.
  3. Compare total byte length against 144-byte (NTAG213) and 504-byte (NTAG215) capacities.
  4. Test a 200-byte URL and confirm overflow rejection for NTAG213.
Concrete Input: URL: "https://howdigitalworks.dev/go/21/" on a 144-byte NTAG213 tag.
Expected Output: Prefix 0x04 + 26-byte payload + 5-byte NDEF header/TLV = 32 bytes used (112 bytes free).

Test Cases: https://howdigitalworks.dev/go/21/ -> fits 144 B; 200-byte URL -> exceeds NTAG213.

Boundary Condition: Payloads >= 256 bytes cannot use the Short Record (SR) 1-byte length field and need a 4-byte length.

Common Mistake to Avoid: Counting JavaScript string .length instead of UTF-8 byte length for international URLs.

Interpreting Results: Protocol headers and abbreviation tables squeeze maximum utility out of tiny low-cost chips.

Show Hint, Extension Challenge & Reflection

Hint: Review the worked example and equation in Chapter 21 before testing the boundary case: Payloads >= 256 bytes cannot use the Short Record (SR) 1-byte length field and need a 4-byte length.

Extension Challenge: Add support for multi-record NDEF messages (e.g., 1 URI record + 1 plain-text description record).

Reflection Question: Why do smart posters use short redirect paths like /go/21/ instead of long tracking URLs?

Project 3 of 3 · v1-c21-p03 Foundational · ~25 min

Cautious Tap-Interface Privilege-Boundary Designer

Lab activity: 3. Design a cautious tap interface · Related code: block-03.js · Pioneer: View profile

Real-World Problem: Tapping an unknown public NFC sticker could trigger an unwanted webpage, pairing prompt, or phishing link.
Scientific Question: What distinct security boundaries separate reading raw bytes, parsing NDEF, opening a URL, and granting permissions?

Objective: Implement a safe tap-preview state machine that inspects decoded NDEF payloads and requires explicit confirmation for external actions.

Hypothesis to Test: Treating raw byte read, parser validation, URL preview, and user-confirmed open as four separate states eliminates silent redirects.

Step-by-Step Implementation

  1. Validate NDEF length bounds strictly before reading payload bytes (defensive parsing).
  2. Classify record type (plain text, HTTPS URL, unsupported/privileged action).
  3. Render full destination origin clearly as plain text before offering an Open button.
  4. Block dangerous URI schemes (javascript:, data:, file:) outright.
Concrete Input: 3 simulated NFC tags: trusted museum link, suspicious lookalike URL, and malformed oversized NDEF record.
Expected Output: Malformed tag -> parser rejects safely; Suspicious URL -> domain highlighted with Cancel default; Trusted -> preview shown before open.

Test Cases: Malformed length > buffer -> rejected cleanly; javascript: URI -> blocked; https:// -> preview + confirm.

Boundary Condition: Never claim reading an untrusted tag is unconditionally risk-free; parser safety matters too.

Common Mistake to Avoid: Auto-opening decoded URLs without showing the domain to the user.

Interpreting Results: Good security UX makes privilege boundaries visible and gives users informed control.

Show Hint, Extension Challenge & Reflection

Hint: Review the worked example and equation in Chapter 21 before testing the boundary case: Never claim reading an untrusted tag is unconditionally risk-free; parser safety matters too.

Extension Challenge: Add a domain-comparison warning when a tag displays text claiming one site while linking to another.

Reflection Question: How do QR codes (Chapter 4) and NFC tags (Chapter 21) share similar human-factor phishing risks?