Physical Computing Class at City of Bridges High School, Pittsburgh

+
+ 🧠 = ‼︎

Arduino Uno R3 board image from arduino.cc

About this class

City of Bridges High School is a “progressive, holistic, 9th–12th grade high school which believes that school should be transformational for the students, the community, and the world.” (I couldn’t put it better than them!) They’re located on the South Side of Pittsburgh, PA.

Robert Zacharias (that’s me) is teaching a five-week class there on Physical Computing in the spring of 2020. The class runs on Tuesday and Thursday afternoons, 1–3 p.m. We’re learning how to build interactive electronic devices using the Arduino electronics platform.

Our goals for the block

Assignments

assignment due
Homework 1 Tuesday 2/11 (extended from 2/6)
Homework 2 Tuesday 2/18
Homework 3 Thursday 2/20
Homework 4 Tuesday 2/25
Homework 5 Thursday 2/27
Homework 6 Tuesday 3/3

Progress log

As of this writing (Thursday, March 5th, 2020), this class has concluded. Thanks to the students and staff of City of Bridges High School for sharing in the learning. I’m hoping that this experience will serve as a useful kernel for further explorations in electronics, software, and building interactive devices.

Here’s a log of the learning and activities we did every day in our time together:

Class 1: Tuesday, February 4th

Class 2: Thursday, February 6th

Class 3: Tuesday, Febuary 11th

// make the light attached to pin 13 blink

/*
 * the steps to make a light blink:
 * 
 * 1. turn the light on
 * 2. turn the light off
 * 3. repeat 1 and 2
 * 
 */

// stuff you want to do once and only once
void setup(){
  // set up the correct pin modes
  pinMode(13, OUTPUT); // OUTPUT is like a power supply
}

// stuff you want to do over and over
void loop(){
  // turn on the LED
  digitalWrite(13, HIGH); // "send electricity out of pin 13"

  // wait for half a second
  // delay(XXX) milliseconds (there are 1000 milliseconds per second)
  delay(500);
  
  // turn off the LED
  digitalWrite(13, LOW); // "don't send electrity out of pin 13"
  delay(200);
}

Class 4: Thursday, February 13th

// read a potentiometer value and send it back to the computer

/* 
 *  potentiometer wiper is connected to pin A1
 *  potentiometer outside legs are connected to 5V and ground
 */

void setup(){
  pinMode(A1, INPUT);
  // turn on the Serial communication system
  Serial.begin(9600);
}

void loop(){
  // Serial.println(thingInHere) will "print" thingInHere to the computer
  Serial.println( analogRead(A1) ); // measure the voltage at pin A1
}

Class 5: Tuesday, February 18th

Partial example solution:

void setup() {
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);

  digitalWrite(2, HIGH);
  digitalWrite(3, HIGH);
  digitalWrite(4, HIGH);
  delay(400);

}

void loop() {
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);

  delay(400);
  digitalWrite(2, HIGH);
  delay(400);
  digitalWrite(2, LOW);
  digitalWrite(3, HIGH);
}
// read a potentiometer's value and send it back to the computer
// use the potentiometer's position to change blink rate

// pot is plugged in to pin A3
// LED1 is plugged into pin 3
// LED2 is plugged into pin 5
// photoresistor is plugged in to pin A1

void setup() {
  pinMode(A3, INPUT);
  pinMode(A1, INPUT);
  pinMode(3, OUTPUT);
  pinMode(5, OUTPUT);
  Serial.begin(9600); // turn on serial communication between Arduino and computer
}

void loop() {
  Serial.println( analogRead(A3) ); // send analogRead(A3) back to the computer
  // turn on one LED and turn off the other
  digitalWrite(3, HIGH);
  digitalWrite(5, LOW);
  delay(analogRead(A3));

  // switch which LED is on and off
  digitalWrite(3, LOW);
  digitalWrite(5, HIGH);
  delay(analogRead(A1));

}

Class 6: Thursday, February 20th

Code we wrote: turning on an LED when an attached button is pressed (Note: I added the lines which make the POTPIN variable)

// button plugged into pin 2
// and LED plugged into pin 6

// make a new variable to store the pin number
int BUTTONPIN; // BUTTONPIN is the name of the variable.
BUTTONPIN = 2; // now BUTTONPIN stores the number 2.
int LEDPIN;
LEDPIN = 6;
int POTPIN = A0; // you can also do these both in one line

void setup(){
  pinMode(BUTTONPIN, INPUT);
  pinMode(LEDPIN, OUTPUT);
  pinMode(POTPIN, INPUT);
}

void loop(){
  // when the button is pressed, light the LED

  int buttonState; // variable to store the button's state
  buttonState = digitalRead(BUTTONPIN);

  int potVal; // variable to store the potentiometer's value
  potVal = analogRead(POTPIN);

  // test: are there 5 volts at pin 2?
  if ( buttonState == HIGH ) {
    // if so, then light pin 6
    digitalWrite(LEDPIN, LOW);
  } else {
    // if not, turn off the light
    digitalWrite(LEDPIN, HIGH);
  }
}

Class 7: Tuesday, February 25th

Code to do the technical warmup homework assignment:

// alternating blinking LEDs, rate based on a pot. position

const int LED1PIN = 4;
const int LED2PIN = 3;
const int POTPIN = A0;

void setup() {
  pinMode(LED1PIN, OUTPUT);
  pinMode(LED2PIN, OUTPUT);
  pinMode(POTPIN, INPUT);
}

void loop() {
  int potVal = analogRead(POTPIN);

  digitalWrite(LED1PIN, HIGH);
  digitalWrite(LED2PIN, LOW);
  delay(potVal);

  digitalWrite(LED1PIN, LOW);
  digitalWrite(LED2PIN, HIGH);
  delay(potVal);
}

Code to drive a hobby servomotor:

// tell a servo motor where to go

#include <Servo.h>
const int SERVOPIN = 3;
Servo turnMotor; // create a servo motor "object"

void setup() {
  turnMotor.attach(SERVOPIN);
}

void loop() {
  turnMotor.write(5); // go to 5 degrees of rotation
  delay(500);
  turnMotor.write(100); // go to 100 degrees of rotation
  delay(500);
}

Class 8: Thursday, Feb. 27th

Code we wrote to read the ADXL335 accelerometer values is below. This code will print values on the computer in the format 356,389,274 per a single-line record, where the comma-separated values are the X, Y, and Z accelerometer values respectively.

// read a three-axis accelerometer

const int XPIN = A0;
const int YPIN = A1;
const int ZPIN = A2;

void setup() {
  pinMode(XPIN, INPUT);
  pinMode(YPIN, INPUT);
  pinMode(ZPIN, INPUT);
  Serial.begin(9600);
}

void loop() {
  Serial.print( analogRead(XPIN) );
  Serial.print(",");
  Serial.print( analogRead(YPIN) );
  Serial.print(",");
  Serial.println( analogRead(ZPIN) );
}

Class 9: Tuesday, March 3rd

We wrote some code to read a photocell as an input and use its value to write to various different outputs.

// read the value of a photoresistor
// and send its value to the computer
// and also drive a ________________

const int PHOTOPIN = A0;
const int SERVOPIN = 4;

void setup() {
  pinMode(PHOTOPIN, INPUT);
  pinMode(OUTPUTPIN, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int potVal;
  potVal = analogRead(PHOTOPIN);
  Serial.println(potVal);

  int outputVal; // create an output value
  // use map() to change the range of the output value
  outputVal = map(potVal, 21, 900, 0, 180);
  
  
  delay(100);
}

Class 10: Thursday, March 5th

Photo of electrical schematic hand-drawn on whiteboard.

(Stevin drew the blue, Austin drew the orange, and Kai drew the purple. I drew the black.)