RFID DOORlOCK WITH ESP8266

Hello guys, i want to ad more 2 tag on my code, but i don't know how i can do it.
code:

#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>

Servo myServo;

#define SS_PIN 2    //D4
#define RST_PIN 0   //D3
#define REDLED 16   //D0
#define GREENLED 5  //D1

MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance.

bool locked;

void setup() {
  Serial.begin(9600);  // Initiate a serial communication
  SPI.begin();         // Initiate  SPI bus
  mfrc522.PCD_Init();  // Initiate MFRC522
  mfrc522.PCD_DumpVersionToSerial();

 // myServo.attach(4);  // servo attach D2 pin of arduino
  //locked = false;

  pinMode(REDLED, OUTPUT);
  pinMode(GREENLED, OUTPUT);
}

Void loop() {
  // Look for new cards
  if (!mfrc522.PICC_IsNewCardPresent()) {
    return;
  }
  // Select one of the cards
  if (!mfrc522.PICC_ReadCardSerial()) {
    return;
  }
  //Show UID on serial monitor
  Serial.println();
  Serial.print(" UID tag :");
  String content = "";
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(mfrc522.uid.uidByte[i], HEX);
    content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
    content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  content.toUpperCase();
  Serial.println();

  //if (content.substring(1) == "43 02 3F FB")  //change UID of the card that you want to give access 53 88 FE 1F
  // PRIMEIRA EXECUÇÃO
  if (content.substring(1) == "43 02 3F FB")
  if (content.substring(1) == "53 88 FE 1F")

  {
    digitalWrite(GREENLED, HIGH);   
    delay(1000);
    digitalWrite(GREENLED, LOW);
    digitalWrite(REDLED, LOW); 


  }

  else
   {
    digitalWrite(REDLED, HIGH);
    delay(1000);
    digitalWrite(GREENLED, LOW);
    digitalWrite(REDLED, LOW);
    delay(1000);
   
  }
}  

Your problem isn't related to the version of the IDE you are using so I will move your topic to a more appropriate section of the forum. Please choose which forum section with more care. Read the sticky post at the top of the forum section to know if it is the right place for your question.

Please post the real, complete code. Otherwise it is very difficult to give correct advice. I can tell that the code you posted is not the real code because you spelled "Void" with a capital letter :wink:

This code will not do nothing, I think:

  if (content.substring(1) == "43 02 3F FB")
  if (content.substring(2) == "53 88 FE 1F")

The reasons are that your String content cannot be equal to 2 different id codes at the same time. If the first if condition is true, the second one must be false. Also you are comparing a different part of content because of the parameter you give to .substring().

Maybe this is what you want:

  if (content.substring(1) == "43 02 3F FB" or
       content.substring(1) == "53 88 FE 1F")

Thanks for your help, is working now.

1 Like

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