Rfid and 2 push buttons Door lock

Hello i needed help to do the code to work I wanted an RFID + servo in my door out and inside 2 buttons which one opens and close the door from inside, but i cant get it work the buttons with the rfid code i need help. There is the code if you can suggest me anything is welcome thanks.
////////////////////////////////////////////////////////
</>MFRC522 mfrc522(SS_PIN, RST_PIN);
const int BUTTON1 = 3;
int BUTTONstate1 = 0;
const int BUTTON2 = 2;
int BUTTONstate2 = 0;
int pos = 0;

Servo myservo;
void setup()
{
pinMode(BUTTON1, INPUT);
pinMode(BUTTON2, INPUT);
Serial.begin(9600); // Initiate a serial communication
SPI.begin(); // Initiate SPI bus
mfrc522.PCD_Init(); // Initiate MFRC522
Serial.println("Approximate your card to the reader...");
Serial.println();
myservo.attach(6);
Servo myservo;

}
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.print("UID tag :");
String content= "";
byte letter;
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));
delay(100);
}
Serial.println();
Serial.print("Message : ");
content.toUpperCase();
if (content.substring(1) == "0C E4 F9 2F");
{
myservo.write(180);
Serial.println("Authorized access");
Serial.println();
delay(3000);
}
(BUTTONstate1 = digitalRead(BUTTON1));
if (BUTTONstate1 == HIGH)
{
myservo.write(100);
Serial.print("1pressed");
delay(3000);
}
(BUTTONstate2 = digitalRead(BUTTON2));
if (BUTTONstate2 == HIGH)
{
myservo.write(50);
Serial.print("2pressed");
delay(3000);
}
}

////////////////////

Your post was MOVED to its current location as it is more suitable.

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

1 Like

Why the parentheses?

  (BUTTONstate1 = digitalRead(BUTTON1));

Your buttons are declared as INPUT inside setup(). This configuration demands that pull-up or pull-down resistors be installed with the buttons. Are those resistors installed? It is much more common (and easier) to use the internal pullup resistors on the arduino. Declare the pin as INPUT_PULLUP, wire one side of the button to ground and the other to the pin. When pressed, it will read LOW, when not pressed, it will read HIGH.

You should also check out the state change detection example in the IDE (File->examples->02.digital->State Change Detection) to learn how to know when you button gets pressed, not if it is currently pressed.

@fotis_fotis, your topic has been moved (again) to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advise on) your project :wink: See About the Installation & Troubleshooting category.

And as requested, please edit your post, select all code and click the </> button to apply so-called code tags and next save your post. It makes it easier to read, easier to copy and prevents the forum software from incorrect interpretation of the code.

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