/*
1. click the breakout circuit board (custom chip)
2. Slide the UID generator slider
3. Press the Green Button for sending data
Note: I am writing a code that supports MFRC522 library,
but I can't make it work,
so here's the link: https://wokwi.com/projects/423914137980242945
(c) 2025, James Balolong
*/
#include <SPI.h>
#define CS 5 // Chip Select pin connected to the custom chip's CS pin
void setup() {
// Initialize Serial for debugging
Serial.begin(115200);
// Configure CS pin as output and set it high initially
pinMode(CS, OUTPUT);
digitalWrite(CS, HIGH);
// Initialize SPI with default pins (SCK: 18, MISO: 19, MOSI: 23)
SPI.begin();
Serial.println("ESP32 SPI initialized, waiting for UID...");
}
void loop() {
uint8_t buffer[4] = {0}; // Buffer to store the 4-byte UID
// Start an SPI transaction
digitalWrite(CS, LOW); // Pull CS low to enable the slave
SPI.transfer(buffer, 4); // Perform a 4-byte transfer, reading data into buffer
digitalWrite(CS, HIGH); // Pull CS high to end the transaction
// Check if any data was received (not all zeros, assuming UID isn't 0x00 0x00 0x00 0x00)
if (buffer[0] != 0 || buffer[1] != 0 || buffer[2] != 0 || buffer[3] != 0) {
Serial.print("Received UID: ");
for (int i = 0; i < 4; i++) {
Serial.print("0x");
// Add leading zero for single-digit hex values
if (buffer[i] < 16) Serial.print("0");
Serial.print(buffer[i], HEX);
Serial.print(" ");
}
Serial.println();
}
// Small delay to prevent overwhelming the Serial Monitor
delay(100);
}SOLENOID
LOCK
sent to
lora indicator