Projects / RFID wristband cashless payment

RFID wristband cashless payment

Intermediate4 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. UNORC522

    Wire the reader

    Check the version over Serial.

  2. UNO

    Read a tag

    Print the ID.

  3. UNO

    Write a balance

    Store it with its inverse.

  4. UNO

    Add the keypad

    Price entry.

  5. UNO

    Charge a tag

    Subtract and show the rest.

  6. UNO

    Add top-up

    A key for the stall.

  7. UNO

    Log the sales

    Compare with the cash.

In short

How do you build an RFID wristband cashless payment?

Festival-style wristbands with RFID tags hold a prepaid balance that stalls read and update. You need Arduino Uno R3, RC522 RFID reader, RFID tags 13.56 MHz (MIFARE Classic 1K) × 5, 16x2 LCD with I2C backpack (PCF8574), Active buzzer 5 V and 4x4 matrix keypad (membrane). It takes 7 steps and about 240 minutes.

Level
Intermediate
Time
About 240 min
Parts
6

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
MFRC522 SDA (SS)Uno D10Chip select
MFRC522 SCK, MOSI, MISOUno D13, D11, D12SPI
MFRC522 RSTUno D9Reset
MFRC522 3.3V and GNDUno 3.3V and GNDPower (never 5 V)
LCD SDA and SCLUno A4 and A5I2C
LCD VCC and GNDUno 5V and GNDPower
Keypad rowsUno D2, D3, D4, D5Four rows
Keypad columnsUno A0, A1, A2, A3Four columns (used as digital pins)
Buzzer plus and minusUno D8 and GNDBeep

Code

The tag is a small memory chip with a radio, and the reader can write a number into it, so each wristband carries its own balance. The sketch stores the balance together with its opposite (every bit flipped); if the two do not agree, the tag is treated as damaged, which protects against a half-finished write. Every sale and top-up prints to the serial monitor so you can check the totals against the cash at the end. Please keep it to play money for a school fair or classroom: Mifare Classic tags can be read, copied and changed with cheap tools, and the factory key used here is public, so someone could give themselves a bigger balance. Real payment systems keep the money on a server and use the tag only as an ID, and anything that handles real money must follow the law. Do not let the top-up key be known to the customers. Wristbands should not be worn by anyone who gets a skin reaction from the strap material. Arduino IDE, board "Arduino Uno".

Runs on a virtual Arduino Uno in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

// Play-money wristband till for a school fair. Libraries: MFRC522, Keypad, LiquidCrystal_I2C. Board: Arduino Uno.
// Keys: digits then # to charge that amount, * to cancel, A then digits then # to top up. Each tag keeps a balance in block 4.
// LEARNING ONLY: Mifare Classic is easy to copy and change, so never use this for real money.
#include <SPI.h>
#include <MFRC522.h>
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
MFRC522 rfid(10, 9);
LiquidCrystal_I2C lcd(0x27, 16, 2);
const byte ROWS = 4, COLS = 4;
char keys[ROWS][COLS] = {{'1','2','3','A'},{'4','5','6','B'},{'7','8','9','C'},{'*','0','#','D'}};
byte rowPins[ROWS] = {2, 3, 4, 5}, colPins[COLS] = {A0, A1, A2, A3};
Keypad pad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
MFRC522::MIFARE_Key key;
const byte BLOCK = 4;
long amount = 0;
bool topUp = false;
bool readBalance(long &bal) {
  byte buf[18]; byte sz = sizeof(buf);
  if (rfid.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, BLOCK, &key, &(rfid.uid)) != MFRC522::STATUS_OK) return false;
  if (rfid.MIFARE_Read(BLOCK, buf, &sz) != MFRC522::STATUS_OK) return false;
  long b, inv; memcpy(&b, buf, 4); memcpy(&inv, buf + 4, 4);
  if (b != ~inv) return false;                          // check value: balance and its inverse must agree
  bal = b; return true;
}
bool writeBalance(long bal) {
  byte buf[16] = {0}; long inv = ~bal;
  memcpy(buf, &bal, 4); memcpy(buf + 4, &inv, 4);
  return rfid.MIFARE_Write(BLOCK, buf, 16) == MFRC522::STATUS_OK;
}
void show(const char* a, const char* b = "") { lcd.clear(); lcd.print(a); lcd.setCursor(0, 1); lcd.print(b); }
void setup() {
  Serial.begin(115200);
  SPI.begin(); rfid.PCD_Init();
  for (byte i = 0; i < 6; i++) key.keyByte[i] = 0xFF;   // factory key: fine for a classroom demo
  pinMode(8, OUTPUT);
  lcd.init(); lcd.backlight();
  show("Enter price", "then # and tap");
}
void loop() {
  char k = pad.getKey();
  if (k >= '0' && k <= '9' && amount < 9999) { amount = amount * 10 + (k - '0'); char t[17]; snprintf(t, 17, "%s %ld", topUp ? "Top up" : "Price", amount); show(t, "# then tap tag"); }
  if (k == '*') { amount = 0; topUp = false; show("Cancelled", "Enter price"); }
  if (k == 'A') { topUp = true; amount = 0; show("Top up mode", "Enter amount"); }
  if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial()) return;
  long bal;
  if (!readBalance(bal)) {
    if (topUp && amount > 0 && writeBalance(amount)) show("New tag", "balance set");
    else show("Tag unreadable", "or not set up");
    tone(8, 300, 400);
  } else if (amount == 0) {
    char t[17]; snprintf(t, 17, "Balance %ld", bal); show(t);
  } else if (topUp) {
    if (writeBalance(bal + amount)) { char t[17]; snprintf(t, 17, "Now %ld", bal + amount); show("Topped up", t); tone(8, 1500, 150); Serial.print("TOPUP,"); Serial.println(amount); }
    amount = 0; topUp = false;
  } else if (bal >= amount) {
    if (writeBalance(bal - amount)) { char t[17]; snprintf(t, 17, "Left %ld", bal - amount); show("Paid", t); tone(8, 1500, 150); Serial.print("SALE,"); Serial.println(amount); }
    amount = 0;
  } else { show("Not enough", "balance"); tone(8, 300, 400); }
  rfid.PICC_HaltA(); rfid.PCD_StopCrypto1();
  delay(1000);
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
New tag in top-up modeBalance set
Tap with price enteredBalance falls by the price
Price above balanceNot enough balance
Serial logEvery sale and top-up listed

If it does not work

Reader not found

Check the 3.3 V supply and the SPI wires.

Tag unreadable

Set it up in top-up mode first.

Keys ignored

Check the row and column order.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the RFID wristband cashless payment?

Arduino Uno R3, RC522 RFID reader, RFID tags 13.56 MHz (MIFARE Classic 1K) × 5, 16x2 LCD with I2C backpack (PCF8574), Active buzzer 5 V and 4x4 matrix keypad (membrane).

How long does the RFID wristband cashless payment take to build?

About 240 minutes for a intermediate maker, in 7 steps.

How do I know the RFID wristband cashless payment works?

New tag in top-up mode: Balance set. Tap with price entered: Balance falls by the price. Price above balance: Not enough balance.

Reader not found: what should I check?

Check the 3.3 V supply and the SPI wires.

Tag unreadable: what should I check?

Set it up in top-up mode first.

Keys ignored: what should I check?

Check the row and column order.