• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Sophie's Documentation Blog

Categories

  • Creative Coding Lab
  • Interaction Lab
  • Interactive Fashion

February 9, 2021

Recitation 2: Arduino Basics

Part 1: In-class learning

Circuit 1: Fade

In this circuit, there are a resistor (220) and a LED. The LED will gradually fade and then light up again. It will constantly repeat the process.

Based on my last experience using the breadboard, I didn’t encounter any difficulties this time. But I find that it’s important to constantly check if the port is connected to usb, otherwise there’s an error.

 Here are my code:

/*
  Fading

  This example shows how to fade an LED using the analogWrite() function.

  The circuit:
  - LED attached from digital pin 9 to ground.

  created 1 Nov 2008
  by David A. Mellis
  modified 30 Aug 2011
  by Tom Igoe

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/Fading
*/

int ledPin = 9;    // LED connected to digital pin 9

void setup() {
  // nothing happens in setup
}

void loop() {
  // fade in from min to max in increments of 5 points:
  for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);
    // wait for 30 milliseconds to see the dimming effect
    delay(30);
  }

  // fade out from max to min in increments of 5 points:
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);
    // wait for 30 milliseconds to see the dimming effect
    delay(30);
  }
}

Circuit 2: toneMelody

When the program is started, the speaker will give off a melody. This circuit only consists of one speaker so the circuit is easy to build and I don’t need to build it on breadboard. 

 

Here are my code:

/*
  Melody

  Plays a melody

  circuit:
  - 8 ohm speaker on digital pin 8

  created 21 Jan 2010
  modified 30 Aug 2011
  by Tom Igoe

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/Tone
*/

#include "pitches.h"

// notes in the melody:
int melody[] = {
  NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
};

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
  4, 8, 8, 4, 4, 4, 4, 4
};

void setup() {
  // iterate over the notes of the melody:
  for (int thisNote = 0; thisNote < 8; thisNote++) {

    // to calculate the note duration, take one second divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = 1000 / noteDurations[thisNote];
    tone(8, melody[thisNote], noteDuration);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    // stop the tone playing:
    noTone(8);
  }
}

void loop() {
  // no need to repeat the melody.
}

Circuit 3: Speed game

In this circuit, two players each have a button and the one who touches the button for ten times with a shorter time is the winner. Also, the LED on the winner side will light up and the speaker will give off a melody at the same time.

The circuit consists of two LED and buttons, four resistors (220 and 10k), and a speaker.

 

When we build the circuit, we first connect the ground and the pins. Then we put the speaker on the board. After that, we connect the LED and the 220 resistor. In the next step we connect the 10k resistors as well as the buttons.

At first, we were confused about this part (as shown in the picture below). Then we understand that these two wires connect both sides of the ground/positive side so that we can make use of both sides of the board, which makes the format of the circuit more clear and easier to understand.

Also, after we connect the two 10k resistors, we find that these resistors occupy too much space on the board so that we cannot put other components on the board. Then we reconnect the resistors to  make the components get “closer” to each other .

Here are the code:

int buzzerPin = 8;
int button1 = 11;
int button2 = 10;
int led1 = 3;
int led2 = 2;

int goal = 10;
int buttonState1 = LOW;
int previousState1 = LOW;
int buttonState2 = LOW;
int previousState2 = LOW;

int counter1 = 0;
int counter2 = 0;
boolean winner1 = false;
boolean winner2 = false;

// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0;         // the last time the output pin was toggled
long debounce = 200;   // the debounce time, increase if the output flickers

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(buzzerPin, OUTPUT);
  pinMode(button1, INPUT);
  pinMode(button2, INPUT);
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  Serial.println("******************* RACE THE LED *******************");
  delay(1000);
  Serial.println("READY");
  delay(1000);
  Serial.println("SET");
  delay(1500);
  Serial.println("GO!!!!!!!!!!!!!!!!");

}

void loop() {
  // put your main code here, to run repeatedly:
  buttonState1 = digitalRead(button1);
  buttonState2 = digitalRead(button2);
  //Serial.println(buttonState1);

  //this checks the times player 01 has pressed the button
  if (counter1 < goal && winner2 == false) {
    if (buttonState1 != previousState1 && millis() - time > debounce) {
      if (buttonState1 == HIGH) {
        counter1++;
        Serial.print("player 01:  ");
        Serial.println(counter1);
        time = millis();
      }
    }
    previousState1 = buttonState1;
    if (counter1 == goal && winner2 == false) {
      winner1 = true;
      digitalWrite(led1, HIGH);
      Serial.println("PLAYER 01 WINS");
      playMelody();
    }
  }

  //this checks the times player 02 has pressed the button

  if (counter2 < goal && winner1 == false) {
    if (buttonState2 != previousState2 && millis() - time > debounce) {
      if (buttonState2 == HIGH) {
        counter2++;
        Serial.print("player 02:  ");
        Serial.println(counter2);
        time = millis();
      }
    }
    previousState2 = buttonState2;
    if (counter2 == goal && winner2 == false) {
      winner2 = true;
      digitalWrite(led2, HIGH);
      Serial.println("PLAYER 02 WINS");
      playMelody();
    }
  }

}

void playFreq(double freqHz, int durationMs) {
  //Calculate the period in microseconds
  int periodMicro = int((1 / freqHz) * 1000000);
  int halfPeriod = periodMicro / 2;

  //store start time
  long startTime = millis();

  //(millis() - startTime) is elapsed play time
  while ((millis() - startTime) < durationMs) {
    digitalWrite(buzzerPin, HIGH);
    delayMicroseconds(halfPeriod);
    digitalWrite(buzzerPin, LOW);
    delayMicroseconds(halfPeriod);
  }
}

void playMelody() {

  playFreq(262, 100);
  playFreq(294, 100);
  playFreq(349, 100);
  playFreq(294, 100);
  playFreq(440, 200);
  delay(100);
  playFreq(440, 400);
  playFreq(392, 400);
  delay(300);
  playFreq(262, 100);
  playFreq(294, 100);
  playFreq(349, 100);
  playFreq(294, 100);
  playFreq(392, 200);
  delay(100);
  playFreq(392, 400);
  playFreq(349, 400);

}

Reflection

1.remember to check the port (usb)

2.adjust the format of circuit

It’s important to design the format of the circuit before starting to connect it. The two problems we encountered are actually about the format of the circuit. For instance, the wires that connect both sides make it easier to connect the ground side of other components. Also, we should learn to design how to put the components together in a more concise way. 

Part 2: Question responses 

Question 1: Reflect on how you use technology in your daily life and on the circuits you just built. Use the Introduction Chapter (page xvii-xxix) of Physical Computing and your own observations to define interaction.

In terms of physical computing, interaction serves as an engaging conversation between the physical world and the virtual world, which complicates the connection between human bodies and computers. What’s more, interaction, as well as physical computing, should be used to support human behaviors rather than simulate their behaviors.

In the book physical computing, the authors propose the concept of intelligence amplification (IA). As they explain, “This approach looks to people to supply the spark of interest and computers to capture and convey a person’s expression”. In other words, the significance of IA is that it emphasizes the supportive role of technology to help humans, which helps me understand the meaning of interaction. Also, the authors discuss how physical computing bridges the gap between physical world and computers, which inspires me incorporate  this “connection” into my definition of interaction. 

The circuit I built in class also helps me understand interaction. For instance, in the circuit 3, as two users constantly pushes the button and enjoy the game, there’s interaction not only between human and the computer/sensors, but also between the two players. Physical computing plays an important role in the production of interactive experience since it receives the signals for the computer to process and finally to transform them into the light and sound.

Also, lots of my real-life experiences contribute to my definition of interaction. For instance, at the entrance of my home is a light which can turn on or turn off based on human behaviors. More specifically, if someone gets close to it or makes some sound, it will automatically turn on. And when the person leaves, the light will turn off. In this case, physical computing is used to support human behaviors as users approach the light and interact with the light with their voice, which goes beyond the simple interaction of controlling  the switch with hands.

Question 2: Why did we use the 10K resistor with the push button?

The 10K resistors are used to protect the circuit from having a short circuit. If the circuit doesn’t has these two resistors, when the switch is connected, the 5V side is directly connected to the ground side, which may cause the short-circuit.

Question 3: If you have 100,000 LEDs of any brightness and color at your disposal, what would you make and where would you put it?

If I have 100,000 LEDs, I will use these LEDs to form the surface of a big sphere. Inside the sphere are lots of touch sensors and temperature sensors. When someone approached the sphere and touches the LEDs on it, the brightness of these touched LEDs will increase and their colors will also change based on the body temperature. In this case, as there are more and more participants, the big sphere will be lighten up and become colorful. I want to hang the sphere on the ceiling so that every part of it can be touched.

Reference

Tom Igoe, Dan O’Sullivan – Physical Computing

Filed Under: Interaction Lab

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Recent Posts

  • Soteria – Interactive Fashion Final Project
  • Interactive Fashion Week 11
  • Presentation : Behnaz Farahi, interactive body architecture
  • Interactive Fashion Week 10
  • Interactive Fashion Week 9

Recent Comments

  • Marcela Godoy on Soteria – Interactive Fashion Final Project
  • Marcela Godoy on Interactive Fashion Week 7 Grasshopper + Paneling Tools
  • Marcela Godoy on Recitation 1: Electronics and Soldering by Sophie Peng
  • Erin on Final Project Proposal

Copyright © 2026 · Brunch Pro Theme on Genesis Framework · WordPress · Log in