Week 9 Assignment : Color Dial

Concept: After seeing what my peers had already done with the assignment guidelines, I wanted to try something different that I hadn’t seen before. Initially, I had the idea of using a color-changing crossroads with an ultrasonic proximity sensor. However, since someone had already done that, I attempted to replicate it using a potentiometer instead. The prototype includes a button that turns on an LED light, and the potentiometer determines the color.

Prototype: During the prototyping phase, I tried to find the most efficient way to minimize the amount of wiring for the three LEDs I wanted. However, I realized that in order to have different LEDs light up for different scenarios, I needed to create separate digital output circuits.

To visualize this, I mapped out the design on TinkerCad, as shown in the following image:

After completing the circuit, I proceeded to the coding part. It took me some trial and error to create a nested loop that worked with the button and potentiometer setup I desired. Since the potentiometer values range from 0 to 1023, I implemented if-else statements for the Red, Yellow, and Green colors based on approximate ranges of 0-300, 300-700, and 700-1000, respectively.

The following is the code:

int buttonState = 0;  // variable for reading the pushbutton status


// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  pinMode(10, OUTPUT); //Green
  pinMode(11, OUTPUT); //Yellow
  pinMode(12, OUTPUT); //Red
  pinMode(3, INPUT_PULLUP); //Button
}

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

  buttonState = digitalRead(3);


  int sensorValue = analogRead(A2);
  Serial.println(sensorValue);

if (buttonState == LOW) {
  if (sensorValue < 300) {
    digitalWrite(12, HIGH);
    digitalWrite(11, LOW);
    digitalWrite(10, LOW);

  } else if (sensorValue < 700) {
    digitalWrite(12, LOW);
    digitalWrite(11, HIGH);
    digitalWrite(10, LOW);

  } else if (sensorValue < 1023){
    digitalWrite(12, LOW);
    digitalWrite(11, LOW);
    digitalWrite(10, HIGH);
  }
} else if (buttonState == HIGH) {
   digitalWrite(12, LOW);
    digitalWrite(11, LOW);
    digitalWrite(10, LOW);
}

  delay(30);  // delay in between reads for stability
}

 

week 9 – Assignment

Ready.. Set.. Go..

Concept:

“Ready Set Go” is a project that lets you control 4 LEDs with just one button. you press the button, and the LEDs light up one after the other like a countdown – it’s like creating your own mini light show!

IMG_1096

Challenges:

The most challenging part of the code is likely the button debouncing mechanism. Even when I’ve pressed the button once the LEDs would rapidly change without a bounce or delay

if (digitalRead(5) == HIGH) {
  newcount = count + 1;
  if (newcount != count) {
    // ... (LED control logic)
    count = newcount;
  }
}

Then I had to find the perfect timing. The delay between consecutive state checks (delay(100)) provides a basic form of debouncing. However, finding the right delay duration was a bit hard because too short, it wouldn’t effectively debounce, and if it was too long, it just felt unresponsive.

 

Areas for Improvement:

For future projects, I’d wish to maybe design the code and circuit in a way that makes it easy to add more LEDs or buttons or add one more idea to which pressing the button a certain number of times can show like a mini light show.

 

Week 9: Parking sensor

THE Parking sensor

For this project, we had only two sensor options: the LDR or the ultrasonic sensor. Since we’d already used the LDR before, I wanted to try out something new. So, I looked into the ultrasonic sensor and started working with it. While brainstorming, I came up with various game ideas that used the sensor, but they needed a screen, which wasn’t allowed for this assignment. After more research on ultrasonic sensors, I found they could work well as a car parking alarm to help drivers avoid hitting obstacles. I started writing the code and set up a variable called “time_delay” to control how fast the LED blinks. To make it more like a real parking sensor, I decided to add a buzzing sound and found out how to connect a buzzer to the setup. With these changes, I made a working parking sensor. To meet the assignment’s requirements for a switch and a second LED, I made a switch that, when pressed, turns on a bulb that matches its color.

THE CODE:

const int trigPin = 9;
const int echoPin = 10;

int led = 5;

long duration;
int distance;

const int buzzer = 13;

const int buttonPin = 2;  // the number of the pushbutton pin
const int ledPin = 8; // the second light

int buttonState = 0; // button bool

void setup() {
  // put your setup code here, to run once:
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  
  pinMode(led, OUTPUT); //light
  pinMode(buzzer, OUTPUT); // buzzer

 
  pinMode(ledPin, OUTPUT); // initialize the LED pin as an output
  pinMode(buttonPin, INPUT);  // initialize the pushbutton pin as an input
  

  Serial.begin(9600);


}

void loop() {
  //sending the audio pulses
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
//calculating distance
  duration = pulseIn(echoPin, HIGH);
  distance= duration*0.034/2;

//the warning rate
  float time_delay= (distance *3) +30;

  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
  } else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }

  if(distance < 50)
  {
    //the warning / buzzing rate
    digitalWrite(buzzer, HIGH);
    analogWrite(led,0);
    delay(time_delay);
    digitalWrite(buzzer,LOW);
    analogWrite(led,255);

  }
  
  else{
    digitalWrite(led, LOW);
    noTone(buzzer);
  }

  //for feedback
  Serial.print("Distance: ");
  Serial.println(distance);


}

 

This is how it looked like

Video:

 

WEEK 9 RED LIGHT GREEN LIGHT

 

IMG_3777

Concept:

For this project, I wanted to re-create a stop light or intersection, where a “car” could be driving when the light is green and a pedestrian could press a button to turn the traffic light red, so that they could walk and cars could not drive forward. I really liked this concept, because it reminded of all the times I would be walking by an intersection and would attempt to press the button to turn the traffic light red and it would never work.  With this model, the light actually turn red to let the pedestrians cross.

FUN FACT: I made the car a Tesla, because I really like teslas.  (:

// Set pin names
// to keep track of what is connected to which pin, we set global variables that name each pin
// this also allows us to use these names in functions like "pinMode" & "digitalWrite" instead of the pin numbers. 
const int switch_Pin = 2;
const int lightSensor_Pin = A0;
const int LED_green = 13;
const int LED_red = 12;
void setup() {

  //Start the serial monitor
 Serial.begin(9600);
 //Set pin modes
 // The LED pins are OUTPUT pins because we are sending information to the LED instead of receiving information from it
 // the information we are sending is in the form of HIGH or LOW
 // this is an alternative to connecting the LED lights straight to the 5V pin, which constantly outputs 5 volts
 // with these pins being used as OUTPUTs we can control wether the LED is recieving power or not.
 pinMode(LED_green, OUTPUT);
 pinMode(LED_red, OUTPUT);

 // The switch pin is an INPUT pin because we are taking in information from the switch about whether it is ON or OFF.
 pinMode(switch_Pin,INPUT);
}

void loop() {
  // Set variables for the input from the light sensor & the switch
  
  // for the lightValue variable, we want it to be equal to the value coming from the light sensor
  // the data coming form the sensor is analog data so we use the "analogRead()" function and we give it the pin it's supposed to read from
  // here we give it the pin connected to the light sensor (A0)

   int lightValue = analogRead(lightSensor_Pin);

  // for the switchState variable, we want it to be equal to the value coming from the switch
  // the data coming form the switch is digital (either HIGH or LOW) so we use the "digitalRead()" function and we give it the pin it's supposed to read from
  // here we give it the pin connected to the switch (2)

   int switchState = digitalRead(switch_Pin);

   // Prints values from sensor in serial monitor
   // we use the "Serial.print()" function to send information serial monitor (open using bottom on top right) so that we can read it
   Serial.print("Analog reading: ");
   Serial.print(lightValue);
   // "\n" is a line break, makes the serial monitor start on a new line
   Serial.print("\n");

// If statement to check if there is something blocking the light from the light sensor & control the green LED accordingly
// if the value coming form the light sensor is less than 700,
   if (lightValue < 800) {
    // we use the "digitalWrite()" to send data to the green LED, in this case we send "HIGH" so that it turns on
    digitalWrite(LED_green,HIGH);
    // else ; if the light value is not less than 700
   } else {
    // we send a "LOW to the green LED so that it turns off"
    digitalWrite(LED_green,LOW);
   }
  
  // If statement to check if the switch is ON or OFF & controls the red LED light accordingly 
  if (switchState == HIGH){
    digitalWrite(LED_red,HIGH);
    digitalWrite(LED_green,LOW);
  } else if (switchState == LOW){
    digitalWrite(LED_red,LOW);
  }
  

}

 

 

 

 

 

 

 

Week 9- Sunset Effect

Concept:

The concept involves creating an Arduino-based project that combines analog and digital sensors to control two LEDs in a creative way.  The goal is to simulate a sunset effect using the LDR to detect ambient light levels. The system uses the button to sequentially turn on two LEDs and the potentiometer to adjust the brightness, providing a visually appealing sunset simulation.

Sunset Simulation Sequence:

    1. Initialization:
      • Upon activation, both yellow and red LEDs light up simultaneously, representing the starting point of the sunset effect.
    2. First Button Press:
      • When the button is pressed for the first time, the yellow LED dims or turns off, symbolizing the initial phase of the sunset where daylight begins to fade.
    3. Second Button Press:
      • Upon another press of the button, the red LED dims or turns off, indicating the advanced stage of the sunset where the sky adopts warmer hues.
    4. Potentiometer Control:
      • Throughout the simulation, the potentiometer allows users to adjust the overall brightness, offering a real-time customization of the sunset effect.

https://youtu.be/DqOrlSnHzus

Code: 

const int buttonPin = 2;     // Pin number for the push button (connected to ground with pull-up resistor)
const int led1Pin = 3;       // Pin number for the first LED
const int led2Pin = 5;       // Pin number for the second LED
const int potPin = A0;       // Pin number for the potentiometer

int buttonState = HIGH;      // Variable to store the current state of the button
int lastButtonState = HIGH;  // Variable to store the previous state of the button
int led1State = LOW;         // Variable to store the state of the first LED
int led2State = LOW;         // Variable to store the state of the second LED
int potValue = 0;            // Variable to store the potentiometer value
int brightness = 0;          // Variable to store the LED brightness
int flag = 0;

void setup() {
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(led1Pin, OUTPUT);
  pinMode(led2Pin, OUTPUT);
}

void loop() {
  buttonState = digitalRead(buttonPin);

  // Check if the button is pressed (LOW) and was not pressed before
  if (buttonState == LOW && lastButtonState == HIGH) {
    // Toggle the state of the first LED
    led1State = !led1State;
    digitalWrite(led1Pin, led1State);

    // If the first LED is turned on, wait for the second button press to turn on the second LED
    if (led1State == HIGH) {
      delay(50); // Debounce delay
      buttonState = digitalRead(buttonPin);
      if (buttonState == LOW) {
        // Toggle the state of the second LED
        led2State = !led2State;
        digitalWrite(led2Pin, led2State);
        flag = 1;
      }
    }
  }

  if (flag == 1) {
    // Read the potentiometer value and map it to the LED brightness range (0-255)
    potValue = analogRead(potPin);
    brightness = map(potValue, 0, 1023, 0, 255);

    // Apply the brightness to both LEDs
    analogWrite(led1Pin, led1State ? brightness : 0);
    analogWrite(led2Pin, led2State ? brightness : 0);
  }

  // Save the current button state for the next iteration
  lastButtonState = buttonState;
}

 

Improvements:

For future upgrades, I want to make the lights in my project more interesting by creating complex patterns. I’m thinking of making the sunset simulation more dynamic and captivating with intricate lighting sequences inspired by nature. Also, I’d like to get better at drawing schematics.

Week 9 – Assignment – Caution Coaster

For this assignment we were required to apply the concepts and components used so far to create a project involving an analog sensor, a digital sensor and two LEDs. I decided to explore the functioning of the TMP36 Temperature sensor and have used it as the analog sensor to develop a simple temperature detection model that may be employed in beverage holders to warn the people of the temperature of the contents of the glass.

Using the RGB LED, I have depicted temperature ranges from hot to cold by changing the colors from red to green to blue. Apart from this I have used a switch along with a yellow LED which may be turned on or off. As the program runs, the corresponding temperature value is printed in the Serial Monitor.

I have demonstrated the working of this circuit using glasses containing water of different temperatures ranging from ice cold to boiling hot and was able to achieve the desired color code.

Assignment Video

I particularly enjoyed figuring out the connections and coding for the temperature sensor through a video and the datasheet provided.

Overall, I believe the assignment helped me delve deeper into creating simple circuits and the commands of Arduino IDE.

int RED=9;
int GREEN=10;
int BLUE=11;
int PIN=A0;
void setup() {
  Serial.begin(9600);
  pinMode(RED,OUTPUT);
  pinMode(BLUE,OUTPUT);
  pinMode(GREEN,OUTPUT);
}

void loop() {
  int sensorValue=analogRead(PIN);
  delay(200); //delays the frequency of temperature readings
  float mv = sensorValue*4.9; //converts the analog input into mV
  float temp = (mv-500)/10; //calculates the final temperature value
  Serial.print("Temperature: ");
  Serial.print((mv-500)/10);
  Serial.print("°C\n");
  if (temp>27){
    digitalWrite(RED,HIGH);
    digitalWrite(GREEN,LOW);
    digitalWrite(BLUE,LOW);
  }
  else if (temp>21){
    digitalWrite(GREEN,HIGH);
    digitalWrite(RED,LOW);
    digitalWrite(BLUE,LOW);
  }
  else if (temp>16){
    digitalWrite(BLUE,HIGH);
    digitalWrite(GREEN,LOW);
    digitalWrite(RED,LOW);
  }
  
}

 

Week 9 – Reading Reflection

In this week’s reading, “Making Interactive Art: Set the Stage, Then Shut Up and Listen” the author set out the fundamental nature of interactive art as free and uncontrolling. He argues that artists should never impose or provide their intentions or interpretation of the artwork to the viewer. This field of art calls for the complex nature of human thought to allow the viewer to explore unique interpretations impacted by personal experiences. I found this idea to be particularly relatable as I often witness people having entirely different viewpoints regarding pieces of art. I also feel that if an artist provides their interpretation or explanation, it limits the viewer from exploring their thoughts as they begin to believe that there is only one right understanding of the art. Providing viewers with the freedom to think brings out their true reaction and adds greater depth to the interactive art. It may also be possible for the artist to discover a new dimension of their own work which they may not have previously considered. Hence, I completely agree with the argument presented by the author and firmly believe that the world of interactive art is all about exploring yourself through the displays.

The second reading, “Physical Computing’s Greatest Hits (and misses)”, felt like an unexplored world of opportunities. I was intrigued to read about the numerous projects created using various aspects of physical computing. It has also provided with an inspiration to think more creatively for future assignments. It was interesting to note that all involved relatively similar components and yet were so diverse in concept and implementation.

Reflection:

Blending the two ideas, Tigoe is like, “Why stick to the same old system when we can spice it up?” Even if it’s another dance floor pad or a gesture-controlled gadget, there’s a whole treasure trove of learning. It’s about giving users the stage to express themselves through art. Creators should give room to users to play and explore, setting up a playground for artistic talents. It’s like peeking into people’s thoughts, adding value to your creation by tuning in to their reactions. All in all, artwork should allow us the viewers or listeners to know the inner thoughts of the viewer to which their reaction was used to create the artwork as well as the designer that made the platform. This is one main thing I resonated with. After all isn’t that what interactive media is?

Week 9- Reflection

The text emphasizes the delicate balance in creating interactive art, cautioning against excessive interpretation. The author challenges the conventional idea that art is a fixed statement, urging artists to view interactive works as ongoing conversations with the audience. This perspective aligns interactive art more with directing a performance than crafting a traditional piece. By providing a basic context, then allowing the audience to navigate and interpret, without imposing predefined meanings. The analogy to directing actors underscores the importance of enabling discovery rather than dictating emotions. It encourages artists to see their creations not as finished products but as evolving performances, completed by the audience’s engagement. It invites a shift from dictation to collaboration, where the audience becomes an integral part of the artistic process.

With the given examples in the text “Physical Computing’s Greatest Hits (and misses)”, it is beautifully shown how these ideas are developed within ourselves based on creativity and sense of living. As an artists I love to add small touches on things I leave behind. It is nice to look back upon them one day and maybe add more bits of the journey beyond that point. The things we create aren’t necessarily useful or practical, but it’s something that allows us to project oursleves freely and openly.