Interaction Lab 2 (Arduino Boards) – Thomas Tai

Lecture Professor: Marcela Godoy
Lab Partner: Emily
Lab Date: February 2nd, 2018

Introduction:

This lab introduces us to microcontrollers, particularly, the arduino uno, and reviews on the concepts of the first lab on electronic components. A basic understanding of programming is necessary to code the software running on the arduino. We found the included example code to be very useful for getting started. Arduino code is very similar to Java or C. The below circuits were generally the same, with code being changed in between steps and parts being reused.

Part A (Individual Part)

Components:
-1x Arduino Board – The arduino board is the heart of the circuit and takes input, processes the information using the code uploaded to the board, and produces and output according to the code.
-1x Breadboard – The breadboard is used to connect various electronic parts together.
-1x LED – The LED emits light when electricity flows from the anode to cathode.
-1x Push Switch – The push switch is a button that completes the circuit when pressed, and closes the circuit when let go.
-1x 220 ohm resistor – This resistor was used for the light to reduce the amount of current going to the LED.
-1x 10k ohm resistor – This resistor limits current even more, and was used for the switch.

Source code for all examples are posted below.

For the first circuit I built, I gathered all the components from our shiny new arduino beginners kit, and assembled it as the schematic described. However, instead of using a 10K ohm resistor, I grabbed a 10K potentiometer instead. The circuit still worked, but I swapped it out for the correct component. I had to change a few wires that were connected to the wrong pins on the arduino, but everything else worked as described. For the coding part, I had to modify the code to be opposite state for the pushbutton, which was relatively easy after looking at the serial monitor, as everything was inverted. I followed the example code since I had no previous knowledge of Arduino Code, and made adjustments to input and output pins as necessary.

 

1.) Using a pushbutton

2.) Blinking LED

3.) Fading LED

4.) Custom 3 LED Project w/ Schematic Design

 

Part B (Pair Work)

Fading LED With Potentiometer:

Multiple Input and Output Circuit:

The serial output monitor was very useful for debugging! 🙂

For the group work portion of our project, we learned everything we needed from the example code for SerialInOut, which showed us how to use a potentiometer to control an LED. Though it looked confusing, our 3 input and 3 output project was easy. All we needed to do was triple the code for each potentiometer and its matching red, green, and yellow LED. We had fun trying to figure out bugs and issues with the circuit, which were mostly tied to loose circuitry and incorrect wiring. As for the coding part, we made several revisions until the code worked, as variables were easy to mix up. Overall, we were happy with how the circuit turned out, though if we were to do it again, we would use better potentiometers.

 

Questions

1.) During the assembly of the circuits, we used many electronic components as inputs and outputs. Which components do you recognize in the city?

During the assembly of the circuit, we recognized several electronic components that were used in the city. Probably the most common component used in electronics is the LED, which is used in everything from displays, streetlights, and skyscrapers. Another electronic component we often see in the city is a button switch, which is used on elevators, phones, light switches, and other input devices.

 

2.) If you have 100000 LEDs of any brightness and color at your disposal, what would you make and where would you put it?

If I had 100,000 LEDs of any color and brightness, I would make a bigger NYU Shanghai sign facing Century Avenue. The current sign that NYU Shanghai has is small, dim, and not visible enough. Of course, we would need purple LEDs, which are a combination of blue and red led diodes, and white LEDs, which are a combination of blue, green, and red led diodes. In my opinion though, RGB leds would offer a better experience, allowing us to make animations and change the image on the LED array. However, I don’t think that students would be happy buying 100,000 LEDs and spending thousands of tuition dollars on a sign.

 

3.) Which reflections about the nature of interaction can you make about the Figure I.1 in the Physical Computing reading?

According to Physical Computing, we can understand traditional computing as something that limits the interaction between human and computer to that of the keyboard and mouse, and screen and speakers. However, the computer cannot “see” the human like we see it. It only understands clicks through the Graphics User Interface, or taps on the keyboard corresponding to different letters. Interaction requires two actors, in this case a computer and its user. For now, a programmer must tell the computer how to receive input, process information, and send output.

 

Conclusion and Reflections

For this lab, greater knowledge of programming and circuitry was required. This made the lab more time consuming, and requiring independent research and analysis of example codes and methods and functions in Arduino code. After this lab, I’ve learned the basics of arduino code, how to work with input sensors such as push buttons and potentiometers digitally, and how to control output components such as LEDs with the Power Modulation. The arduino allows us to easily work with input and output sources almost entirely through code.

--------------------------------------------------------------------------------------------------
1.) Using a pushbutton

/*
  Button

  Turns on and off a light emitting diode(LED) connected to digital pin 13,
  when pressing a pushbutton attached to pin 2.
*/

// constants won't change. They're used here to set pin numbers:
const int buttonPin = 4;     // the number of the pushbutton pin
const int ledPin =  11;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

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

/*
  Blink Button

  Turns on and off an LED connected to digital pin 13,
  3 times when pressing a pushbutton attached to pin 2.
  
*/

// constants won't change. They're used here to set pin numbers:
const int buttonPin = 4;     // the number of the pushbutton pin
const int ledPin =  11;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop() {
  // read the state of the pus
hbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, LOW);
  } else {
    // turn LED off:
    for (int i=0; i <= 3; i++){
    digitalWrite(ledPin, HIGH);   // turn the LED on (HIGH is the voltage level)
    delay(1000);                       // wait for a second
    digitalWrite(ledPin, LOW);    // turn the LED off by making the voltage LOW
    delay(1000);
    }
  }
}
--------------------------------------------------------------------------------------------------
3.) Fading LED

/*
  Fade LED

  Fades an LED connected to digital pin 11
  
*/

// constants won't change. They're used here to set pin numbers:
const int buttonPin = 4;     // the number of the pushbutton pin
const int ledPin =  11;      // the number of the LED pin
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  } else {
    // turn LED on and fade:
    // set the brightness of pin 9:
  analogWrite(ledPin, brightness);

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness <= 0 || brightness >= 255) {
    fadeAmount = -fadeAmount;
  }
  // wait for 30 milliseconds to see the dimming effect
  delay(30);
  }
}
--------------------------------------------------------------------------------------------------
4.) Custom 3 LED Project

/*
  Custom LED Pattern

  Blinks through the different LED colors repeatedly in a loop.

*/

// constants won't change. They're used here to set pin numbers:
const int buttonPin = 4;     // the number of the pushbutton pin
const int redledPin =  11;      // the number of the RED LED pin(s)
const int greenledPin =  9;      // the number of the RED LED pin(s)
const int yellowledPin =  10;      // the number of the RED LED pin(s)
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(redledPin, OUTPUT);
  pinMode(yellowledPin, OUTPUT);
  pinMode(greenledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED off:
    digitalWrite(redledPin, LOW);
    digitalWrite(greenledPin, LOW);
    digitalWrite(yellowledPin, LOW);
  } else {
    // turn LED on:
    for(int x = 0; x <= 3; x++){ //Loop 3 times
      for (int i=9; i <= 11; i++){ //Loop through LEDs
        digitalWrite(i, HIGH); //Turn LED i on
        delay(500); //Wait before turning off
        digitalWrite(i, LOW); //Turn LED i off
      }
    }
  }
}
--------------------------------------------------------------------------------------------------
5.) (Pair Work) Fading an LED with a potentiometer

/*
  Analog input, analog output, serial output

  Reads an analog input pin, maps the result to a range from 0 to 255 and uses
  the result to set the pulse width modulation (PWM) of an output pin.
  Also prints the results to the Serial Monitor.
*/

// These constants won't change. They're used to give names to the pins used:
const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to

int sensorValue = 0;        // value read from the pot
int outputValue = 0;        // value output to the PWM (analog out)

void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600);
}

void loop() {
  // read the analog in value:
  sensorValue = analogRead(analogInPin);
  // map it to the range of the analog out:
  outputValue = map(sensorValue, 0, 1023, 0, 255);
  // change the analog out value:
  analogWrite(analogOutPin, outputValue);

  // print the results to the Serial Monitor:
  Serial.print("sensor = ");
  Serial.print(sensorValue);
  Serial.print("t output = ");
  Serial.println(outputValue);

  // wait 2 milliseconds before the next loop for the analog-to-digital
  // converter to settle after the last reading:
  delay(2);
}
--------------------------------------------------------------------------------------------------
6.) Fading three LEDs with three Potentiometers

/*
  RGY LED controls with potentiometers

  Uses 3 different potentiometers corresponding to green, yellow, and blue to fade an LED.
*/

// constants won't change. They're used here to set pin numbers:
const int buttonPin = 4;     // the number of the pushbutton pin
const int redledPin =  11;      // the number of the RED LED pin(s)
const int greenledPin =  9;      // the number of the GREEN LED pin(s)
const int yellowledPin =  10;      // the number of the YELLOW LED pin(s)
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by

//Potentiometer variables
const int redanalogInPin = A0;  // Analog input pin that the potentiometer is attached to
const int greenanalogInPin = A2;  // Analog input pin that the potentiometer is attached to
const int yellowanalogInPin = A1;  // Analog input pin that the potentiometer is attached to

//More variables
int redsensorValue = 0;        // value read from the pot
int redoutputValue = 0;   // value output to the PWM (analog out)
int greensensorValue = 0;        // value read from the pot
int greenoutputValue = 0;        // value output to the PWM (analog out)
int yellowsensorValue = 0;        // value read from the pot
int yellowoutputValue = 0;        // value output to the PWM (analog out)


void setup() {
  // initialize the LED pin as an output:
  pinMode(redledPin, OUTPUT);
  pinMode(yellowledPin, OUTPUT);
  pinMode(greenledPin, OUTPUT);

  //Serial communication init
  Serial.begin(9600);
  
}

void loop() {
  // POTENTIONMETER ------------------------------------
  // read the analog in value:
  redsensorValue = analogRead(redanalogInPin);
  yellowsensorValue = analogRead(yellowanalogInPin);
  greensensorValue = analogRead(greenanalogInPin);
  // map it to the range of the analog out:
  redoutputValue = map(redsensorValue, 67, 1023, 0, 255);
  yellowoutputValue = map(yellowsensorValue, 67, 1023, 0, 255);
  greenoutputValue = map(greensensorValue, 67, 1023, 0, 255);
  
  // change the analog out value:
  analogWrite(redledPin, redoutputValue);
  analogWrite(yellowledPin, yellowoutputValue);
  analogWrite(greenledPin, greenoutputValue);

  // print the results to the Serial Monitor:
  Serial.print("redsensor = t");
  Serial.print(redsensorValue);
  Serial.print("tyellowsensor = ");
  Serial.print(yellowsensorValue);
  Serial.print("t greensensor = ");
  Serial.println(greensensorValue);

}

One thought on “Interaction Lab 2 (Arduino Boards) – Thomas Tai

  1. great documentation Thomas!
    Regarding to your answer of the 10000 LEDs, it wouldn’t be interesting to think how that sign could interact with what is happening inside the building?
    Now that you know how to control LEDs, you could make them to react to something and create an interactive sign instead of a regular one 🙂

Leave a Reply