Week 9: Cookie Jar

Concept:

For this week, our task was to get information from at least one analog sensor and at least one digital sensor (switch), and use this information to control at least two LEDs, one in a digital fashion and the other in an analog fashion, in some creative way.
My project is called “The Cookie Jar”, and it’s inspired by my love for chocolate chip cookies.

After recklessly spending my savings on this bucket of cookies, I decided to base my project on it. The idea was to turn a light on every time I opened the lid of this cookie bucket. To do this, I had to code the photoresistor in a way that it could take the difference between the light outside and the light inside. However, the problem relied on the fact that turning on the LED also generated light by itself, so I had to adapt the constraints of it in a way that would work properly. Also, I added a switch to turn on and off manually the other light inside, just in case someone wants to sneak a cookie in the middle of the night.

Breadboard and connections: 

Demonstration:

 

Code: 

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(5,OUTPUT);
  pinMode(9,OUTPUT);
  pinMode(2,INPUT);
  pinMode(A2,INPUT);
}

bool lightsOn = false;
void loop() {
  // put your main code here, to run repeatedly:
  int sensorValue = analogRead(A2);
  int switchValue = digitalRead(2);
  
  if(switchValue == 1){
    lightsOn = !lightsOn;
    delay(500);
  }
  digitalWrite(9,lightsOn);
// The brightness is the difference between inside and outside, but reversed (more light if the difference is low)
  int brightness = 255-(620-sensorValue);
  if(brightness<0){
    brightness = 0;
  }
  if(brightness>255){
    brightness = 255;
  }
  analogWrite(5,brightness);
  Serial.println(sensorValue);
  
}

Challenges:

The biggest challenge I faced was the shape and the fact that I had to connect the arduino UNO inside with the lid closed. I fixed this problem by reluctantly making a hole in my cookie bucket. I opened it just enough so it could fit the USB connector, which allowed me to insert the circuit inside even with the lid closed.

 

Reflections – Week 9

Making Interactive Art: Set the Stage, Then Shut Up and Listen

This piece highlights the difference in making interactive art and making art. While artists (and viewers alike) generally believe that a work of art is an expression or a statement – interactive art is much different in several aspects. The artist’s role isn’t to make a statement but rather start a conversation. The viewer will then interact with this and have an experience that ideally will communicate what you want it to.

Here Tom Igoe gives practical advice as to how to make interactive art – that ultimately boils down to setting the stage, shutting up and listening to the audience. At the start of the course, this idea would have seemed foreign to me, but through both the readings and personal experiences I have come to realize what Tom intends to say here. Additionally, I love the example of the director Tom uses here, and his overall writing style!

Lastly, I believe interactive art – as the way Tom puts it – in a way serves to liberate the artist. It suggests that as an artist, one doesn’t have to bear the entire burden of meaning or impact. Instead, by creating a framework for interaction and then stepping back, an artist can allow the artwork to breathe, grow, and morph through each interaction. At the same time, it also poses a challenge: can an artist resist the urge to dictate, to instead become a facilitator of experience?

Physical Computing’s Greatest Hits (and misses)

Here Tom Igoe provides us with several examples of the kinds of physical computing works that show up frequently. Of these, I would like to reflect on 3 ideas in particular:

I particularly liked the idea of a “meditation helper”. Beyond directly building something to help with meditation. What really interests me is the concept of reading a person’s heart rate, breathing rate, etc. These factors are easily accessible these days, and it will be very interesting to build technology infused clothing that is practical and useful.

The Scooby Doo painting art type seems overdone but something about it still remains intensely creepy. I would love to incorporate something of that manner in a project I do going forwards.

Lastly, floor pads are also exciting. I am curious as to if we can somehow engineer them in a way that lets us walk in place (like a treadmill and have that actually simulate a walk for a character in real-time etc. Moreover, there’s a lot more that can be done with such pads if we keep adding layers of complexity!

Week 9 – Pedestrian Problems

Concept

For this week’s assignment, I decided to show the common problem of pedestrians when crossing the road. My idea was to create a pedestrian crossing light, which would show the common problem of having “infinite” red light and only limited actual crossing green light. I believe this is a common problem in any country and anyone can relate to the idea of this project.

Video: Pedestrian Traffic Light

Diagram, Code, Highlights, and Challenges of the Project

To make this project, I decided to break it into three steps.

Firstly, I made a switch as a push button, which will turn on the green LED. For this, I built a circuit for the switch button, which I learned from the class material. I am proud of this step, as I could apply the previous knowledge (building the circuit of the light sensor) and understand how to do the same with the switch button. I used a 10K Ω resistor, a green push button (to indicate the same color as the LED color), a green wire that connects to pin 12, a red wire that connects to 5V, and a black wire for the GND connection. One challenge I faced was forgetting that the current could not jump from one place on the breadboard to another, so I added another red wire to finish the connection.

Moreover, I made a simple circuit for the green and red light, using green and red LEDs, 2 330Ω resistors, and yellow wires connected to pins 2 and 3. I didn’t have to use an additional black wire, as I intentionally had all of my components connected in a way that uses only 1 black wire connected to GND.

As I completed building this, I wrote a simple program that will turn on the green LED, and turn off the red LED, when the green button is pushed. Moreover, I made a code for the green LED blinking. For this part of the project, I used a digital sensor and controlled it in a digital fashion.

Lastly, I decided to add an analog sensor – a light sensor – which will control the brightness of the red LED. I had no problem building this part of the circuit, however, I had to decide whether I wanted to completely turn off the red LED or control the red LED in a fashion that is independent of the digital switch. If I decided to turn off the LED using a light sensor, I would need to think about 4 different options of its connection to the switch button: switch on & sensor value >400, switch on & sensor value <400, switch off & sensor value >400, switch off & sensor value <400. I decided that independent control of the light sensor would reflect my concept better. Therefore, I made a red LED to always have a dimmed brightness, and when the light sensor is covered the LED will become brighter.

Here, is the code for my program:

// assigning variables to the pins
// push button has a connection to pin 12
// green LED has a connection to pin 2
// red LED has a connection to pin 3

int pushButton = 12;
int greenLED = 2;
int redLED = 3;

// the setup routine
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  // make the pushbutton's pin an input
  pinMode(pushButton, INPUT);
  // make green LED and red LED pins as output
  pinMode(greenLED, OUTPUT);
  pinMode(redLED, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {

  // read the input pin of the push button:
  int buttonState = digitalRead(pushButton);
  // print out the state of the button:
  Serial.println(buttonState);
  delay(1);  // delay in between reads for stability

  // if statement for controlling the red and green LEDs through the push button (digital switch)
  // if button is pushed
  // turn off the red LED and blink the green LED with a delay in between the blinks

  if (buttonState == HIGH) {

    digitalWrite(redLED, LOW);

    digitalWrite(greenLED, HIGH);
    delay(1000);
    digitalWrite(greenLED, LOW);
    delay(1000);

    // if button is not pushed
    // green LED is always off
    // red LED is always on
    // and the red LED is controlled by the light sensor values a.k.a. the brightness
    // if the sensor value is less than or equals to 400, the brightness of the red LED is at maximum
    // if the sensor value is more than 400, the brightness of the red LED is alway dimmed at brighness of 10

  } else {
    //if the green button is not pushed,
    // the green LED is not turning on
    digitalWrite(greenLED, LOW);

    // initializing variable called sensorValue which reads the values from A2 analog pin
    int sensorValue = analogRead(A2);

    if (sensorValue <= 400) {
      analogWrite(redLED, 255);
    } else {
      analogWrite(redLED, 10);
    }
  }
}

Future Work and Reflection

Overall, I believe that I achieved all of my goals for this project. I was able to practice the knowledge I gained during class work and apply it in a new context. I am proud of the work I have done. Although I faced several challenges, which I described above, I was able to resolve them easily. For the next work, I am planning to keep up with my method of breaking the big project into smaller parts and achieving the same good results.

 

Week 9 Sensors – Christmas Tree

Concept:

For this assignment, we had to get information from an analog and a digital sensor and control 2 LEDs, one with the analog and one with the digital. Since it is almost Christmas season, I wanted to create a Christmas tree lit by a light sensor and a switch separately. I really like this time of the year because it is special in my hometown. It is all about family and friends gatherings, rainy days, meaningful conversations with delicious food, and an end-of-year celebration.

Highlight:

Reviewing the lecture notes and my notes was key in constructing this assignment. I started by drawing the tree, coloring it, and marking where I wanted the LEDs to go. I had to glue things in place because the paper was not strong enough to handle all the LEDs and wires.

I was a little scared of assembling the circuit in the wrong way and creating a shot, but it worked out well. However, I had to figure out how to deal with many things to make this project work. For instance,  I  had to figure out how to make the LED anode longer. To fix this problem, I  decided to use wires and attach them to the anode and the board instead of attaching the LEDs directly to the board. It was frustrating to attach the wires to the LEDs especially to keep them in place. To distinguish between the positive and negative anodes of the LED I used foil for one and copper tape for the other. Doing so made it less confusing to attach them to the board. I had some doubts about whether the circuit was correct or not so I re-assembled them multiple times to make sure I made it correctly. Attaching the switch and the light sensor was easier. Even though I made two codes one for the switch and the other for the light sensors, on the board they both share the same GND and the 5V.

The code is like to what we did in class. I tried to figure out how to add all Pins in one line of code but I could not figure out how,

Light Sensor:

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(2, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A4);
  if (sensorValue > 255) {
    digitalWrite(13, LOW);
    digitalWrite(11, LOW);
    digitalWrite(9, LOW);
    digitalWrite(7, LOW);
    digitalWrite(5, LOW);
    digitalWrite(3, LOW);
    digitalWrite(2, LOW);
    delay(1000);  // turn the LED off by making the voltage LOW
  }
  // wait for 30 milliseconds to see the dimming effect
  else {
    digitalWrite(13, HIGH);
    digitalWrite(11, HIGH);
    digitalWrite(9, HIGH);
    digitalWrite(7, HIGH);
    digitalWrite(5, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(2, HIGH);
  }
}

Switch :

// digital pin 2 has a pushbutton attached to it. Give it a name:
int pushButton = A2;

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  // make the pushbutton's pin an input:
  pinMode(pushButton, INPUT);
  pinMode(13, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(2, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input pin:
  int buttonState = digitalRead(pushButton);
  // print out the state of the button:
 if (buttonState==1) {
  digitalWrite(13, HIGH);
    digitalWrite(11, HIGH);
    digitalWrite(9, HIGH);
    digitalWrite(7, HIGH);
    digitalWrite(5, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(2, HIGH);
  
    // turn the LED off by making the voltage LOW
  }
  // wait for 30 milliseconds to see the dimming effect
  else {
      digitalWrite(13, LOW);
    digitalWrite(11, LOW);
    digitalWrite(9, LOW);
    digitalWrite(7, LOW);
    digitalWrite(5, LOW);
    digitalWrite(3, LOW);
    digitalWrite(2, LOW);
    
    
  }
}


 

 

Reflection and future improvements:

Trusting the process was a huge reason why this project worked. It is not complicated, but it needs a lot of focus. In the future, I want to make it more presentable and neater. I want to also find a way where both the sensors work together in the same code.

Merry Christmas!

Week 9 – Light Chameleon

Concept

For this assignment, I imagined to simulate a kind of animals using just LEDs. It took me some time to decide on which animal to imitate because the information communicated by LEDs can be very limited. Then, suddenly an idea came to my mind: a chameleon that is sensitive to light! To do this, I used a light sensor and a RGB LED as the analog input and output. The RGB LED will change color as the sensor detects different amount of light, just like chameleon changing color with its environment. Besides this, I used a button and a normal LED as the digital input and out. This simulates the situation where the chameleon is found out by its predator and got eaten. So, if the button is pressed, the red normal LED will be on and the RGB LED will become white, regardless of the light sensor.

(Due to the quality of the video, the color change might not be so obvious in the video. But it works really well in reality.)

 

IMG_0922

Highlight of the code

The code is relatively easy. It essentially uses map() to take different ranges of RBG values and pass them to the RGB LED respectively.

#define RED_PIN 3
#define GREEN_PIN 5
#define BLUE_PIN 6
#define LED_PIN 12

void setup() {
  Serial.begin(9600);
  pinMode(RED_PIN, OUTPUT);
  pinMode(GREEN_PIN, OUTPUT);
  pinMode(BLUE_PIN, OUTPUT);
  pinMode(A0, INPUT);  //light sensor input
  pinMode(2, INPUT);   //button input
  pinMode(LED_PIN, OUTPUT);
}
int value = 0;
int buttonState = 0;
int lastButtonState = 0;
int LEDState = LOW;
void loop() {
  value = analogRead(A0);
  lastButtonState = buttonState;
  buttonState = digitalRead(2);

  // the LED is on when button is pressed, and off when button is pressed again
  if (lastButtonState == 1 && buttonState == 0) {
    LEDState = !LEDState;

    digitalWrite(LED_PIN, LEDState);
  }


  if (LEDState == HIGH) { // if the red LED is on, RGB LED is always white
    setColor(255, 255, 255);
  } else { // make the range of R, G, B different from each other
    int R = map(value, 100, 1000, 0, 255);
    int G = map(value, 100, 1000, 255, 0);
    int B = map(value, 0, 1000, 0, 100);

    setColor(R, G, B);

    Serial.println(R); // for debug
  }
}

void setColor(int R, int G, int B) {
  analogWrite(RED_PIN, R);
  analogWrite(GREEN_PIN, G);
  analogWrite(BLUE_PIN, B);

Reflection and Improvement

I think the challenge of this assignment for me is to convey meaningful messages through LEDs and their own inputs, which are relatively limited. However, the use of RGB LED gives me more flexibility and makes the project a little more interesting. If I were to improve it, I would make an actual chameleon using some materials like cardboards. This might make the concept of the assignment more visually concrete.

The Nightlight and the Alarm

Approach and Concept:

It took me a long time to come up with the idea for this project given the requirements it had. But at the end of our previous lecture, I realized I could make a night-light+morning alarm system.

For my analog input I use the light sensor we employed in class. In the morning, this turns on the buzzer (digital output 1) and the red LED light( digital output 2). While it’s night (low light) the blue LED (analog output) blinks in a slow and satisfying manner. A button (digital input switch) can be used to turn the whole system off or on at any given time.

I believe this whole system, if refined further a bit has actual practical utility, and I’m really happy I could make something like this on my own!

Highlights:

I would like to highlight both the coding and the hardware work for this project:

Coding: The system uses a state management system. When I tried to use code from the examples we used in the lecture. This became complicated because doing things like making the analog output led blink slowly couldn’t be done through for loops – or the delay would mess up with the state switching mechanism. To navigate through this, I had to remove the for loops and instead work directly with the loop function. Similarly, I faced this issue again with the buzzer where the delay’s blocking nature was causing some problems – leading me to use the external ezBuzzer library. Beyond this, joining together so many components itself was a fun challenge!

void loop() {
  buzzer.loop();
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
  int analogValue = analogRead(A0);
  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH && led_state==0) {
    while(buttonState==HIGH)
    {
      buttonState = digitalRead(buttonPin);
    // turn LED on:
      led_state=1;
    }
  }
  else if(buttonState == HIGH && led_state==1)
  {
    while(buttonState ==HIGH)
    {
      buttonState = digitalRead(buttonPin);
      led_state=0;
    }
  }
  Serial.println(led_state);
  digitalWrite(ledPin,led_state && led_stateD);
  if(led_state==0 || led_stateD==0)
  {
    if (buzzer.getState() != BUZZER_IDLE) {
      buzzer.stop() ; // stop
    }
  }
  else 
  { if (buzzer.getState() == BUZZER_IDLE) {
      int length = sizeof(noteDurations) / sizeof(int);
      buzzer.playMelody(melody, noteDurations, length); // playing
    }
  }
  if (analogValue < 300) {

    led_stateD=0;
    led_stateA=1;
  }
  else {
    led_stateD=1;
    led_stateA=0;
  }
  if(led_state==1 && led_stateA){
  // fade in from min to max in increments of 5 points:
  if(millis()%10==0) {
    // sets the value (range from 0 to 255):
    fadeValue+=increment;
    analogWrite(ledPinAnalog, fadeValue);
    if (fadeValue==255 || fadeValue==0)
      increment*=-1;
  }}
  if(led_state==0 ||led_stateA==0)
    analogWrite(ledPinAnalog, 0);

}

 

Hardware: The connections itself were simple enough in themselves – since I had knowledge of what we had done in class to borrow from. However, given the many elements the board itself got messy – making navigation a hassle.

Reflections and Future Work:

There are several improvements I would like to make on this work. On the technical implementation aspect, I can possible manage the wires I use much better than I have done here. And on the coding aspect, the code can definitely be made more streamlined and easier to read.

In terms of future work, I would like to add more lights to the nightlight aspect, and make the blinking pattern more complex to have a more soothing experience. Similarly, the buzzer noise and the morning alarms can also be improved aesthetically. In terms of functionality, it would be nice to have another button than can function as a snooze button.

 

 

Week 9 | Analog + Digital input & output: “Mario’s Magic Light-Up Mushroom” Assignment

Mario’s Magic Light-Up Mushroom:

The inspiration for my project struck me when I found myself without my Nintendo Switch, unable to play one of my all-time favorite games since childhood, ‘Mario Party.’ This game is filled with quirky and fun elements like the lucky block and the magical mushroom, both of which can greatly influence your journey in the game.

So, I decided to base my project on the game. It’s not only a personal passion but also a nostalgic trip down memory lane. I believe it’s a creative concept that encapsulates the magic of ‘Mario Party,’ and I had the input of my friends to help shape the idea.

 

 

 

 

 

 

 

 

IMG_5210_DEMOSTRATION VIDEO

Structure

The structure of my project revolves around the use of buttons and sensors from the SparkFun kit, which I gained an understanding of during one of our classes.

The materials I used are a printed out image of the iconic mushroom and lucky block from the game. These images were carefully mounted on cardboard for durability, and I affixed them with tape on the to ensure they could withstand the project.

The red is controlled by the sensor, The yellow is controlled by the button

The code provided in class examples played a crucial role in helping me bring this assignment to life. It served as a valuable starting point and a foundation for what I aimed to achieve. With the help of this code, I’m confident that the project will capture the fun and nostalgia of ‘Mario Party’ while showcasing my newfound skills in working with hardware and sensors.

Reflection

I must admit that the journey of building the Arduino circuit and working with the breadboard was a bit challenging, but it was also immensely rewarding. I spent a considerable amount of time understanding the components, making connections, and ensuring everything functioned as intended. While it tested my patience at times, it also provided me with invaluable insights into electronics and hardware, which I know will be useful in the future.

Assignment 9 – “Don’t steal my Arduino UNO Part 2”

Concept

For this assignment, I decided to advance my first assignment by using an analog sensor (ultrasonic range finder) to calculate the distance to the object, indicating if it has been moved too far from the sensor.

Technical structure

For the digital switch, I used the one from the last assignment, where the conductive fabric was used to complete the circuit when an object touched the wires. When it happens, the blue LED lights up.

  .  

As I mentioned earlier, for the analog switch, I decided to use the ultrasonic range finder. It turned out that working with this sensor is quite easy; however, while I was testing the sensor, I found that sometimes the waves go through the object (e.g., hands), and the sensor detects dramatic changes in distance, which makes it slightly inaccurate.

The program is constantly checking the distance to the object, and when the distance detected is more than 10 cm, the red LED starts fading.

Code

void loop() {

  digitalWrite(trigPin, LOW);
    delayMicroseconds(2);

    digitalWrite(trigPin, HIGH);  
    delayMicroseconds(10);  

    digitalWrite(trigPin, LOW); 
  duration = pulseIn(echoPin, HIGH);
  distance = (duration*.0343)/2;

  if (distance >= 10){
    analogWrite(led, brightness); // set the brightness of pin 11:
    brightness = brightness + fadeAmount; // change the brightness for next time through the loop:

    // reverse the direction of the fading at the ends of the fade:
    if (brightness <= 0 || brightness >= 255) { 
      fadeAmount = -fadeAmount;
    }

    // wait for 3 milliseconds to see the dimming effect
    delay(3);
  } else {
    analogWrite(led, 0); // turn off the light if the object is within 10 cm distance
  }

  Serial.print("Distance: ");  
    Serial.println(distance);  

    delay(10);
}

In this part of the code, the loop function for the project is described. The first part controls the functionality of the switch, and starting with the if function, the red LED is being controlled. In line 11, the duration is multiplied by 0.343 because the speed of sound in centimeters per microsecond is .0343 c/μS. Then it’s being divided by two because the sound waves travel to the object and back.

Demonstration

Link to the video: Assignment demonstration

Reflection

While working on the assignment, I realized that making a theft detection device is not as simple as it seems to be. The device I created can be easily bypassed by placing another object in front of the sensor. But if the person is not aware of how the system functions, the device can be used successfully. I enjoyed working with a new sensor, and I hope to expand my knowledge of Arduino more.

Sources used:

“Getting Started with the HC-SR04 Ultrasonic sensor”

https://projecthub.arduino.cc/Isaac100/getting-started-with-the-hc-sr04-ultrasonic-sensor-7cabe1

Week 9 – Reading Reflection

Making Interactive Art: Set the Stage, Then Shut Up and Listen

In this blog post, Tom Igoe talks about shifting the focus on what interactive art should be: instead of a complete piece, a finished artwork, we should approach it as if they were “performances”. His ideas, in my opinion, provide a valuable lesson on the final objective of interactive pieces. Every person might have their own vision and goals for their projects and art pieces, but at least for me, ultimately what I would like to achieve is to create something that people can see and be satisfied with their experience. I do not want to have to be present, or to have to talk to people explaining what they have to do in order to have the experience. In my opinion, that is the essence of interactivity and one of the key components of good design: the user should start, process and finish the experience by themselves.

Physical Computing’s Greatest Hits (and misses)

In this article, Tom Igoe discusses recurring themes in physical computing projects, highlighting popular ideas and their variations. In my opinion, I think that from this article, the author encourages creativity within these themes (physical computing recurring themes), emphasizing that even though certain ideas have been done before, there is room for originality and variation. And I personally want to emphasize this last part. “I don’t want do to that, it’s already done”, this quote resonated especially hard in my head. The reason behind this dates back to my highschool, where during a rough patch in my software development learning process, I struggled to think about projects that could be usable but would also help me learn. In my head, I was constantly repeating these exact words that the author included: “it has been done before, why care?”.

This mindset was what stopped me from improving as a creator and as a programmer. The principal of my highschool came up to me one day, and he clearly told me one example: “I do not want you to invent the wheel, and I do not want you to invent the suitcase. I want you to explore, and maybe you will end up creating the travel luggage”.

This article helped me remember those learnings, and I think the moral of the story is also one of the pillars of creativity: be able to push away your ego and work with things that are created, work on stuff that has been invented and do not shy away from these opportunities, because Rome was not built in one day, and definitely not from scratch.

Week 9 – Digital and Analog Input/Output

Cutie Cat

Cat video

Concept:
Ever since coming to the Abu Dhabi campus with its abundance of cats, I have noticed that some of them close their eyes in a very cute manner when you pet them, so I wanted to simulate this adorable interaction.

As I did not have the resources or knowledge to make an eye-closing movement, I decided to have the cat’s nose become brighter when you pet it. The photoresistor was perfect for this, because during our in class exercise, I noticed that, as move your hand closer to it, the value drops in a predictable manner. Thus, I wrote some code that made the LED increase in brightness when you move your hand closer to the cats head. Since we needed to have a digital input/output as well, I made a blue gemstone for my cat’s collar that is activated by pressing the blue button.

Highlight:
I am quite happy with how this project turned out, especially the cardboard portion. The tool training enabled me to use the Exacto knife, and by cutting out the cat’s nose and putting a few layers of tape over the back of the hole, I was able to conceal the LED while still allowing it to emit a glow. I was also able to create reliable electrical connections (better than the ones for my candle last time) by using a foil + tape technique, where I placed two bits of foil separated by a gap on a piece of tape and used it to secure the wire ends to the cardboard.

Challenges:
I wanted the light to become incrementally brighter as I moved my hand closer to the cat, so I set three brightness values for when sensorValue is above 700, between 400 and 700, and below 400. However, there is an unsolved bug in which this incrementation does not actually reflect the LED’s brightness. The LED only increments between two levels. When sensorValue is below 400, the LED is still the same brightness as for when sensorValue is between 400 – 700.

analogWrite(yellowLED, brightness);  // set the brightness of yellow LED

  if (sensorValue < 400) {
    brightness = 255;
    delay(1);  // incrementation of brightness not working
  }

  if (400 < sensorValue < 700) {
    brightness = 100;
    delay(1);
  }

  if (sensorValue > 700) {
    brightness = 25;
    delay(1);
  }

Reflection and improvement:
If I were to do this homework again, I would like to successfully implement the incrementation above, and maybe program even more segments so that the brightness of the nose increases smoothly as you move your hand towards the cat, as if it is delighted to see you. I think there may be some way to do this using the fade example, but I could not figure out how, as of now.

Update:

After talking to my classmate, I now know how to program the LED to make it smoothly fade brighter as your hand moves closer:

// set the brightness of yellow LED
  analogWrite(yellowLED, brightness);  

  // set brightness equal to max sensorValue minus the currently received sensorValues
  // the less the sensorValue (the closer your hand is), the higher the brightness
  brightness = 870 - sensorValue; 
  Serial.println(brightness);