Skip to content
esp-labsESP32-S3 bench guide
ESP32-S3 DevKitC pinoutThis lesson uses: VCC on 3V3, RC 3.3V on 3V3, BLK on 7, RES on 8, DC on 9, CS on 10, SDA on 11, SCL on 12, GND on GND, RC SDA on 15, RC SCK on 16, MOSI on 17, MISO on 18, RC RST on 14, IRQ on 13, RC GND on GND, BTN on 5, BOOT on 0.ESP32-S3WROOM-1 N16R8BOOTRSTRGBUSBCOM3V3VCC3V3RC 3.3VRST45BTN67BLK15RC SDA16RC SCK17MOSI18MISO8RES3469DC10CS11SDA12SCL13IRQ14RC RST5VGNDGNDGNDRC GNDTX 43RX 441242414039383736350BOOT454847212019GNDGND
  • used in this lesson
  • safe GPIO
  • avoid
  • power
  • ground
  • button input
  • RC522
Between lessons
  1. Ctrl+C closes the monitor on the Mac only. The board keeps running.
  2. Unplug USB: this is what stops the program and the screen
  3. Rewire while off
  4. Check VCC is on 3V3, no loose ends
  5. Plug in, flash the next lesson

Never unplug during Writing at 0x…. Pin changing from output to input? Flash first, then wire.

Lesson R7

RFID & NFC · lesson 7 of 8

Manage your cards from a React app

runs on the board

Its own firmware (rfid-lab-r7) turns the bench into a door you manage from a small React app (esp-labs/apps/door-app) over your Wi-Fi. The board keeps the card list in its flash and decides every tap itself; the card only brings its UID. From the app you add cards, name them, give them a role, block them, limit them to hours, an end date or a number of uses, copy one card's rules to another, replace a lost card, write a name label onto them, wipe the data the labs wrote, save a card's data and write it back or copy it onto another card, open the door remotely, switch on lockdown, and watch every tap live. Two simulated locks (the screen and the LED): the front door, for every role, and the admin room, for admin cards only; the one reader is mounted at one of them at a time.

Goal

Run your two tags as a small access system: one resident, one guest, and see each rule decide a tap.

You're done when

  • The app shows live and both tags are in the list: the white card as a resident, the key tag as a guest.
  • Tapping the white card shows OPEN on the screen and in the app; after Block the same tap shows DENIED · blocked.
  • The guest tag's uses go down with each tap; at 0 it is refused with “no uses left”.
  • Every tap and every change appears in the access log, on the board's log view and in the app.
  • The white card's data is saved, copied onto the key tag and compared: same data, and the key tag still opens as Key tag, because a copy never moves the UID.

You will learn

  • REST API + WebSocket
  • server-side decisions
  • rule order
  • fail closed
  • NVS storage
  • admin token via a dev proxy
  • React + zod
  • backup, restore, verify
  • a copy is not a clone
uv run pio run -d labs/rfid-lab-r7 -e rfid-lab-r7 -t upload
Open this lab's code on GitHubesp-labs / labs / rfid-lab-r7 (opens in a new tab)

Parts required

Parts library
  • ESP32-S3-DevKitC-1 + USB-C data cable
  • 1.9″ ST7789 screen
  • RC522 card reader
  • MIFARE card and key fob
  • 2.4 GHz Wi-Fi network

Which rule decides?

The board checks the rules in this order, and the first one that says no wins. Set up a card, the clock and lockdown, and see which rule decides. It is the same order as kit/lib/door-rules/src/access_rules.h (tested on the Mac).

Interactive access-control rule simulator mapping RFID UIDs to door unlock permissions. The board checks the rules in this order, and the first one that says no wins. Set up a card, the clock and lockdown, and see which rule decides. It is the same order as kit/lib/door-rules/src/access_rules.h (tested on the Mac).

  • Key concepts: REST API + WebSocket, server-side decisions, rule order, fail closed, NVS storage, admin token via a dev proxy, React + zod, backup, restore, verify, a copy is not a clone.
  • Signals & pins: 3V3 (VCC), 3V3 (RC 3.3V), GPIO7 (BLK), GPIO8 (RES), GPIO9 (DC).

Interactive diagram loads after page initialization.

Follow one tap, one block, one new card, one copy

What crosses the wires and the Wi-Fi: the app never talks to the reader directly, and the card never decides anything.

Sequence diagram connecting the ESP32-S3 HTTP API, WebSocket updates, and React card-manager frontend. What crosses the wires and the Wi-Fi: the app never talks to the reader directly, and the card never decides anything.

  • Key concepts: REST API + WebSocket, server-side decisions, rule order, fail closed, NVS storage, admin token via a dev proxy, React + zod, backup, restore, verify, a copy is not a clone.
  • Signals & pins: 3V3 (VCC), 3V3 (RC 3.3V), GPIO7 (BLK), GPIO8 (RES), GPIO9 (DC).

Interactive diagram loads after page initialization.

What a copy moves

Save the white card's data, copy it onto the key tag, and watch which blocks move. Block 0 (the UID) and the sector trailers (keys, access bits) never do, and a sector that doesn't open with the factory key is skipped, not forced.

Card cloning and UID-vs-sector security comparison demonstrating why UID-only checks are insecure. Save the white card's data, copy it onto the key tag, and watch which blocks move. Block 0 (the UID) and the sector trailers (keys, access bits) never do, and a sector that doesn't open with the factory key is skipped, not forced.

  • Key concepts: REST API + WebSocket, server-side decisions, rule order, fail closed, NVS storage, admin token via a dev proxy, React + zod, backup, restore, verify, a copy is not a clone.
  • Signals & pins: 3V3 (VCC), 3V3 (RC 3.3V), GPIO7 (BLK), GPIO8 (RES), GPIO9 (DC).

Interactive diagram loads after page initialization.

Commands, in order

Type these in the serial monitor (uv run pio device monitor) unless the grey tag says otherwise. The coloured tag says what should be near the board while it runs.

  1. uv run pio run -d labs/rfid-lab-r7 -e rfid-lab-r7 -t uploadMac terminalcard: doesn't matter
    Does
    Flashes the door firmware. The first build copies the web libraries W2 already uses (ESPAsyncWebServer, AsyncTCP, ArduinoJson) into esp-labs/.pio.
    You should see
    The screen shows DOOR door, LOCKED, “0 cards in the list” and http://bench.local at the bottom once Wi-Fi joins.
    If not
    “no Wi-Fi saved: run W1 once”: R7 uses the network W1/W2 saved. Flash W1, join, then flash R7 again.
  2. tokenserial monitorcard: doesn't matter
    Does
    Prints the admin token (shared with W2). Every change in the app needs it.
    You should see
    Admin token: 3f… and where to put it.
    If not
    Keep it out of chats and git. token new replaces it.
  3. cd esp-labs/apps/door-app && cp .env.example .envMac terminalcard: doesn't matter
    Does
    Creates the app's settings file: BENCH_URL=http://bench.local (or the IP from status) and BENCH_TOKEN= the token.
    You should see
    A .env file next to package.json. It is git-ignored.
  4. pnpm install, then pnpm devMac terminalcard: doesn't matter
    Does
    Installs the app (React 19, Vite 8, zod: the same versions as the dashboard) and starts it. Vite forwards /api and /ws to the board and adds the token on the way, so the browser never holds it.
    You should see
    Open http://localhost:5174: the door panel says live, the chip says B2h · FM17522 (your clone), the clock shows the time.
    If not
    “connecting…” forever: is the board on Wi-Fi (screen footer)? Does http://bench.local/api open in the browser? FRITZ!Box: allow Wi-Fi devices to talk to each other (W2).
  5. Add card: “White card”, residentin the appcard on the reader
    Does
    The board waits 20 s for a card it hasn't seen; the screen shows ADD A CARD and the LED blinks blue. Then lay the white card on the reader.
    You should see
    A toast “White card added”, the card in the list with opens now, an “enrolled” line in the log.
    If not
    “already in the list”: that card is enrolled; tap another or delete it first.
  6. Add card: “Key tag”, guestin the appcard on the reader
    Does
    The same for the key tag. Guests start with 5 uses.
    You should see
    Key tag · guest · 5 uses left.
  7. tap each cardwith your handscard on, then move it
    Does
    The board decides from its list: OPEN 5 s (green LED, padlock opens) or DENIED 2 s (red LED, with the reason).
    You should see
    The app's door panel and log update within a second; the guest's uses go 5 → 4 → 3.
    If not
    Nothing happens, or “card can't be read”: look at the app's Reader chip cell and the banner under it. “settings restored” means the RC522 reset itself when its 3.3 V dipped (often while Wi-Fi transmits): short wires to the 3.3V pin, header pins pressed in or soldered. “IRQ wire stays quiet” is harmless: the board polls instead. Serial: status prints the same.
  8. Block, then Unblockin the appcard: doesn't matter
    Does
    The quickest rule: a blocked card is refused before anything else is checked.
    You should see
    blocked on the card; its next tap shows DENIED · blocked.
  9. Edit → presetsin the appcard: doesn't matter
    Does
    Office hours (08-18), Night shift (22-06, across midnight), Weekend guest (10 uses until Sunday 20:00), One visit (1 use, 24 h), Lost card (blocked). Save sends only what changed.
    You should see
    The card's rule line and its “opens now” chip change at once.
    If not
    “no clock yet”: dated or timed cards are refused until the board has internet time (fail closed).
  10. Add card: “Admin fob”, adminin the appcard on the reader
    Does
    A fourth role: admin cards open the front door like a resident, and they are the only cards the admin room opens for. They also open during lockdown.
    You should see
    The card's row shows front door ✓ and admin room ✓; a resident's shows admin room · admins only.
  11. Locks → Admin room → Move reader herein the appcard: doesn't matter
    Does
    The bench has one reader, so it is mounted at one lock at a time (saved on the board). Serial: at admin, at front.
    You should see
    The admin room tile gets the teal border and “reader here”; the screen says ADMIN ROOM above the padlock.
  12. tap the admin card, then a resident cardwith your handscard on, then move it
    Does
    Same board, same list, different lock: the role check comes right after “blocked”, before any hours or dates.
    You should see
    Admin card: the admin room OPEN 5 s. Resident card: DENIED · admins only, logged with “admin room”. Move the reader back: the resident opens the front door again.
    If not
    Still OPEN for a resident? Check which tile says “reader here”.
  13. open admin (or Open 5 s on a tile)serial monitorcard: doesn't matter
    Does
    Opens one lock from the app or serial, whatever card is near; open alone is the front door.
    You should see
    That tile goes green for 5 s; the log says “opened from the app” with the lock.
  14. Lockdown onin the appcard: doesn't matter
    Does
    Only maintenance and admin cards open. The LED glows amber while idle.
    You should see
    LOCKDOWN on the screen, every resident and guest tap DENIED · lockdown.
  15. Edit → Write name labelin the appcard on the reader
    Does
    Writes the name into block 4 and the role into block 5 of that card (factory key, sector 1 only), then reads them back.
    You should see
    “label written”. Read the card on the reader: block 4 shows its name.
    If not
    The door still ignores the label: it decides from its own list. Write any name there and nothing changes.
  16. Edit → Wipe card datain the appcard on the reader
    Does
    Second click to confirm. Blocks 4-6 and 8-10 back to zeros where the access bits allow (the label, R5's credits). Keys, trailers and block 0 are never touched.
    You should see
    “6 of 6 data blocks cleared”.
  17. Edit → Remove from the listin the appcard: doesn't matter
    Does
    Second click to confirm. The board forgets the card; the card itself is not touched.
    You should see
    Its next tap: DENIED · unknown card.
  18. Edit → Copy rules from…in the appcard: doesn't matter
    Does
    Fills the form with another card's role, hours, end date and uses (not its name, not its block). Save sends what changed.
    You should see
    Both cards now have the same rule line.
  19. Card data → Save the card on the readerin the appcard on the reader
    Does
    Reads blocks 4-6 and 8-10 with the factory key and keeps them on the board as a named snapshot (up to 8, in NVS). Serial: save White, saved.
    You should see
    “6 of 6 blocks saved as …” and a snapshot with its six cells: text, values (R5's credits), zeros.
    If not
    “no lab block opens”: that card's sectors 1-2 use another key: nothing to save.
  20. Card data → Download, Import a saved filein the appcard: doesn't matter
    Does
    Downloads the snapshot as a JSON file on your Mac; Import puts such a file back on the board (lab blocks only, checked twice: by the app and by the board).
    You should see
    A card-data-….json file; after import, a snapshot “from a file”.
  21. Card data → Copy this card onto anotherin the appcard on, then move it
    Does
    Reads the card on the reader, then the screen shows COPY: 2ND CARD and the LED blinks violet. Lift it and lay the other card within 20 s: each block is written and read back. Serial: copy, cancel.
    You should see
    “6 of 6 blocks copied from White card onto 9C4F6A0D”, a “data copied here” line in the log.
    If not
    Laying the same card again does nothing (it waits for a different one). Cancel writes nothing.
  22. Compare with the readerin the appcard on the reader
    Does
    Reads the card on the reader and lines it up against a snapshot, block by block.
    You should see
    same for each copied block. Now tap the key tag: it still opens as Key tag.
  23. Write onto the card on the readerin the appcard on the reader
    Does
    Second click to confirm. A snapshot back onto the card it came from (restore), e.g. after R5 spent its credits, or onto another card. Serial: restore 1.
    You should see
    “… written to 9C4F2A1B (the card it came from)”.
  24. Edit → Replace with a new cardin the appcard on, then move it
    Does
    For a lost or broken card: the next new card you tap takes over its name, role and rules; the old one stays in the list, blocked, renamed “… old”.
    You should see
    Two entries: the new card opens, the old one shows DENIED · blocked if it ever turns up.

Steps

0 of 9 ticked. Ticks are saved in this browser.

Why the board decides and not the card: a card's UID and the data on a MIFARE Classic can be read by anyone with a reader, so they are fine as a name tag, not as proof. Real access systems keep the decision on a server and use cards with modern cryptography (e.g. MIFARE DESFire); this lab teaches the server side of that. Reading the API is open on your Wi-Fi; every change needs the token. The card list lives in the board's NVS and survives re-flashing; it is separate from the R1-R6 labs. Copying moves data only: block 0 is written once at the factory, so the copy keeps its own UID and the door treats it as a different card. That is also why access never rests on the data: it would be copied along.

Preview: what you should see

Simulated smart-door RFID dashboard synchronized with the ESP32-S3 card reader.

  • Key concepts: REST API + WebSocket, server-side decisions, rule order, fail closed, NVS storage, admin token via a dev proxy, React + zod, backup, restore, verify, a copy is not a clone.
  • Signals & pins: 3V3 (VCC), 3V3 (RC 3.3V), GPIO7 (BLK), GPIO8 (RES), GPIO9 (DC).

Interactive diagram loads after page initialization.

ESP32-S3 peripherals used in this lab

Open interactive GPIO pinout

Explore the hardware blocks, pin rules, and registers behind this experiment.

  • GPIO and IO MUX

    45 pins, and a matrix that routes almost any signal to almost any pin

  • SPI

    Fast four-wire bus for screens, card readers and flash

  • Wi-Fi

    2.4 GHz 802.11b/g/n, as a station, an access point or both

  • UART

    Three serial ports, the one you see in the serial monitor

  • CPU

    Two Xtensa LX7 cores at up to 240 MHz

  • SRAM

    512 KB of fast on-chip RAM for your code and data

Troubleshooting & hardware gotchas

See all 17 ESP32-S3 hardware gotchas
What if it does not work or behaves unexpectedly?
Why the board decides and not the card: a card's UID and the data on a MIFARE Classic can be read by anyone with a reader, so they are fine as a name tag, not as proof. Real access systems keep the decision on a server and use cards with modern cryptography (e.g. MIFARE DESFire); this lab teaches the server side of that. Reading the API is open on your Wi-Fi; every change needs the token. The card list lives in the board's NVS and survives re-flashing; it is separate from the R1-R6 labs. Copying moves data only: block 0 is written once at the factory, so the copy keeps its own UID and the door treats it as a different card. That is also why access never rests on the data: it would be copied along.
If “uv run pio run -d labs/rfid-lab-r7 -e rfid-lab-r7 -t upload” does not work
“no Wi-Fi saved: run W1 once”: R7 uses the network W1/W2 saved. Flash W1, join, then flash R7 again.
If “token” does not work
Keep it out of chats and git. token new replaces it.
If “pnpm install, then pnpm dev” does not work
“connecting…” forever: is the board on Wi-Fi (screen footer)? Does http://bench.local/api open in the browser? FRITZ!Box: allow Wi-Fi devices to talk to each other (W2).
If “Add card: “White card”, resident” does not work
“already in the list”: that card is enrolled; tap another or delete it first.
If “tap each card” does not work
Nothing happens, or “card can't be read”: look at the app's Reader chip cell and the banner under it. “settings restored” means the RC522 reset itself when its 3.3 V dipped (often while Wi-Fi transmits): short wires to the 3.3V pin, header pins pressed in or soldered. “IRQ wire stays quiet” is harmless: the board polls instead. Serial: status prints the same.
If “Edit → presets” does not work
“no clock yet”: dated or timed cards are refused until the board has internet time (fail closed).
If “tap the admin card, then a resident card” does not work
Still OPEN for a resident? Check which tile says “reader here”.
If “Edit → Write name label” does not work
The door still ignores the label: it decides from its own list. Write any name there and nothing changes.
If “Card data → Save the card on the reader” does not work
“no lab block opens”: that card's sectors 1-2 use another key: nothing to save.
If “Card data → Copy this card onto another” does not work
Laying the same card again does nothing (it waits for a different one). Cancel writes nothing.
Four pins are read at reset
GPIO0, GPIO3, GPIO45 and GPIO46 are sampled the moment the chip comes out of reset: they pick the boot mode, the flash voltage, the ROM log and the JTAG source. Anything wired to them must not pull them the wrong way at power-up. After reset they are normal pins again.
GPIO3 has no pull resistor at reset
GPIO0 has a weak pull-up and GPIO45/46 weak pull-downs, but GPIO3 floats. When the eFuses make it choose the JTAG source, an outside circuit has to hold it at a clear level.
ADC2 stops working while Wi-Fi is on
The ADC2 channels (GPIO11-20) cannot be used at the same time as Wi-Fi: the radio shares ADC2 through an arbiter. Put analog sensors on ADC1 (GPIO1-10), as the sound labs do with GPIO6.
GPIO47 and 48 run at 1.8 V on R16V modules
Modules with the ESP32-S3R16V chip set the flash voltage to 1.8 V, and GPIO47/48 share that supply. A 3.3 V part on those pins sees the wrong levels.