Assignment 6 Unusual Switch

Concept: 

While thinking of unusual switches, the first thing that came to mind was how suitcase locks work. How setting some sort of combination and pressing a button would make that into a ‘password’ that you could repeatedly use to open the suitcase. Inspired and fascinated by the workings of such a simple concept I came up with the idea of mimicking a combination lock but instead using buttons on a breadboard. Although using our hands wasn’t technically a part of the assignment, I do believe that being able to set a combination using the code, and having the circuit only work when the correct combination is entered is a creative switch.
Code Highlight:

Approaching this problem I had to think very creatively about how the Arduino code would work with multiple switches. In the end the best solution I arrived at was setting a lock using the pins each switch was connected to and then checking if each switch pressed in order was one corresponding to its index in the combination array.

const int buttonPins[] = {2, 3, 4, 5}; // Digital pins connected to the buttons
const int ledPin = 13; // Digital pin connected to the LED
int combo[] = {0, 1, 2, 3}; // The correct sequence of button presses (in order)
int input[4]; // Array to store the user's button press sequense
int index = 0; // Keeps track of how many correct buttons have been pressed
bool isUnlocked = false; // Flag to indicate if the correct combination has been entered

void setup() {
  // Set up each button pin as an input
  for (int i = 0; i < 4; i++) {
    pinMode(buttonPins[i], INPUT);
  }
  // Set up the LED pin as an output
  pinMode(ledPin, OUTPUT);
}

void loop() {
  if (!isUnlocked) { // Only check for button presses if the lock is not yet unlocked
    for (int i = 0; i < 4; i++) { // Iterate over each button
      if (digitalRead(buttonPins[i]) == HIGH) { // Check if the current button is pressed
       delay(50) //Small delay to ensure one press is not registered multiple times
        if (digitalRead(buttonPins[i]) == HIGH) { // Confirm the button is still pressed
          if (i == combo[index]) { // Check if this button is the next in the correct sequence
            input[index] = i; // Record the correct press in the input array
            index++; // Move to the next position in the sequence
            delay(500); // Delay to avoid multiple readings from a single press
          } else {
            index = 0; // Reset if a wrong button is pressed
            break; // Exit the loop to start checking from scratch
          }
        }
      }
    }

    if (index == 4) { // If all buttons have been pressed in the correct order
      digitalWrite(ledPin, HIGH); // Turn on the LED to indicate success
      isUnlocked = true; // Set flag to indicate that the lock has been unlocked
    }
  }
}

Demonstration:

The led only lights up when the correct combination is pressed
In this case the correct combination is yellow, red, green, blue for clarity of demonstration.

Week 8 Reading Response

Her Code Took Us to the Moon

Reading about Margaret Hamilton’s work on the Apollo mission taught me a lot about how careful and exact programming needed to be. The mission depended on software, so even a small mistake could lead to failure. This reading reminds me that when working on physical programming projects, I need to pay close attention to every detail. As we move into the hands-on part of the course, I’ll focus on testing my projects carefully, just like the Apollo team used simulations to catch problems early and make sure everything worked as it should.

Norman’s “Emotion & Design: Why Good Looks Matter”

In Norman’s reading, I found it interesting how he connects emotions and looks with how well things work. He says that when something is nice to look at, it makes people feel good, and that makes it easier to use. This idea makes me want to design things that aren’t just useful but also make people curious and excited to try them. Moving forward, I’ll try to add features that make people want to explore, while keeping things simple to use. Norman’s ideas showed me that good looks can improve the whole experience, helping people enjoy and connect with what they’re using.

 

Week 8: Reading Reflection of McMillian’s “Her Code Got Humans on the Moon…”

Hi there! 👋

Today, I also wanna reflect on McMillan’s article, “Her Code Got Humans on the Moon — And Invented Software Itself” (on WIRED), which was an interesting article, talking primarily about the history and nature of Margaret Hamilton’s work with NASA on the Apollo missions.

However, one thing I didn’t really like about the article was that it hypes her up a lot, often unjustly and by greatly exaggerating. Make no mistake, I’m not going after her. The work she did was invaluable, and the fact that she worked in a time when women often didn’t get these roles is noteworthy, and I applaud her for that. It’s the article I have an issue with.

For example, the title literally says “Her Code … And Invented Software Itself”, which to anyone familiar with the history of computing would know, is a huge stretch, to say the least. Ada Lovelace is widely believed to have written the very first computer program (software), and hence is the first computer programmer (though some believe Charles Babbage should have this title, as he had some writings written earlier that could be considered programs). So anyways, the title rests between them, not Hamilton, who came over a hundred years later (no knock on her, it’s simply the facts).

Ok, you might be thinking “So what, a news outlet used a clickbaity and incorrect headline, what’s new?” However, it also mentions “Software engineering, a concept Hamilton pioneered” in the article itself, which is also a bit of a stretch, as neither was she the first, nor did she invent the term, which was already in use by her time (although for some credit, maybe not very widely).

Also, while I get that the article focuses on her, it makes it seem like she was single-handedly responsible for saving the mission and some other important aspects, which leaves out the huge collaborative effort and teamwork that went into those missions, as well as a space to call out the other brilliant experts who worked on it as well.

In the end, the article offers an engaging look at Margaret Hamilton’s vital contributions to the Apollo missions (with some feel-good vibes), and while it definitely might’ve overstated her accomplishments, she is highly accomplished regardless, and her, along with the rest of the entire team’s achievements, are something we can all be inspired by and appreciate.

Week 8 Assignment

Ultrasonic Distance-Based LED Switch

Concept: This project uses an HC-SR04 ultrasonic sensor and an Arduino to activate an LED when an object is within 10 cm. This distance-based switch can serve as a touchless light control.

Materials
– Arduino Uno
– HC-SR04 Ultrasonic Sensor
– LED
– 220Ω Resistor
– Breadboard and Jumper Wires

Process:
1. Setup: The ultrasonic sensor’s Trig and Echo pins connect to Digital Pins 12 and 13 on the Arduino, while the LED is connected to Digital Pin 2 with a resistor.
2. Code: The Arduino reads the distance from the sensor. If within 10 cm, it lights the LED; otherwise, it turns off.
3. Testing: The LED successfully turns on when an object is close, providing feedback on proximity.

CODE: 

const int echo = 13;     // Echo pin of the ultrasonic sensor
const int trig = 12;     // Trigger pin of the ultrasonic sensor
int LED = 2;             // LED pin

int duration = 0;        // Variable to store pulse duration
int distance = 0;        // Variable to store calculated distance

void setup() {
  pinMode(trig, OUTPUT);    // Set trig pin as output
  pinMode(echo, INPUT);     // Set echo pin as input
  pinMode(LED, OUTPUT);     // Set LED pin as output
  Serial.begin(9600);       // Initialize serial monitor for debugging
}

void loop() {
  // Send out a 10 microsecond pulse on the trig pin
  digitalWrite(trig, LOW);
  delayMicroseconds(2);
  digitalWrite(trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(trig, LOW);

  // Read the echo pin and calculate distance
  duration = pulseIn(echo, HIGH);
  distance = (duration / 2) / 29.1;  // Convert duration to distance in cm

  // Turn on the LED if the distance is less than 10 cm
  if (distance < 10 && distance > 0) {  // Check distance within range
    digitalWrite(LED, HIGH);  // Turn on LED
  } else {
    digitalWrite(LED, LOW);   // Turn off LED
  }

  // Print distance to the serial monitor for debugging
  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm");

  delay(500);  // Delay for stability
}

VIDEO DEMONSTRATION

 


 

Reflection: This project demonstrates basic sensor integration and is adaptable for touchless applications in home automation.

Week 8: Reading Reflection of Norman’s “Emotion & Design: Attractive things work better”

Hey there! 👋

Today, I wanna reflect upon Noman’s essay, “Emotion & Design: Attractive things work better”.

It was a pretty nice and interesting read, that spoke about how design, behaviour, and (a new term for me,) affect, interact. I feel like it takes pieces which we individually can easily accept as true, and ties them together to create more interesting ideas. Overall, he says that how an object is perceived is also dependent on the emotion of the user, as well as the beauty/design (obviously including its workings, but not sorely dependent on it). For example, happy, relaxed users interacting with a beautifully designed product are much more likely to forgiving and overlook some of the faults and issues, compared to focused users in stressful situtations. He ends the main text with title text “Attractive things work better” (an arguably controversial but true statement).

However, while reading this, I couldn’t help but think of some of my previous research (for a different course), where a similar thing could be said for people. Now obviously, this is much more controversial and offensive, but bare with me, research has shown that the “Pretty Privilege” or “Attractiveness Advantage”, where people who are more conventionally attractive have a noticeable advantage in many aspects of life, is unfortunately, very real.

For example, people are slightly more forgiving to those conventionally attractive, not too dissimilar to how people were more forgiving of issues in beautifully designed objects. Also, the halo effect (where a someone associates other positive traits after seeing just a few / one) comes into play too, and since one of the first thing people see when they meet someone, is how they look, that often ends up being the basis (or initial positive trait) for the halo effect, and so those people are usually also considered smart, trustworthy, and kind (among other things).

However, the opposite is also true, and something people who are more conventionally attractive are also considered to be rude, snobbish, arrogant, and undeserving of their success (sometimes for good reason, but not always, and certainly not everyone). Similarly (going back to objects), I think that people also hold more beautiful products to higher standards, and although they might end up being more forgiving sometimes, they could also easily become upset due to expecting it to support their desired functionality (and quite well too), as simply the appearance of a better looking product often leads people to believe it is also better made.

In conclusion, I found this essay to be an insightful reading about how design, affect, and behaviour interact, and how the experience of someone using a product could differ not only on how it works, and not also only about its design, but also the emotional and mental state the user is in, and how the design needs to take that into account. I then compared and contrasted this with how people interact with others (specifically those considered more conventionally attractive), and while drawing similarities between people and objects may seem inhumane, I think it could help us further understand and research these effects, as there’s now another situation that exhibits the same properties, allowing us to look at this problem from another angle.

Week 8: Creative Switch – Course

# Jump To:


# Introduction & Conception

Hey everyone, welcome back from your break! 👋
(I know, I know, I wish it was longer too… but hope you had a relaxing and wonderful break!)

This week’s practical assignment was to create a creative/unusual switch. I immediately got a few ideas in my head, but the one I ended up going with, was a “looking at” detector! (or rather, a very crude head rotation detector 😅). I wanted to activate something something just by looking at / facing it.

So I built a simple circuit with 3 LEDs, that could indicate the rotation of my head (where I was facing). I now remember that initially, I also wanted to extend this concept by having a multiple screen setup, and then automatically closing or blacking out the screens I wasn’t facing towards, saving energy. I also had one where it would automatically dispense food or something when I turned my head, building the ultimate “automated-eating-while-working-solution” (which would probably result in a montage of hilarious fails too) 😂. However, I somehow totally forgot about these, and only remembered while writing this blog post right now (and it’s too late to implement them now, probably for the better 😅). But argh man, those would have made for a much more interesting blog :/… oh well.

 

# Implementation

I first started by connecting 3 LEDs on a breadboard, to 3 resistors which connect to the Arduino’s 3.3V. Then I realised that I could use just 1 resistor, and so wired 3.3V to the resistor, and the resistor to the positive rail of the breadboard. Then I had a wire for each LED’s cathode (the shorter pin, the one that connects to ground), and could now activate any individual LED by connecting the Arduino’s ground wire to the LED’s ground wire! All that was left now was the simply connect ground to a hat (with some tape and foil) and a flag sticking out, and have a foil flag/square for each LED, and success!

 

This circuit is so simple in fact, that it doesn’t even need the Arduino! Literally the only thing the Arduino is doing here is providing power, which can easily be replaced with a battery. However, when I looked at the requirements again, it says we have to use digitalRead :/… Ah man, ok I’ll need to integrate it.

At first I really wanted to keep the simplicity as much as I could, and basically just try the Arduino pins as ground, so there would be almost no difference in the circuit, but we could detect which LED is being lit up. Unfortunately, I read that this is quite a bad idea as the Arduino isn’t well suited for that, so I had to double the number of wires, to separate the switch part from the lighting part. The circuit now still works in a very similar way, it’s just that when I try now connect 2 wires (meaning my head has turned to a certain position), the Arduino detects the switch is activated, and then powers the corresponding LED. Same functionality, but with including the Arduino and its digitalRead and digitalWrite functions. Oh also, I used “INPUT_PULLUP” instead of “INPUT” for the pinMode, as I didn’t want to add another 3 resistors 😅 (so the readings are flipped (as there’s no “INPUT_PULLDOWN” on most of the Arduino boards), 1 for inactive and 0 for active, but this isn’t an issue).

Code:
 

const int rightLED = 10;
const int centerLED = 11;
const int leftLED = 12;

const int rightSwitch = A0;
const int centerSwitch = A1;
const int leftSwitch = A2;

void setup() {
  // Initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  
  // Inputs (set to INPUT_PULLUP instead of INPUT so that it automatically pulls up the value, saving me from adding 3 resistors 😅)
  pinMode(rightSwitch, INPUT_PULLUP);
  pinMode(centerSwitch, INPUT_PULLUP);
  pinMode(leftSwitch, INPUT_PULLUP);

  // Outputs
  pinMode(rightLED, OUTPUT);
  pinMode(centerLED, OUTPUT);
  pinMode(leftLED, OUTPUT);
}

void loop() {
  // Read the input pins
  int rightState = digitalRead(rightSwitch);
  int centerState = digitalRead(centerSwitch);
  int leftState = digitalRead(leftSwitch);

  // Power the correct LED
  digitalWrite(rightLED, rightState == 0 ? HIGH : LOW)
  digitalWrite(centerLED, centerState == 0 ? HIGH : LOW)
  digitalWrite(leftLED, leftState == 0 ? HIGH : LOW)


  // Print out the states
  Serial.print(rightState);
  Serial.print(',');
  Serial.print(centerState);
  Serial.print(',');
  Serial.println(leftState);

  delay(1);  // Short delay between reads for stability
}

 

 

# Final Result

 

 

# Additional Thoughts & Room for Improvement

I initially wanted to use a potentiometer, to be able to get a much greater resolution and more accurately determine where the head was facing (and hence, have more fine grained control over what activates), while also eliminating a few wires and the need to have the foil flags. While I opted out of that idea as this assignments requires we use digitalRead, it would be a great improvement.

Well, unfortunately that’s it for today (yea, this was a very short blog), so until next time!

Week 8 – Reading

Attractive things work better

I found this reading particularly intriguing because it introduced a concept I hadn’t considered before: the significance of “mindspace” in our interactions with objects. As the text points out, when users are in a relaxed state, they are more likely to successfully complete tasks, such as unlocking a door.

Additionally, the reading thoughtfully explores the idea that an object’s beauty extends beyond mere aesthetics; its functionality plays a crucial role as well. This connection between emotion and design is fascinating—attractive objects not only draw us in but also enhance our overall experience and effectiveness in using them.

Week 8 Assignment: Head Switch

Concept:

 

Final results for you convenience: https://youtu.be/6M-4nbYk2Is

 

Initially, the idea of using a switch that didn’t require hands felt challenging to execute. However, after some contemplation, the thought process shifted: if not manually, perhaps turning on the switch wirelessly would be ideal. My initial idea was to see if I could use my laptop to turn on the light with a clap. This, however, didn’t work for two main reasons: 1) it still required using my hands, and 2) the claps were too soft, as sound is typically best detected in a controlled setting. I then considered if I could control the light by turning my head left or right. Once this idea settled, the execution began.

Design and Execution:

The following schematic represents the electrical connection for the Arduino Uno board:

Schematic image painfully made using photoshop.

The final connection represented by the image above can be found from the image below:

Connection Image for the head switch LED control

Finally, the magic that brought everything together was not only the Arduino code but also a Python script, with a bit of help from everyone’s favorite chatbot. The following code was used in the Arduino IDE:

const int ledPin = 13;  // Pin connected to the LED

void setup() {
  Serial.begin(9600);       // Initialize serial communication
  pinMode(ledPin, OUTPUT);  // Set the LED pin as output
}

void loop() {
  if (Serial.available() > 0) {  // Check if data is available on the serial port
    char command = Serial.read();  // Read the incoming byte

    if (command == '1') {
      digitalWrite(ledPin, HIGH);  // Turn LED on
    } else if (command == '0') {
      digitalWrite(ledPin, LOW);   // Turn LED off
    }
  }
}

I then ran the Python code in my terminal, which activated the camera. Head tracking began, and from that point, turning my head to the left switched the light on, while turning it to the right switched it off. The following portion of the code made this possible:

while True:
       # Capture a frame from the camera
       ret, frame = cap.read()
       if not ret:
           break

       # Convert frame to RGB
       rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

       # Process the frame with Mediapipe
       results = face_mesh.process(rgb_frame)

       # If a face is detected, analyze head direction
       if results.multi_face_landmarks:
           landmarks = results.multi_face_landmarks[0].landmark
           direction = calculate_turn_direction(landmarks)

           if direction < LEFT_THRESHOLD and not led_on:
               print("Head turned left - Turning LED on")
               arduino.write(b'1')  # Send signal to Arduino to turn LED on
               led_on = True

           elif direction > RIGHT_THRESHOLD and led_on:
               print("Head turned right - Turning LED off")
               arduino.write(b'0')  # Send signal to Arduino to turn LED off
               led_on = False

       # Display the frame (optional)
       cv2.imshow("Head Movement Detection", frame)
       if cv2.waitKey(1) & 0xFF == ord('q'):
           break

 

Final Project:

Have a look at how the final project turned out in this short YouTube video:

https://youtu.be/6M-4nbYk2Is

Here is a progress of what happens when the user turns their head left and right:

Progress of head turns
Final Thoughts & Reflection:

This homework exercise was both fun and enjoyable. It pushed me to learn Arduino while thinking creatively about solving problems. Throughout the project, I kept considering how it might be integrated into my final project. So, instead of making this exercise long and complex, I approached it as a potential feature for the final project. That’s where I envision improvements and a broader application of this single project. That’s all for now!

Assignment Week 08: Unusual Switch ft Aloevera

Concept:
The idea for creating an unusual switch with my arm actually struck me while I was at the gym. As I was practicing with dumbbells, I thought, “Why not use the motion of my arm to activate a switch?” When I was doing bicep curls — you know, the exercise where you pull the dumbbells up toward your shoulders, maybe called as bicep curls— it clicked. I needed some conductors that could connect the wires and pass electricity when my arm moved upward. I initially thought of using aluminum foil, but that felt too common. I wanted to do something different, so I decided to go with aloe vera gel instead. It seemed like a more unique choice, and I was curious to see how well it would conduct electricity.

Hardware Used:

  • Arduino
  • LED
  • 330 ohm resistor
  • Jumper wires
  • Breadboard
  • Aloe vera gel (as a conductor)
  • Aluminum foil (optional, used for wrapping, but didn’t use)
  • Glue to attach the aloe vera slices with a decorative plant that can be wrapped around my arm

Process:

  1. Prepare the Aloe Vera Gel: I first applied some aloe vera gel to the inside of my elbow, creating a path for electricity when my arm bends during the bicep curl motion. This would serve as a conductor, allowing the current to flow when I made contact. But, it did not work. So, I used this decorative plant to wrap my arm and put the aloe vera slices glued on to it.
  2. Set Up the LED Circuit:
    • I placed the LED on the breadboard, with the shorter leg (cathode) on one row and the longer leg (anode) on another.
    • I connected a 330 ohm resistor to the same row as the shorter leg of the LED. The other end of the resistor was connected to one of the Arduino’s GND pins.
    • Then, I took a jumper wire and connected the row with the longer leg of the LED (anode) to digital pin 13 on the Arduino.
  3. Integrate the Aloe Vera Gel as the Switch:
    • I connected a jumper wire from the Arduino’s 5V pin to one piece of aloe vera that was in contact with my elbow.
    • Another jumper wire went from the same piece of aloe vera to pin 2 on the Arduino (set up as an input pin).
    • I then placed the second piece of aloe vera on the outer part of my elbow, completing the circuit when my arm was bent.
  4. Coding the Arduino:
    • In the code, I used digitalRead() to check if there was a connection between the two pieces of aloe vera (when the gel completed the circuit during the bicep curl).
    • If the circuit was closed, the LED would turn on. When I relaxed my arm, breaking the connection, the LED would turn off.
  5. Testing: I tried different amounts of aloe vera gel and even experimented with wrapping aluminum foil around the gel for better conductivity. Eventually, I found a sweet spot where the gel was conductive enough to switch the LED on and off based on my arm movement.

Pictures From The Process:

The circuit:
This is the circuit with aloe vera slices and decor plant  on my arm.

 

Unfortunately, the decor plant did not work properly. So, I used a black rope ( does not look good) to tie aloe vera with my arm directly. Here is the final one!

 

Video of the switch:

Reflection and Future Implementation:

  1. Need to find a way to adjust the aloe vera properly on my arm as I tried to use glue on a decor plant which did not work and gave me burning sensation  on my elbow area instead.
  2. Overall, I find it amusing to work with aloe vera and electronics. It was fun!

 

 

 

Creative Switch – Antiprocrastination Iphone Case

For this assignment, I decided to create something that would make sense rather than just something funny. Many people, especially students, are known to have trouble concentrating on their work. Thanks to our phones and social media, YouTube, Netflix, and other stuff inside, the focus span of a young person is deteriorating. The idea behind my device is specifically targeting people who lack self-discipline and cannot spend even a little time without looking at the screens of their phones – this can be adults, teenagers, or even kids. I decided to call it the Antiprocrastination iPhone Case.

Concept

The concept is simple – the tracking device, which can be attached to any surface, and the case itself.

1) You can put the tracking device on your desk if you are using it for yourself. However, for people like parents or teachers who want to use the device to not allow their children or students to look at their phones, it is recommended to put the device in the common area.

2) Put the iPhone case on. It is equipped with a special electrified silk on the backside that transfers the signal to the green LED lamp whenever it is lying on the surface of the tracking device. Thus, if you see the green light, it means that everything is good and the phone is connected to the tracking device.

3) As soon as the phone leaves the surface of the tracking device, the lamp turns off, indicating that the person is trying to use the phone.

Refer to the video below to check how it works:
P.S. don’t mind my tired voice, it’s been a pretty packed weekend haha

 

Reflection

The idea was simple to implement – I used the same logic that the professor showed us during the class. What I did differently was the usage of electrified silk that would be cut into 3 pieces. 2 would lie on the table with wires connected to them and with a short distance between them, so the chain would not be closed until the third bigger piece of silk would cover both of the smaller ones from the top. I attached the bigger piece to the iPhone case, and whenever it lies on the smaller pieces, the chain gets closed, and electricity circles and flows as intended, which allows the LED light to turn on.

It is the Antiprocrastination iPhone Case 1.0 as it does not include advanced features. For example, I could add the sound effect whenever the iPhone is removed to warn a user. I could also make the vice-versa LED light effect by, for instance, putting on the red LED light and turning it on whenever the iPhone is removed from the surface.

Anyway, I enjoyed my first experience with Arduino and I am extremely excited to learn more in the upcoming classes to start building more advanced things.