The issue with the ESP32 connection to the RFID on the RST pin

I have a problem with the RFID RC-522 reader in a device I created. I am using an ESP32 connected to pins SDA=16 and RST=22. At one point, while the system was working, the RST pin stopped working. I then changed it to pin 21, and it worked for a while, but the problem recurred, and the RFID stopped working again. Has anyone found a solution to this issue? I have already tried it with an Arduino Uno, and it successfully read the RFID, so I assume the RC-522 RFID module is functioning correctly.

my program:

#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#include <MFRC522.h>
#include <HTTPClient.h>
#include <DHT.h>
#include <RBDdimmer.h>



#define SDA_PIN 16
#define RST_PIN 22
#define LAMP_INDICATOR 13
#define SOLENOID 12
#define outputPin 27
#define zerocross 26
#define DHTPIN 17
#define DHTTYPE DHT22

MFRC522 mfrc522(SDA_PIN, RST_PIN);
DHT dht(DHTPIN, DHTTYPE);
dimmerLamp dimmer(outputPin, zerocross);
const int batas_maks_sudut_picu = 120;
const int batas_min_sudut_picu = 80;

String IDTAG = "";
String statusMessage = "";

unsigned long previousRFIDTime = 0;
unsigned long previousTempHumTime = 0;
unsigned long previousSpeedChangeTime = 0;
unsigned long previousIFTTTTime = 0;

const unsigned long rfidInterval = 500;
const unsigned long tempHumInterval = 1000;
const unsigned long speedChangeInterval = 500;
const unsigned long accessDeniedDuration = 5000; // 5 seconds
const unsigned long IFTTTInterval = 1000; // 1 second

bool accessDenied = false;
unsigned long accessDeniedStartTime = 0;



String value1ToSend = "";
String value2ToSend = "";
String value3ToSend = "";

void setup() {
  Serial.begin(115200);
  mfrc522.PCD_Init();
  pinMode(LAMP_INDICATOR, OUTPUT);
  pinMode(SOLENOID, OUTPUT);
  dht.begin();
  dimmer.begin(NORMAL_MODE, ON);
  Blynk.begin(auth, ssid, pass);
}

void loop() {
  Blynk.run();
  unsigned long currentMillis = millis();

  if (accessDenied && (currentMillis - accessDeniedStartTime >= accessDeniedDuration)) {
    accessDenied = false;
  }

  if (!accessDenied && currentMillis - previousRFIDTime >= rfidInterval) {
    readRFID();
    previousRFIDTime = currentMillis;
  }

  if (!accessDenied && !mfrc522.PICC_IsNewCardPresent()) {
    if (currentMillis - previousTempHumTime >= tempHumInterval) {
      readTemperatureHumidity();
      updateDimmerAngle(currentMillis);
      previousTempHumTime = currentMillis;
    }
  }

  if (currentMillis - previousIFTTTTime >= IFTTTInterval) {
    sendIFTTTData();
    previousIFTTTTime = currentMillis;
  }
}

void readRFID() {
  if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
    IDTAG = "";
    for (byte i = 0; i < mfrc522.uid.size; i++) {
      IDTAG += mfrc522.uid.uidByte[i];
    }

    if (IDTAG == "1631169166")      controlLEDs("GROUP1");
    else if (IDTAG == "22787245166") controlLEDs("GROUP2");
    else if (IDTAG == "2225594175") controlLEDs("GROUP3");
    else {
      value1ToSend = "AKSES DITOLAK " + IDTAG;
      sendIFTTTData();
      Blynk.virtualWrite(V2, "Akses ditolak");
      accessDenied = true;
      accessDeniedStartTime = millis();
    }
  }
}

void controlLEDs(String group) {
  static bool areLEDsOn = false;
  if (areLEDsOn) {
    digitalWrite(LAMP_INDICATOR, LOW);
    digitalWrite(SOLENOID, LOW);
    statusMessage = group + " CLOSE";
  } else {
    digitalWrite(LAMP_INDICATOR, HIGH);
    digitalWrite(SOLENOID, HIGH);
    statusMessage = group + " OPEN";
  }
  areLEDsOn = !areLEDsOn;
  Blynk.virtualWrite(V2, statusMessage);
}

void readTemperatureHumidity() {
  float temperature = dht.readTemperature();
  float humidity = dht.readHumidity();
  Blynk.virtualWrite(V0, temperature);
  Blynk.virtualWrite(V1, humidity);
  String value3 = getBlowerSpeedString(temperature);
  value1ToSend = statusMessage;
  value2ToSend = "Temperature: " + String(temperature) + "°C, Humidity: " + String(humidity) + "%";
  value3ToSend = value3;
}

String getBlowerSpeedString(float temperature) {
  if (temperature >= 34 && temperature <= 36) {
    return "Kecepatan Blower: 1";
  } else if (temperature >= 36 && temperature <= 38) {
    return "Kecepatan Blower: 2";
  } else if (temperature >= 38 && temperature <= 40) {
    return "Kecepatan Blower: 3";
  }
  return "";
}

void updateDimmerAngle(unsigned long currentMillis) {
  float temperature = dht.readTemperature();
  int angle = 0;
  if (temperature >= 34 && temperature <= 36) {
    angle = 80;
  } else if (temperature >= 36 && temperature <= 38) {
    angle = 100;
  } else if (temperature >= 38 && temperature <= 40) {
    angle = 120;
  }
  if (angle != 0 && currentMillis - previousSpeedChangeTime >= speedChangeInterval) {
    setDimmerAngle(angle);
    previousSpeedChangeTime = currentMillis;
  }
}

void setDimmerAngle(int angle) {
  int persen_pemotongan_tegangan = map(angle, 0, 180, 0, 100);
  dimmer.setPower(persen_pemotongan_tegangan);
  String speed = getBlowerSpeedString(dht.readTemperature());
  Blynk.virtualWrite(V3, speed);
}

void sendIFTTTData() {
  HTTPClient http;
  String payload = String("{ \"value1\": \"") + value1ToSend + "\", \"value2\": \"" + value2ToSend + "\", \"value3\": \"" + value3ToSend + "\" }";
  http.begin(IFTTTUrl);
  http.addHeader("Content-Type", "application/json");
  int httpResponseCode = http.POST(payload);
  http.end();
}

I moved your topic to an appropriate forum category @anggaamalulahli.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.