Week 8 The Switch

Description:

I have always been the worst when it came to forgetting different things at different places. Forgetting my card at the most random places was getting me locked out of my room more than I would have liked. So I decided to make a switch that reminds you to put your card back in its place sometime out.

I started by placing a switch in the circuit and making it work using a normal push-button switch. once I finished the circuit I replaced one end of the switch with a wire connected to the card and the other end with a wire connected to a cardholder that is to be stuck to a phone.

I connected the wires to copper tape that I stuck on contacting sides of the card and the cardholder so that when the card is in place, the switch is closed.

I used a yellow led light for the normal time when the card is placed in its location. when you remove the card from the cardholder, a timer starts, when the time span in the code ends, the red light starts to blink to remind you to put the card back in.

IMAGES:

Breadboard Circuit:

Whole Circuit:

Card Connection

Video:

CODE:

long mytime=500, timer = 0;
const int outs[] = {2, 4};
const int ins = A2;
int curr = 0, prev=0;
bool flip=false;
long blinkk=0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  for (int i = 0; i < sizeof(outs); i++) {
    pinMode(outs[i], OUTPUT);
  }
  pinMode(ins, INPUT);
}

void loop() {
  curr = digitalRead(ins);// <500, <900, >900
  if (curr == 0) {
    Serial.print(timer);
    Serial.print(" ");
    Serial.println(mytime);
    if (mytime == timer) {
      if(blinkk<=millis()){
        flip=!flip;
        blinkk+=500;
      }
      digitalWrite(outs[0], flip);
      digitalWrite(outs[1], LOW);
    }
    else{
      timer+=1;
      digitalWrite(outs[0], LOW);
      digitalWrite(outs[1], LOW);
    }
  }
  else {
    {
      timer=0;
      digitalWrite(outs[1], HIGH);
      digitalWrite(outs[0], LOW);
      blinkk=millis();
    }
  }
  prev = digitalRead(ins);
}

 

 

 

Leave a Reply