Unusual Switch

https://github.com/da3755-ui/intro-to-im/blob/84cc7d7002b1b2e0cfad3839631bc4e4fa16566c/UnusualSwitchAssignment_IntroToIM.ino

 

The Concept

For this assignment I had two attempts and changed my concept. my first concept was a switch that lights up when you put glasses on. I ended up changing it to a led that lights up when a book is closed.

The Process

I used the same process for both concepts. Connected to my breadboard was an led with a jumper wire connected from the longer leg to a digital pin, and from the shorter leg a resistor then a wire connecting to ground.

For my conductor I used aluminum foil. I put aluminum foil on two pages of the book and placed a jumper wires on each foil. the first wire is connected to ground while the second to a digital pin. When the book closes, the foils touch the led lights up.

Challenges

The main challenge was in my glasses concept. ALthough my wiring and code were correct, I had a problem with connecting the foils and the wires together and getting them to light up the LED. After removing the wires from the foils and putting them towards each other I realized the issue. To fix this for my book concept, I made sure the tips of the wires were properly secured to the foil to ensure proper conduction for the foils.

I also  had to watch many Youtube videos after my failed attempt to get a full understanding of the difference between digital pins and power, understanding how LEDs work, and how circuits open and close with the arduino. I also watched many tutorials on digital read, write, and inputs to understand how it works. I also rewatched the lectures and decided to switch my code from using INPUT to INPUT_PULLUP after I heard someone  in class say it helps since arduino already has a built in resistor and this makes it mroe stable.

Code snippet

  if (state == LOW) {   
    digitalWrite(ledPin, HIGH);
  } else {
    digitalWrite(ledPin, LOW);
  }
  // digitalWrite(ledPin, HIGH);
}

I am actually most proud of the commented out code. This code is what helped me understand whether the problem in my failed attempt was because of wiring or because of the foils. After commenting out almost everythung out, leaving only relevant code, and adding this final line of code, I realized the led was working and the issue was with the foil.

Reflection

For future works I would love to create something with other forms of sensors like a sound sensor so the switch can light up with sound.

References

I also cant figure out how to move the code to github so here is the code

int book = 2;
int ledPin = 13;

void setup() {
  pinMode(book, INPUT_PULLUP);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  int state = digitalRead(book);

  if (state == LOW) {   
    digitalWrite(ledPin, HIGH);
  } else {
    digitalWrite(ledPin, LOW);
  }
  // digitalWrite(ledPin, HIGH);
}

 

 

Leave a Reply