Note: “codebook” entries below are verbatim pasting of all of the code we used in class. It’s possible they may not compile (i.e. may have errors) if we left things unresolved, or were writing pseudocode, etc.

Tuesday, Sept. 1st: intro

  • Introduction to course content, policy, and housekeeping (with reference to the course website’s home page)
  • Make a group sketch to show people’s things they’ve built (or wanted to build)
  • Go around sharing names, pronouns, language clues, things people have built
  • Go over syllabus
  • Homework 1 assigned, due at start of class on Thursday, Sept. 3rd

Thursday, Sept 3rd: circuits and blinks

  • Students share out their Homework 1 projects
  • Syllabus quiz
  • Orientation to Tinkercad
  • Beginning to write our first blinking sketch (we ran out of time!)
    • Remainder of lesson is recorded and shared on course Canvas site
  • Homework 2 assigned, due at start of class on Tuesday, Sept. 8th

Tuesday, Sept. 8th: inputs

  • going over questions from the asynchronous teaching assigned as part of Homework 2
    • drawing a complete circuit that doesn’t have a circle in it—using the 5V and ⏚
  • going over questions from the Homework 2 software/electronics assignment
  • how to use a potentiometer in a circuit
    • connect one leg to 5V, one leg to ⏚, and the “wiper” to an Arduino analog input pin
  • how to read a potentiometer in software and print a value back to the user
    • use analogRead(pin) to read the voltage at the specified pin
    • use Serial.println(data) to send the specified data back to the attached computer
  • wiring a pushbutton: pull-down resistor is needed
    • in hydraulic analogy: a little tiny drain to empty out any pressure and bring the tank down to 0 in the absence of any other input
  • Homework 3 assigned, due at start of class on Thursday, Sept. 10th

Thursday, Sept. 10th: homework review, resistor colors, variables, PWM

  • Questions and comments on Homework 3
  • Go over some schematic dos and don’ts from prior homeworks (names removed to protect the innocent)
  • Style notes
    • Use const int data types for pin assignments and other constant variables, using ALL_CAPS names, e.g.: const int POTPIN = A3;
    • Use whatever data type is appropriate for other variables, with camelCase names, e.g.: int potVal = 0;
  • Arduino data types (see relevant reference section for details)
    • int stores “integers” (whole numbers) -32,768 to 32,767
    • long stores a bigger range of integers, -2.1 billion to 2.1 billion
    • unsigned int stores a non-negative integer, 0 to 65,535
    • unsigned long stores a non-negative long, 0 to 4.2 billion
    • float stores a number with a decimal point in it, -3.4×10^38 to 3.4×10^38
    • char stores a single character like a, ?, Q, or 8 (the character 8, not the number 8)
    • String stores a “string,” or chain, of characters, like Hey, there or A28DN29
    • bool stores a boolean value, either true or false (equivalent to 1 and 0 respectively)
  • Be sure to follow the link I emailed you to request your course kit. Hopefully we’ve got those in hand next time we meet!
  • Reading resistor color codes (using this chart or its ilk)
  • The fourth member of a small matrix: analogWrite. (We’d already learned analogRead, digitalRead, and digitalWrite.)
    • The outputting of voltages other than 0V and 5V is accomplished with analogWrite, which has a range of 0–255
    • It actually is rapidly switching the power supply on and off, and varying the proportion of time that it’s on (this is called pulse width modulation, or PWM)
    • The on-chip facility that accomplishes the task is a digital to analog converter, or DAC
  • Using a multimeter and oscilloscope in Tinkercad to see if we can observe actually changing voltages in writing our own simple PWM as shown below
  • Homework 4 assigned, due at start of class on Tuesday, Sept. 15th
// const makes this an unchangeable variable
// I use ALL_CAPS for any constant in the code
const int LEDPIN = 13;

void setup(){
  pinMode(LEDPIN, OUTPUT);

void loop(){
  digitalWrite(LEDPIN, HIGH);
  delay(3); // on for 3 milliseconds
  digitalWrite(LEDPIN, LOW);
  delay(1); // off for 1 millisecond

  // if it's on for 3 and off for 1, it is on 75% of the time x 5 volts ≈ 3.75V

Tuesday, Sept. 15th: finer points of resistors in circuits, switches, and more inputs

  • Different types of switches:
    • single-pole single-throw (SPST) is the most basic switch type, with two legs coming out, which can be either connected to each other or not; an example is a pushbutton.
    • single-pole double-throw (SPDT) is like the slide switch in our kit: it’s got three legs coming out, and either the middle leg is connected to one of the outsides, or the middle leg is connected to the other outside.
    • “maintained” switches hold their position once they’re switched there (like a light switch)
    • “momentary” switches bounce back to a resting state when they’re not being pushed on (like a pushbutton that bounces back)
  • Driving a servo motor in Tinkercad (and using the Servo library)
  • Driving a speaker in Tinkercad (using the tone() command)
  • Quick Homework 5 introduced, due on Thursday

codebook: driving a servo motor

#include <Servo.h>

// make a servo "object" called doorMotor (like any other variable)
Servo doorMotor;

const int DOORMOTORPIN = 4;

void setup(){
  // tell the Arduino where the motor is plugged in

  // note that there's no need for pinMode; the library takes care of that

void loop(){
  // tell the motor to go to any position 0–180º
  doorMotor.write(60); // 60º

  delay(1000); // give it time to get there!

  doorMotor.write(170); // 170º

  delay(1000); // give it time to get back, too

codebook: driving a speaker

const int SPEAKERPIN = 8;

void setup(){

void loop(){
  // play any tone by specifying its frequency
  tone(SPEAKERPIN, 440); // play the A4 note, which is 440 Hertz

Thursday, Sept. 17th: introduction to Double Transducer project

  • Go over everyone’s Homework 5 solutions together (pretty straightforward, thankfully)
  • Most people either have their kits, or are getting them mailed very soon (they’ve got tracking numbers), which is really good to hear
  • mea culpa! I am behind in grading homeworks 3 and 4. My apologies. They’re coming.
  • New sensor: passive infrared (PIR) motion detector
  • Introduction to Project 1: Double Transducer
    • Teams assigned
    • Ideation assignment due Tuesday 9/22
    • Rest of day is a work session
  • Also for Tuesday 9/22: please prepare your computers to do a trial run of our MQTT-mediated inter-Arduino communication
    • If you don’t have it, please download and install Python 3 (installation instructions from Garth Zeglin’s 16-223 Creative Kinectic Systems course)
    • Then, download two Python modules, paho-mqtt and PyQt5 (installation instructions for Mac users)
    • Finally, download the “MQTT Monitor” program that Dr. Zeglin wrote; information page and direct download link
    • Try launching that program yourself before class on Tuesday; if you aren’t able to get it running, please email Zach requesting tech support directly and we’ll see if we can’t figure it out.

codebook: using analog input pins for digital purposes, and other tricks

// analog input pins are *also* digital I/O pins
const int PIRSENSOR = A1;
const int LEDPIN = A3;

void setup(){
  pinMode(LEDPIN, OUTPUT);


void loop(){
    if you don't need to preserve the value of a digitalRead,
    you can just use it immediately inside of a function or test:

  // for example

  // another example
  digitalWrite(LEDPIN, digitalRead(PIRSENSOR));

  // both of these work just fine!

Tuesday, Sept. 22nd: technical odds and ends, Project 1 Ideation

  • We try the MQTT Monitor program info link as a trial run. Some success, some not so much. To be further debugged.
  • Introducing the Diary of Sorrows, a short form you can fill out when something is really not working the way it should be and you are feeling frustrated/annoyed/etc. (The link to the Diary appears on the site’s Canvas page.) Sharing the frustrations is far better than shouldering them yourself!
  • How to “schedule” an event to happen on a regular basis on the Arduino, without using a delay(): use the event-loop programming model, which is further explicated at the Blink without blocking tutorial page.
  • Remainder of class is used for team meetings about Project 1 ideation
  • Homework 6: Asynch lectures on the Arduino board and IDE assigned, due before class on Thursday 9/24

Thursday, Sept. 24th: IDE, ultrasonic ranger, Project 1 work time

  • Started class with a quick survey to try to get to the root of the MQTT software problems; I’ll analyze after class and see if I can see any trends to identify the trouble.
  • Launching the Arduino IDE and wiring up the ultrasonic ranger (class tutorial link)
  • Briefly describing the PIR sensor’s operation (most students didn’t have it physically with them)
  • Remainder of the session is free work time for Project 1, due in one week

Codebook: very lightly modified NewPing example

We only changed a couple lines of this example from the NewPing library, but just for completeness, it’s posted here as we used it in class:

// ---------------------------------------------------------------------------
// Example NewPing library sketch that does a ping about 20 times per second.
// ---------------------------------------------------------------------------

#include <NewPing.h>

const int TRIGGER_PIN = 12;  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     11  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

void setup() {
  Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.

void loop() {
  delay(50);                     // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
//  Serial.print("Ping: ");
  Serial.println(sonar.ping_cm()); // Send ping, get distance in cm and print result (0 = outside set distance range)
//  Serial.println("cm");

Tuesday, Sept. 29th: MQTT attempt #2, Project 1 work time

  • Running sample code on students’ machines to try again to get MQTT to work (see below)
  • Thursday presentation plan: ~10 minutes/group
    • use slide deck linked from Canvas “syllabus” page
    • show your thing, both in Tinkercad and real life
    • share challenges, findings, and comment on any aspect you’d like
    • after everyone presents we’ll try for the MQTT-mediated chain! (Please see the Codebook entry below and the more complete example program here for the little bits of code you’ll need to add to your sketch to make it work with MQTT.)
  • LCD note: the course tutorial page assumes you have an LCD with an “I²C backpack,” which the Elegoo part in your kit does not have. Tinkercad’s model LCD (oops—sorry for a typo earlier in this link—updated 9/30/20) matches yours in wiring and viable code; use that as an example.
  • Project 1 work time. Don’t forget to take pictures as you go!
    • Also don’t forget about the Diary of Sorrows (linked from the course Canvas page)
  • Lab hours: I am teaching a different class, also having a work day, on Wednesday 9/30, 2:40–5:30 p.m. You are welcome to come to the lab during that time, though I won’t be able to give you sustained attention as I give that time to the students in that course. (There are only 2–3 in-person students in that class, so overcrowding is not a worry.)
  • Extra-help hours: I am available Wednesday 9/30 in the morning, 9–11:30 a.m. Please let me know if you’d like any help in that window and I’ll be happy to schedule a meeting.
  • Otherwise, please just email me to ask for help, any time. If I’m awake, I’ll write back. Don’t hesitate to ask!

Codebook: MQTT / Arduino interface

The two very simple functions below should allow your Arduino to send and receive data from the MQTT server, provided you are already running the Arduino-MQTT Bridge program.

For a slightly more fleshed out example, see MQTT sample sketch on the Code Bites page

void serialEvent(){
  /*  You do *not* need to call this function in your loop;
      it is a special function that will run whenever serial
      data flows into the Arduino. */
  /*  The function assumes your machine's input value 
      is called "inVal" (change that variable name as needed) */

  // if there is incoming serial data, read it
  while (Serial.available() > 0){
    // interpret incoming digits as integer and save into inVal
    inVal = Serial.parseInt();

void transmitSerialSignal(){
  /* You should call this function 2-4 times/second in your
     main loop to transmit information to the next Arduino
     in the transmission chain. */
  /* Assumes your machine's outgoing value is called outVal
     (change that variable name as needed) */

Thursday, Oct. 1st: Project 1 due

  • Project 1 critique

Tuesday, Oct. 6th: A few more tricks

  • External power (a.k.a. You Can Power Your Arduino With Things Other Than the USB Port on Your Computer). Possibilities:

    1. Use the USB connection (we have done this so far)
    2. Use an external 5V power supply, plug it into a breadboard’s power rails, and plug the Arduino into those power rails as well (Arduino’s 5V pin to 5 volt line, Arduino’s gnd pin to the ground rail)
    3. Use a 7–12V power source

      1. With a barrel plug: plug into the Arduino’s barrel jack
      2. With a naked wire: plug into the Arduino’s VIN pin

      (Whichever of these you choose, the Arduino will use its on-board voltage regulator to turn the 7–12 volts you feed it into the 5V it needs.)

  • New pin mode: INPUT_PULLUP. No more need for those pull-down resistors for buttons/switches!
  • Quick poll on student mood and learning interest. Major findings:
    • Students want to learn about external power, electronics, software, and CAD
  • Lesson on using CircuitLab to draw schematics (this is the expected format for Project 1, and future project, schematic documentation)

Thursday, Oct. 8th: Project 2 assigned, Fusion 360 tutorial

  • Please submit Project 1 documentation to Canvas by noon (I hadn’t published the assignments—oops!)
  • For Project 1 “Technical Proficiency” grade: please fill out this Canvas assignment to suggest the appropriate grade for your work.
  • Project 2 introduced.
  • Fusion 360 CAD tutorial: drawing an Arduino board
    • making a new component
    • making a new sketch
    • dimensioning a rectangle in inches and millimeters
    • adding construction lines for defining positions of objects
    • drawing a line with a fixed angle
    • trimming lines, and seeing references destroyed
    • adding center-diameter circles
    • using the “Change Parameters” dialogue to add named dimensions
    • extruding a plane into a new body
    • adjusting visibility of body and sketch
    • seeing a change in the sketch affect the body
    • adding a new sketch on top of a body
    • adding another body from that sketch
    • projecting geometry from one sketch to another
    • using that geometry to draw a new feature
    • defining a new, orthogonal plane with an “offset plane” construction
    • starting a sketch on that new plane
    • drawing a two-point circle
    • extruding into a cylinder (to form the power jack)
  • The design as we left it at the end of class is available for download/manipulation here
  • Homework: Project 2 brainstorming

Tuesday, Oct. 13th: Ideation presentations

  • Dr. Katie Walsh of the Eberly Center on campus joins us to help gather student feedback on the course
  • Remainder of class (and extending over class time): individual 15-minute meetings with students reviewing their Project 2 ideation assignments and giving feedback.
  • Homework: Project 2 prototype development

Thursday, Oct. 15th: Ideation discussions and development

  • Room temperature superconductivity!
  • Student group discussions about individual Project 2 ideation, via

Tuesday, Oct. 20th: Guest speaker and prototype check-ins

  • Guest speaker Brenda Dare joins us to speak about matters of universal design, assistive technology, and answer questions about living with a disability. Ms. Dare works an advocate for people with disabilities at Transitional Paths to Independent Living, a local nonprofit organization providing an array of services to their clients. A few salient points she made:
    • “Assistive technology” is something that enables someone to perform a task that they could not otherwise.
    • The most important piece of assistive technology that Brenda owns is her travel coffee mug!
    • “Universal design” is the principle that making tasks/processes/etc. easier for people with disabilities often produces benefits for everyone else, too; an example is curb cuts, which make it possible for people using wheelchairs to get from the street onto a sidewalk, but which are also useful for people pushing strollers, people making deliveries, children, and older people.
    • For myself does not necessarily mean by myself.”
    • “We all have to depend on other people to get through our day,” including (but not limited to!) people with disabilities. We all use technologies all the time to help ourselves make things easier, or possible, for us to do. (This is the same sentiment Sara Hendren is quoted expressing on the project assignment page.)
  • Homework: Project 2 work continues

Thursday, Oct. 22nd: Work day

  • Project 2 presentation deck
  • Work day.
  • Remember to take pictures as you go!
  • Zach’s upcoming availability:
    • Thursday 10/22: 2:30–4pm
    • Friday 10/23: 9am–noon
    • Monday 10/26 10:30am–1:30pm
    • and any time at all via email!

Tuesday, Oct. 27th: Project 2 presentations

  • Students present their Project 2 work to the group, ~5 minutes each, from slides
  • Written comments and feedback can be posted to a different comment deck (it’s shared via link in the Zoom call)
  • Brief Q&A (a minute or two) after each presentation
  • We break into Gather space for more sustained discussions, with students moving between commenters in cycles as described in class
  • Project 2 documentation due in one week, November 3rd.