Nfc-ing a lock

Hi Denis!
I used a particle Photon and a http://www.stronglink-rfid.com/en/rfid-modules/sl030.html

Photon to SL030 wiring:

  • A3/TAG 5
  • A4/SDA 3
  • A5/SCL 4
  • 5V -
  • GND 6
  • 3V3 1

Here is the code I used to capture the ID :slight_smile: If I’m correct you should see the ID in particle console. There is an IFTTT and SmartThings integration, I imagine you can open an lock or turn a light on with this :slight_smile:

int led = D7; 
int TAG = A3; 

char* mifare[] = { "1K", "Pro", "UltraLight", "4K", "ProX", "DesFire" };

void setup()
{
  // Init serial port to host and I2C interface to SL018/SL030
  Serial.begin(19200);
  Wire.begin();

  // Initialize D0 pin as an output
  pinMode(led, OUTPUT);
  pinMode(TAG, INPUT);
  
  // Prompt for tag
  Serial.println("Show me your tag");
}

void loop()
{
  // Wait for tag
  //while(digitalRead(TAG));
  if (digitalRead(TAG) == LOW) {   
    // Read tag ID
    readID();
  } 
  // Wait until tag is gone
  //while(!digitalRead(TAG));
}

int readID()
{
  digitalWrite(led, HIGH);
  
  // Send SELECT command
  Wire.beginTransmission(0x50);
  Wire.write(1);
  Wire.write(1);
  Wire.endTransmission();
  
 // Wait for response
  while(!digitalRead(TAG))
  {
    // Allow some time to respond
    delay(5);
    String ID;
    
    // Anticipate maximum packet size
    Wire.requestFrom(0x50, 11);
    if(Wire.available())
    {
      // Get length of packet
      byte len = Wire.read();
      
      // Wait until whole packet is received
      while(Wire.available() < len)
      {
        // Quit if no response before tag left
        if(digitalRead(TAG)) { return 0; digitalWrite(led, LOW);}
      }

      // Read command code, should be same as request (1)
      byte command = Wire.read();
      if(command != 1) { return -1; digitalWrite(led, LOW);}
      
      // Read status
      byte status = Wire.read();
      
      switch(status)
      {
        case 0: // Succes, read ID and tag type
        {
          len -= 2;
          // Get tag ID
          while(--len)
          {
            byte data = Wire.read();
            
            if(data < 0x10) {
                Serial.print(0);
                ID += "0"; 
            }    
            
            ID += String(data);
            Serial.print(data, HEX);
          }


          Serial.println(ID);
          Spark.publish("update", ID);
          
          // Get tag type
          byte type = Wire.read();
          if(type > 0 && type < sizeof(mifare))
          {
            Serial.print(" Mifare ");
            Serial.print(mifare[type - 1]);
          }
          Serial.println();
        }
        digitalWrite(led, LOW);
        delay(700);
        return 1;

      case 0x0A: // Collision
        Serial.println("Collision detected");
        break;

      case 1: // No tag
        Serial.println("No tag found");
        break;

      default: // Unexpected
        Serial.println("Unexpected result");
      }
      digitalWrite(led, LOW);
      return -1;
    }
  }
  // No tag found or no response
  digitalWrite(led, LOW);
  return 0;
}
1 Like