Alternative to PIN 10(SS)

My PIN 10 on Arduino UNO is not working . I'am trying to get a MFRC522 Reader to get to work with arduino . So how i can i reassign a new SS pin on the board???

That depends on what you are trying to do.

Simple SPI applications you only need to use a different output in.

Example:

  // enable Slave Select
  digitalWrite( 9, LOW);    
  
  // send test string
  for (const char * p = "Fab" ; c = *p; p++)
    SPI.transfer (c);

 // disable Slave Select
 digitalWrite( 9, HIGH);

For pin 5 use the above.

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

 
#define SS_PIN 10
#define RST_PIN 9

#define SERVO_PIN 3
Servo myservo;

#define ACCESS_DELAY 1000
#define DENIED_DELAY 1000
MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.
 
void setup() 
{
  Serial.begin(9600);   // Initiate a serial communication
  SPI.begin();          // Initiate  SPI bus
  mfrc522.PCD_Init();   // Initiate MFRC522

  myservo.attach(SERVO_PIN);
  myservo.write( 0 );
  delay(7500);
  myservo.write( 0 );
  Serial.println("Put your card to the reader...");
  Serial.println();

}
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));
  }
  Serial.println();
  Serial.print("Message : ");
  content.toUpperCase();
  if (content.substring(1) == "C5 68 AF AC") //change here the UID of the card
  {
    Serial.println("Authorized access");
    Serial.println();
   myservo.write( 180 );
 delay(7500);
  myservo.write( 0 );

  }
 
 else   {
    Serial.println(" Access denied");
 

    delay(DENIED_DELAY);

 
  }
}

How can i add it to this code?

Did you try:


`MFRC522 mfrc522( 5, RST_PIN);   // Create MFRC522 instance.`

replace

#define SS_PIN 10

with

constexpr byte SS_PIN {5}; // or any other pin you can can use 

and keep the line

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

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