Week 8 – Unusual Switch

Concept
I always keep my magnetic cardholder attached to the back of my phone. It can hold one to three cards comfortably without them falling out. Recently, I almost lost my NYU FAB card, which had around 800 dirhams on it for my study abroad visa appointment. I was so upset and searched my room for two days, cleaning everything. Finally, I found it under my glasses case. That was such a relief. From now on, I’ll always keep it in my cardholder.

For this Arduino project, I reused the LED code from class. The light stays on when the card is outside the holder, and it turns off when the card is inside, showing that it’s safe. I used aluminum foil to extend the wire’s conductivity and duct tape to build a working prototype.

Photo
Video
Unusual Switch on Arduino UNO

Highlight of the code
That’s actually the entirety of the code. The code itself is simple. It starts with a 5V input, and I used digitalWrite(2, LOW) to let the electricity flow since it works from high to low. The system detects when there is contact with the card. If the card touches the sensor, the LED turns off. If there’s no contact and the card is outside the holder, the LED stays on as an alert to remind the user to put the card back for safety. That’s exactly what I did with my FAB card.

void setup() {
  pinMode(13, OUTPUT); // led pin
  pinMode(2, INPUT);  // foil pin
  digitalWrite (2, LOW);
}

void loop() {
  int cardtouch = digitalRead(2);

  if (cardtouch == LOW) { 
    digitalWrite(13, HIGH); 
  } else {
    digitalWrite(13, LOW);
  }

}

Reflection
It’s clear that the prototype isn’t perfect. I can already see ways to improve it, especially since the wires limit the movement of the card. Using a motion or distance sensor would be a better option if I want to make it portable and attach it to my cardholder. The foil isn’t always reliable either. It sometimes slips off the wire, which reduces conductivity and can cause the LED to give the wrong signal. Still, I think it’s great that after just one class, I could use the same code to create something useful that I might actually use in the future.

Leave a Reply