Lab 1: Intro to Physical Computing

Eric Rawn
2 min readSep 1, 2021

Eric Rawn. Professor Kimiko Ryokai. Tangible User Interfaces, Fall 2021

Today’s lab was an introduction to Arduino—we set up the basic software to Blink an LED.

To start, we downloaded the Arduino IDE, and unpackaged everything. The circuit below is 3.3V -> LED Anode -> LED Cathode -> Resistor (220 Ohm) -> GND.

Components:

Arduino Uno

220 Ohm Resistor

1 Jumper Wire

1 Breadboard

1 Red LED

Code:

This code is based on the “Blink” Example from the Arduino IDE Examples. To get this working, we only needed to replace BUILTIN_LED with A0 to blink the external LED.


// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(A0, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(A0, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(A0, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

Bonus: Random Walk

As an extra, I programmed the LED to fade in intensity according to a random walk:

float intensity = 125;// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(9, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
intensity += random(-10,10);
analogWrite(9, int(intensity));
delay(100);
}

^ Here we can see how the random walk “wraps around” the integer variable (capped at 255) to zero, and so what is normally a smooth transition becomes a sudden change.

--

--

Eric Rawn

CS PhD Student at Berkeley. Art, Computers, and Education.