   digitalWrite(A0, locked);
 }
 
+bool readRfid() {
+  char buffer[TAG_LENGTH];
+  int count = 0;
+  bool tagChanged = false;
+
+  if (rfidSerial.available()) {
+    if (rfidSerial.read() != 2)
+      return false;
+    while (count < TAG_LENGTH && rfidSerial.available()) {
+      buffer[count] = rfidSerial.read();
+      count++;
+    }
+
+    if (count == TAG_LENGTH) {
+      count = 0;
+      if (rfidSerial.read() != 3)
+        return false;
+      for (int i = 0; i < TAG_LENGTH; i++) {
+        tagChanged |= buffer[i] != rfidTag[i];
+      }
+    }
+    if (tagChanged) {
+      memcpy(rfidTag, buffer, TAG_LENGTH);
+      rfidTag[TAG_LENGTH] = 0;
+      Serial.print("Changed: "); Serial.println(rfidTag);
+    }
+  }
+}
+
 void loop() {
+  readRfid();
   readLightsensor();
   readDataFromMpu();
 

uint16_t fifoCount;     // count of all bytes currently in FIFO
uint8_t fifoBuffer[64];

// Software serial for XBee module
SoftwareSerial xbeeSerial(2, 3); // RX, TX

void setup() {
  // Setup serials
  Serial.begin(SERIAL_BAUDRATE);
  xbeeSerial.begin(SERIAL_BAUDRATE);

  // Setup lock
  pinMode(A0, OUTPUT);


#define FETCH_INTERVAL 100
#define POST_INTERVAL 5000

#define TAG_LENGTH 12

const int numLedSamples = POST_INTERVAL / FETCH_INTERVAL;
int ledSamples[numLedSamples];
