Week 8 – Unusual Switch

Demo Below:

 Concept:

I have an extra Arduino I got years ago, so I decided to scour through the parts to see if I can find something to use, which I did! The switch here is more functional rather than unusual, but its hand-less nonetheless. The 2 main players here is an RFID reader and a dot matrix module. The RFID reader reads the card in your pocket while you walk through the door. If the card matches the accepted card(s), a green LED will flash and a smiley face will be shown on the dot matrix module. However if a person with the wrong card passes through the door, the red LED will flash and the dot matrix will show a huge X.

Implementation:

void loop() {
  if (!mfrc522.PICC_IsNewCardPresent() || !mfrc522.PICC_ReadCardSerial()) {
    return;
  }
...
}

We begin our loop code with this, and what this does is just check if the RFID module can read a card at all, if it can’t the rest of the code won’t run at all.

// Long green flash when correct card and show smile.
if (match) {
  Serial.println("ACCESS GRANTED");
  digitalWrite(GREEN_LED_PIN, HIGH);
  showSmile();
  delay(3000); 
  digitalWrite(GREEN_LED_PIN, LOW);
}

Here if the card scanned matches the card we give access to, we turn on the green pin and show the smile on the dot matrix module, this lasts for 3 seconds before turning things off.

else {
    Serial.println("ACCESS DENIED - ALARM");
    showX();
    
    // Repeated red flashing
    for(int i = 0; i < 5; i++) {
      digitalWrite(RED_LED_PIN, HIGH);
      delay(100);
      digitalWrite(RED_LED_PIN, LOW);
      delay(100);
    }
  }

If the card that is read does not match the card we want, then we will show the X on the dot matrix and repeatedly flash the red LED 5 times.

// Reset visuals
lc.clearDisplay(0);
lc.setLed(0, 0, 0, true); 
mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();

At the end of the loop, we just turn on a singular dot that is top left of the dot matrix, to show that it is currently on standby.

ShowX and ShowSmile are functions that simply turn on the correct dots in the matrix to show the image we want to show.

GitHub Code is here.

Reflection:

The only thing I would really add here is maybe a buzzer with 2 different sounds for either granting access or rejecting access.

 

Leave a Reply