[p-com wk 3] making music & (servo) movement

1. Lab: Tone Output

I did this lab following instructions here.

Since miraculously behaving normally last week, my Arduino Nano decided to give up on me yet again. After fighting with the connection for quite a while, I set it aside with my other hopes and dreams, and went with a nice, reliable Uno board.

First experiment was to control one speaker with two force sensors connected to Analog pin A0. It’s quite difficult to describe the relationship between the two sensors. In terms of completing a circuit from power to ground, they’re in series. However, they’re also independently connecting to the A0 pin, one from power to A0, and the other from ground to A0. The lab described it as “a voltage divider circuit”. I looked it up but still not quite sure what it means.

Checking the input value, the range is between 0 and 1023. In this week’s class I learnt about byte (8 bits), so now I know 1024 is the amount of “pixels” in a 10-bit system.

Connecting speaker with a 100 ohm resistor, then onto the output pin on the board, I completed the circuit. In the code, I mapped the input range 0 – 1023 to the speaker’s frequency range (100-1000), and it sounded something like this:

I did notice that the input number changed rapidly when neither sensor was in use, but did react to changes as I touched at least one of them — which also reflected in the sound. I wonder if it’s similar to digital input when a switch not connected to any resistor gives out unstable input of both 1 and 0 (and therefore needs a pull up/pull down resistor)? Or maybe it’s the force sensor being unreliable and wild?

Onto making Arduino sing!

I used a pitches.h library to define each musical note with its frequency. In the example of a “shave and a haircut” melody, the notes are: C4, G3, G3, GS3 (though I'd argue it should be an A3), G3, 0 (pause) , B3, C4 . After finding the pitch, call the duration of each tone in relations to a whole note (4 for quarter note, etc). I wanted this song to loop, so I added in another 0 at the end of the melody that would last for a whole note, and wrote the program in void loop().

Unfortunately, no video evidence of this sound experiment is present. Here’s a clip of me (fake) tap dancing the rhythm:

I did, however, later programmed another tune. I made a surprising discovery that, in contrary of popular belief, the happy birthday song is actually in 3/4 time signature.

The code is as below

#include "pitches.h"
int melody[] = {

int noteDurations[] = {8,8,4,4,4,4,4,

void setup() {
void loop() {
    for (int thisNote = 0; thisNote < 29; thisNote++) {
    // one second divided by the note type.
    int noteDuration = 1000/noteDurations[thisNote];
   tone(8, melody[thisNote],noteDuration); 
    //pause for the note's duration plus 30 ms:
    delay(noteDuration +30);

Last experiment: making a finger piano with 4 pressure sensors.

My good cohort John traded me two gigantic pressure sensors, whose legs are half-broken. Rumor has it that they are extremely fragile and easy to melt. I worked some soldering magic on one of them and got it some new legs.

Leg surgery for large pressure sensor

The schematic diagram on the lab instruction page is blurry, so I drew my own. Everything is easier when you have a good schematic. A four-key pressure sensor piano in A minor (A-C-E-A) is produced.

Filming credit goes to David Currie

Notebook gifted by Tinrey Wang. Could’ve not survived without friends.

Through peeping at my cohorts’ lab, I realized my speaker plays way louder than most other speakers. I have hooked it onto other people’s setups (sometimes even without a resistor), and it wasn’t nearly as loud as when it was on my breadboard. I’m wondering if it’s because I’m supplying it with 5V instead of 3.3V from the Nano? But on a 3.3V circuit without a resistor, 3.3 / 8 should be much bigger than 5/108 as well. I should’ve measured the voltage and current that went through my speaker-in-uno. I thought of this question only after finishing the labs and tearing the circuits apart.

One other small (and slightly upsetting) discovery: The speaker can’t seem to play multiple notes at once. In order to make an instrument that would harmonize, preferably I should get two or three speakers / buzzers that connect to different output pins.

In general, this lab practiced my knowledge in mapping analog inputs into digital outputs, and familiarized me with using multiple sensors in various ways. I have developed some ideas for the first group project, and will be writing another blog post on my process.

2. Lab: Servo Motor

Continuing from the previous lab, I just took out all the force sensors but one, and changed the speaker into a motor. Another three-legged component! (see my complaint about three-legged components in last week’s blog). This time it’s much more obvious which wire does which based on their colors: red, power input; black, ground; yellow, connect to output pin. A good reminder that color-coding cables is important.

According to the lab instruction, I included a servo.h library that was already installed in my Arduino software, though not very sure what it did to my code. When I have time I need to look into the servo library and see with my own eyes what it has to offer. I guess it calculates the angles??

Code ran. It moved. Joy of success I tasted.

A failed attempt of mapping AnalogRead to (1, 360) was made right after. Turns out the servo really does not turn beyond 180 degrees.

Reading about motor-related projects after this lab opened my eyes to so many inspirations and possibilities. For as long as I’ve know of ITP I was in awe of Danny Rozin’s wooden mirror. To think about it now, deconstructed as a system with 830 square pieces of wood and 830 servo motors, I’m much more excited and even more curious to explore (and maybe, soon, build) larger scaled mechanical pieces.

Leave a Reply

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