DianWardiana
Junior Member level 3
Hi,
I'm using Arduino Nano to read RFID card. I'm using RC522 as RFID Reader.
I have problem when i try to save RFID card value with leading zero into string. The leading zero is not saved into string.
Here is my code:
Here is the result in Serial monitor:
https://imgur.com/a/0mbxlDH
What i want is the String under "Hex normal" would be "04292e5a" not "4292e5a"
Thank You.
I'm using Arduino Nano to read RFID card. I'm using RC522 as RFID Reader.
I have problem when i try to save RFID card value with leading zero into string. The leading zero is not saved into string.
Here is my code:
Code:
#include <SPI.h>
#include <MFRC522.h>
#include <stdlib.h>
#define RST_PIN 9
#define SS_PIN 10
String inStringHex = "";
MFRC522 mfrc522(SS_PIN, RST_PIN);
void setup() {
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
}
void loop() {
// Look for new cards
if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial())
{
//Serial.print("Card UID:");
for (byte i = 0; i < 4; i++) {
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? "0" : "");
Serial.print(mfrc522.uid.uidByte[i], HEX);
inStringHex += String(mfrc522.uid.uidByte[i], HEX);
}
Serial.println();
Serial.println(F("Hex normal"));
Serial.print(inStringHex);
Serial.println();
Serial.println();
inStringHex = "";
delay(5000);
}
}
Here is the result in Serial monitor:
https://imgur.com/a/0mbxlDH
What i want is the String under "Hex normal" would be "04292e5a" not "4292e5a"
Thank You.