Hi, greetings everyone. I'm currently working on my final year project which I'm using UHF RFID reader (YPD-R200), AC voltage LM358 V3 volt sensor to measure tx or rx volt, ESP32 as microcontroller, UHF on-metal RFID tags and LCD for output display. The project concept is when reader reads the tag's epc code which was updated in database, esp32 will convert the hexa and lcd will display the output ( Manhole ID, Owner) while i want serial monitor to have measured volt.
#include <WiFi.h>
#include <HTTPClient.h>
#include <LiquidCrystal_I2C.h>
#include <HardwareSerial.h>
const char* ssid = "-------2.4GHz"; // Your WiFi SSID
const char* password = "-------"; // Your WiFi Password
#define RXD2 16
#define TXD2 17
LiquidCrystal_I2C lcd(0x27, 16, 2);
HardwareSerial rfidSerial(2);
String lastTag = "";
unsigned long lastSeen = 0;
void setup() {
Serial.begin(115200);
rfidSerial.begin(115200, SERIAL_8N1, RXD2, TXD2);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Connecting WiFi");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("Connected.");
lcd.clear();
lcd.print("Scan tag...");
}
void loop() {
static String buffer = "";
while (rfidSerial.available()) {
char c = rfidSerial.read();
buffer += c;
if (buffer.length() > 128)
buffer = buffer.substring(buffer.length() - 64);
if (buffer.length() >= 24) {
String epc = parseEPC(buffer);
if (epc.length() == 24 && epc != lastTag && epc != "000000000000000000000000") {
lastTag = epc;
lastSeen = millis();
Serial.println("Detected EPC: " + epc);
fetchTagInfo(epc);
buffer = "";
}
}
}
if (millis() - lastSeen > 5000 && lastTag != "") {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Scan tag...");
lastTag = "";
}
}
String parseEPC(const String &raw) {
String hexStr = "";
for (int i = 0; i < raw.length(); i++) {
byte b = (byte)raw[i];
if (b < 0x10) hexStr += "0";
hexStr += String(b, HEX);
}
hexStr.toUpperCase();
if (hexStr.length() >= 24) {
return hexStr.substring(hexStr.length() - 24);
}
return "";
}
void fetchTagInfo(String epc) {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
String url = "http://192.----------/get_tag_info.php?epc=" + epc;
http.begin(url);
int httpCode = http.GET();
if (httpCode > 0) {
String payload = http.getString();
Serial.println(payload);
// Parse JSON and display on LCD
int ownerIdx = payload.indexOf("\"owner\":\"");
int descIdx = payload.indexOf("\"description\":\"");
if (ownerIdx > -1 && descIdx > -1) {
String owner = payload.substring(ownerIdx + 9, payload.indexOf("\"", ownerIdx + 9));
String description = payload.substring(descIdx + 15, payload.indexOf("\"", descIdx + 15));
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Owner: " + owner);
lcd.setCursor(0, 1);
if (description.length() > 16) description = description.substring(0, 16);
lcd.print(description);
} else {
lcd.clear();
lcd.print("Tag not found");
}
} else {
Serial.println("Error on HTTP: " + String(httpCode));
lcd.clear();
lcd.print("HTTP error");
}
http.end();
} else {
Serial.println("WiFi not connected");
lcd.clear();
lcd.print("WiFi Disconnect");
}
}
but when reader is initiated lcd shows unknown tags while serial monitor shows variety of detected epc and which is not from the tag that i have. Can anyone help me please?