Lab 2 – Group 16

Group Members
Andrew Boik (aboik@)
Brian Huang (bwhuang@)
Kevin Lee (kevinlee@)
Saswathi Natta (snatta@)

Group 16

Description

We built three instruments: Instrument of Light, a light detecting theremin from a photo resistor); Lollipop (it kind of looks like one), a proximity theremin using a capacitive proximity sensor; and La Tromba, a trumpet from three FSRs (for valves) and a flex sensor with wind sail attachment (for simulating airflow). All three worked fairly well, except the trumpet was a little difficult to control and the proximity sensor didn’t have a very wide range. In all three, we used a buzzer for sound, except for the trumpet which used a piezo element initially and then a buzzer in the final version. We ultimately decided to develop the trumpet into our final instrument. We were motivated to build this instrument because one of our group members plays trumpet, and we thought it would be interesting to create an electronic version of the instrument. Our final version featured a buzzer instead of piezo element, and we tuned our flex sensor thresholds so less blowing/bending would be required. The combination of FSRs held down is mapped to actual trumpet notes, and the signal from the flex sensor simulates the partial, so bending it further will result in a higher pitch. Overall we think the final result was a success. We liked that we could actually kind of play a scale and go through the trumpet’s full range with it. Our attachment to the FSR was a little bit of a disappointment because it was nearly impossible to control the sound by blowing on it like you would on a real trumpet, so we ended up manually bending the flex sensor instead.

Video

La Tromba (initial)
Use FSR sensors as 3 buttons for the trumpet and the flex sensors to sense when user blows into the trumpet. Sound is only generated when the flex sensor is bent and certain FSR sensors are pressed

La Tromba (initial) Video

Instrument of Light
Depending on the value that the photo resistor outputs, the tone that the buzzer plays will change.

Instrument of Light Video

Lollipop
Music by proximity: Using a capacitive proximity sensor to moderate which pitch that the buzzer plays. The pitch is higher if a person is closer to the sensor.

Lollipop Video

La Tromba (final)

La Tromba (final) Video

Instructions

Instrument of Light (Photo resistor theremin) – Wire a photocell with a voltage divider, using a 10k resistor to ground, between one pin connected to 5V power and the other pin connected to a Arduino analog input pin to detect the resistance.  Wire a buzzer to a chosen Arduino digital output pin and the shorter end to ground.

La Tromba (FSR and flex sensor trumpet) – Wire 3 FSR sensors using 10k pull down resistors for each. Each combination of buttons will produce a different tone. Wire a flex sensor with a 10K pull down resistor inside a hollow tube and when it is bent by wind being blown, it will allow the buzzer to sound a tone.

Lollipop (Capacitive proximity sensor theremin) Wire a capacitive proximity sensor, which is essentially a bit of aluminum just as in http://playground.arduino.cc//Main/CapacitiveSensor?from=Main.CapSense and connect a buzzer to the arduino to output sound depending on the proximity of the person

 

Materials Used in Final Instrument

1 Arduino
1 Small breadboard
3 FSRs
1 Buzzer
1 Flex sensor
1 Paper wind sensor attachment to flex sensor
4 10K resistors

 

Code

La Tromba

Source Code Here

Instrument of Light

int light_pin = A0;

int speaker_pin = 8;
void setup() {
 Serial.begin(9600);
 pinMode(8, OUTPUT);
}
void loop() {
 while(1) {
 int reading = analogRead(light_pin);
 Serial.println(reading);
 tone(speaker_pin, reading);
 }
}

Lollipop

#include <CapacitiveSensor.h>
/*
 * CapacitiveSense Library Demo Sketch
 * Paul Badger 2008 edited 2013 by Princeton HCI lab group 16
 * Uses a high value resistor e.g. 10 megohm between send pin and receive pin
 * Resistor effects sensitivity, experiment with values, 50 kilohm - 50 megohm. Larger resistor values yield larger sensor values.
 * Receive pin is the sensor pin - try different amounts of foil/metal on this pin
 * Best results are obtained if sensor foil and wire is covered with an insulator such as paper or plastic sheet
 */
/* Modified by Lab Group 16 COS 436 HCI Spring 2013 */
CapacitiveSensor cs_4_2 = CapacitiveSensor(4,2); // 1 megohm resistor between pins 4 & 2, pin 2 is sensor pin, add wire, foil
long sensorValue;
long sensorHigh = 0;
long sensorLow = 2000;
void setup() 
{
 cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibra- //te on channel 1 - just as an example
 Serial.begin(9600);

 // upon starting, we have five seconds to give the proximity
 // detector an upper and lower bound
 while (millis() < 5000) {
 sensorValue = cs_4_2.capacitiveSensor(30);
 if (sensorValue > sensorHigh) {
 sensorHigh = sensorValue;
 }
 if (sensorValue < sensorLow) {
 sensorLow = sensorValue;
 }
 }
 Serial.print("sensorHigh = ");
 Serial.println(sensorHigh);
 Serial.print("sensorLow = ");
 Serial.println(sensorLow);
}
void loop() 
{
 sensorValue = cs_4_2.capacitiveSensor(30);

 // map the sensor values to a wide range of pitches
 int pitch = map(sensorValue, sensorLow, sensorHigh, 1047, 131);

 // play the tone for [duration] ms on pin 8
 tone(8, pitch);
}

 

L2 — Saxobeat

GROUP NAMES: Vivian, Harvest, Neil, Alan

GROUP NUMBER: 25

WHAT WE BUILT:

We played around with capacitive proximity sensing to detect when a user touches the instrument when we considered building 3 music instrument prototypes. We used the same circuit design for a 5-note musical instrument and varied the interface. Each uses aluminum foil in various configurations to play different notes. The first is a guitar tab style device, with aluminum covering stiff paper tabs. The second is a mini piano using pistachio shells to hold clumps of aluminum foil. The final design is a xylophone kit style device, using capacitive sensing with spoons hitting aluminum balls which act as the xylophone bars. We liked the xylophone the best because it had the most interesting visual setup and a comfortable interface, letting users play notes quickly and intuitively. It’s a fun, easy-to-use instrument with a creatively natural use of spoons 🙂

PROTOTYPE #1: GUITAR TABS

The user strums or just simple touches a tab in order to play a corresponding note.

Music: “When the Saints Go Marching In”

PROTOTYPE #2: PISTACHIO PIANO

Pistachio shells are used as the base to hold balls of aluminum. The user touches their finger to each aluminum-covered shell to play a note.

Music: “Turret Opera,” Portal 2

FINAL PROTOTYPE: SAXOBEAT

User holds the round end of the spoon, engaging the capacitive nature of the aluminum material. The round end is connected to the flat tip using a wire, and touching the aluminum balls generates a note.

Music: “Mr. Saxobeat,” Alexandra Stan

LIST OF PARTS:

  • Balls of aluminum (x5)
  • Plastic spoons (x2)
  • Aluminum sheet
  • 10 megaohm resistor (x5)
  • Arduino Uno (x1)
  • Piece of cardboard (x1)
  • Breadboard (x1)
  • Wires

SETUP INSTRUCTIONS: 

  1.  Wrap the round end of the spoon with aluminum. Wrap the thin, flat end of the spoon with aluminum as well. Tape a piece of wire connecting the round and flat end.
  2. Secure the five balls of aluminum to a stiff piece of cardboard using electric tape.
  3. Wire up the arduino. Place the five resistors on the breadboard and connect each end to a digital pin. Connect another end of each resistor to an aluminum ball.
  4. Upload the code and enjoy!

ARDUINO CODE:

// Team Deep Thought
// "Saxobeat" Musical Instrument

#include 

CapacitiveSensor   Eb = CapacitiveSensor(3,2);        // 10 megohm resistor between pins 4 & 2, pin 2 is sensor pin, add wire, foil
CapacitiveSensor   D = CapacitiveSensor(5,4);
CapacitiveSensor   C = CapacitiveSensor(7,6);
CapacitiveSensor   Bb = CapacitiveSensor(9,8);
CapacitiveSensor   A = CapacitiveSensor(12,11);
int spkr = 10;

// Turret Opera
int fA = 440;
int fBb = 466;
int fC = 523;
int fD = 587;
int fEb = 622;

// When the Saints Go Marching In
int wC = 262;
int wD = 294;
int wE = 330;
int wF = 349;
int wG = 392;

// Saxobeat
int sB = 494;
int sCs = 554;
int sD = 587;
int sE = 659;
int sFs = 740;

void setup()                    
{

   A.set_CS_AutocaL_Millis(0xFFFFFFFF);
   Bb.set_CS_AutocaL_Millis(0xFFFFFFFF);
   C.set_CS_AutocaL_Millis(0xFFFFFFFF);
   D.set_CS_AutocaL_Millis(0xFFFFFFFF);
   Eb.set_CS_AutocaL_Millis(0xFFFFFFFF);
   pinMode(spkr, OUTPUT);
   Serial.begin(9600);

}

void loop()
{
    long nA = A.capacitiveSensor(30);
    long nBb = Bb.capacitiveSensor(30);
    long nC = C.capacitiveSensor(30);
    long nD = D.capacitiveSensor(30);
    long nEb = Eb.capacitiveSensor(30);

    // Turret Opera
//    if (nA > 1000) tone(spkr, fA, 80);
//    else if (nBb > 1000) tone(spkr, fBb, 80);
//    else if (nC > 1000) tone(spkr, fC, 80);
//    else if (nD > 1000) tone(spkr, fD, 80);
//    else if (nEb > 1000) tone(spkr, fEb, 80);
//    
//    // Saints 
//    if (nA > 1000) tone(spkr, wC, 80);
//    else if (nBb > 1000) tone(spkr, wD, 80);
//    else if (nC > 1000) tone(spkr, wE, 80);
//    else if (nD > 1000) tone(spkr, wF, 80);
//    else if (nEb > 1000) tone(spkr, wG, 80);

    // Saxobeat
    if (nA > 1000) tone(spkr, sB, 80);
    else if (nBb > 1000) tone(spkr, sCs, 80);
    else if (nC > 1000) tone(spkr, sD, 80);
    else if (nD > 1000) tone(spkr, sE, 80);
    else if (nEb > 1000) tone(spkr, sFs, 80);

}

Lab 2 (The Elite Four)

The Elite Four (#24)
Clay Whetung (cwhetung@)
Jae Young Lee (jyltwo@)
Jeff Snyder (jasnyder@)
Michael Newman (menewman@)

What we built and why:
We built a softpot-based instrument that plays totally rocking guitar solos. It uses a softpot to select frequency and a button that allows sound to be played when pressed. We are collectively fans of not just one specific band, but rather the whole genre of rock ‘n’ roll. We wanted to make sure that all aspects of our instrument went up to 11, right across the board. Therefore, we modified our softpot-based prototype to use the most rocking of all pitch mappings: the blues scale. We were able to achieve a good approximation of many rock classics with our instrument, including “Tonight I’m Gonna Rock You Tonight” and “Stonehenge.” The thing we liked most about the final iteration was its ability to play sick guitar solos as well as classic riffs. Pitch was a little difficult to control precisely with a finger, as we needed a range of two octaves to really rock out, but it was easy to control with precision using a pencil or other stylus-like object. In a future iteration, the ability to play multiple notes at once would help us to rock out even harder. Specifically, the ability to play power chords would help us cement our status as one of F114’s loudest lab groups.

Prototypes:

Prototype 1

Jeff demonstrates our first prototype, a softpot-based instrument.

Jeff demonstrates our first prototype, a softpot-based instrument.

This prototype features a softpot that controls frequency (broken up into discrete notes) and a button that, when clicked, plays a note. By moving a finger along the softpot and simultaneously pressing the button, it’s possible to play simple melodies.

Prototype 2

By flexing his finger, Clay can change the frequency of this instrument.

By flexing his finger, Clay can change the frequency of this instrument.

This prototype features a flex sensor that controls frequency and a button that, when clicked, plays a note. We attached the flex sensor to our subject’s finger so that he was able to play different melodies simply by bending his finger while pressing the button.

Prototype 3

In this prototype, frequency is controlled by a force sensor, and clicking a button allows a note to be played. One can play a tune by squeezing the force sensor with varying degrees of force while simultaneously pressing the button.

The final system:
For the final system, we chose to work with our first prototype: the softpot-based instrument. As before, the button controls when a note is being played, but the mapping of softpot to frequency was altered to allow playing “guitar solos.” Below, we have photos and video of the system in action.

The entire system

The entire system

The final system's Arduino connections

The final system’s Arduino connections

Closeup of the breadboard, with button and speaker

Closeup of the breadboard, with button and speaker

finalphoto5

Closeup of the frequency-controlling softpot

As seen in the video, the system has been refined to allow rockin’ riffs instead of just simple melodies. This change was made by altering the system’s code, not by changing the hardware.

Ingredients:
1 Softpot
1 Speaker
1 Large Button
1 Arduino
Breadboard(s)
Jumper Wires
Tape

Recipe:
0. Insert the softpot, speaker, and button into the breadboard. The speaker and button are most easily inserted spanning the middle divider. You may find it helpful for the following steps to connect ground and +5V to the power rails of the breadboard.
1. Attach the far left pin of the softpot to ground and the far right to +5V. Connect the middle pin to the A0 pin of the Arduino.
2. Connect one side of the speaker to ground and the other to one side of the button. Connect the other side of the button to pin 8 of the Arduino.
3. For added stability, tape the softpot to a hard surface (like the table).

Source code:

/* 
  Authors: jasnyder, cwhetung, menewman, jyltwo
  Date: 3/4/2013
  COS 436 Lab L2: Awesome Electric Guitar Instrument

  Our instrument: By using a softpot, we created something similar
  to a keyboard. We first experimented with a typical scale, and eventually
  chose notes to make a solo electric guitar. There are 10 possible pitches
  mapped by the softpot, and the sound is outputted through the speaker as
  values are continously read in. 
*/

#include "pitches.h"

// Pitches on our guitar
int pitches[] = {NOTE_G5, NOTE_AS5, NOTE_C6, NOTE_DS6, NOTE_F6, 
                 NOTE_FS6, NOTE_G6, NOTE_AS6, NOTE_C7, NOTE_DS7};

//  Musical constants
const int NOTE_DELAY = 300; // ms
const int NOTE_DUR = 250;   // ms

//  Pin connection constants
const int softpot = A1;
const int speaker = 8;

// Softpot reading
int softpotValue = 0;
// Mapped value of softpot
int note = 0;

// Continuously read values from the softpot and output the corresponding tone
void loop() {
  softpotValue = analogRead(softpot);
  note = map(softpotValue, 0, 1023, 0, 9);

  tone(speaker, pitches[note], 1);
}

Lab 2 – Name Redacted

Names: Brian, Matt, Joshua, Ed

Group Number: 20

We built a capacitive piano with four keys. In the final iteration, you can play one note at a time but the sound is continuous for as long as it is pressed. Our creative add on is including a nob (potentiometer) that allows a user to change the pitch. It was successful in that it creates interesting tones and we can push the idea of duets on the same instrument. In the final performance, the two performers performed different duties while simultaneously working together to create a beautiful sound. In the future, we would like to add more dynamic music instead of a single tone. We would also create more roles for additional people to further our idea of multiple individuals performing on the same instrument. Finally, we would like to add some tactile feedback to the capacitive keys so that there is a physical response to the individual playing the music.

Prototype 1: Four capacitor sensors for four different notes. The notes are distinct and played one at a time but if two keys are pressed, they are played sequentially to create pseudo-chords.

// Graphing sketch
//Adapted from http://arduino.cc/en/Tutorial/Graph 

import processing.serial.*;

 Serial myPort;        // The serial port
 int xPos = 1;         // horizontal position of the graph

 int zero_pos;
 int one_pos;
 float max_pos;
 float min_pos;


 
 void setup () {
	 // set the window size:
	 size(1080, 720);
	 max_pos = height; 
	 min_pos = 0;       

	 // List all the available serial ports
	 // println(Serial.list());
	 // I know that the first port in the serial list on my mac
	 // is always my  Arduino, so I open Serial.list()[0].
	 // Open whatever port is the one you're using.
	 myPort = new Serial(this, Serial.list()[0], 9600);
	 // don't generate a serialEvent() unless you get a newline character:
	 myPort.bufferUntil('\n');
	 // set inital background:
	 background(224,228,204); 
	}
	void draw () {
 	// everything happens in the serialEvent()
 }
 
 void serialEvent (Serial myPort) {
	 // get the ASCII string:
	 String inString = myPort.readStringUntil('\n');

	 if (inString != null) {
		 // trim off any whitespace:
		 inString = trim(inString);

		 if (inString.length() != 0) {
		 	String[] sensor_strings = inString.split(" ");

		 	if (sensor_strings.length < 3) {
		 		println("RETURN");
		 		return;
		 	}

		 	float inByte = float(sensor_strings[0]); 
		 	inByte = map(inByte, 0, 1023, 0, height/3);

		 	float yPos = height;
		// draw the line:
		stroke(105,210,231);
		line(xPos, yPos, xPos, yPos - inByte);
		yPos -= (inByte + 1);

		inByte = float(sensor_strings[1]); 
		inByte = map(inByte, 0, 1023, 0, height/3);

		stroke(167,219,216);
		line(xPos, yPos, xPos, yPos - inByte);
		yPos -= (inByte + 1);


		inByte = float(sensor_strings[2]); 
		inByte = map(inByte, 0, 1023, 0, height/3);

		stroke(250, 105, 0);
		line(xPos, yPos, xPos, yPos - inByte);


		if ((yPos-inByte)  min_pos) {
			min_pos = yPos-inByte;
		}
		drawMax(max_pos);
		drawMax(min_pos);


		 // at the edge of the screen, go back to the beginning:
		 if (xPos >= width) {
		 	xPos = 0;
		 	max_pos = yPos-inByte;
		 	min_pos = yPos-inByte;
		 	background(224,228,204); 
		 } 
		 else {
		 // increment the horizontal position:
		 xPos++;
		}
	}
}
}

void drawMax(float max_pos) {
	stroke(255, 0, 0);
	ellipse(xPos, max_pos, 2, 2);
}

Prototype 2: We are extending prototype 1 but now have a potentiometer that shifts the tone of all of the notes. This allows the instrument to have a larger range than just the four notes presented.

#include <CapacitiveSensor.h>


/*
 * CapitiveSense Library Demo Sketch
 * Paul Badger 2008
 * Uses a high value resistor e.g. 10 megohm between send pin and receive pin
 * Resistor effects sensitivity, experiment with values, 50 kilohm - 50 megohm. Larger resistor values yield larger sensor values.
 * Receive pin is the sensor pin - try different amounts of foil/metal on this pin
 * Best results are obtained if sensor foil and wire is covered with an insulator such as paper or plastic sheet
 */
 
int speakerPin = 7;
int knobPin = 1;
int knobVal = 0;

int threshold = 3000;


CapacitiveSensor   cs_0 = CapacitiveSensor(3,8);        // 10 megohm resistor between pins 4 & 2, pin 2 is sensor pin, add wire, foil

CapacitiveSensor   cs_2 = CapacitiveSensor(2,10);        // 10 megohm resistor between pins 4 & 2, pin 2 is sensor pin, add wire, foil

CapacitiveSensor   cs_4 = CapacitiveSensor(4,12);        // 10 megohm resistor between pins 4 & 2, pin 2 is sensor pin, add wire, foil

CapacitiveSensor   cs_6 = CapacitiveSensor(6,13);        // 10 megohm resistor between pins 4 & 2, pin 2 is sensor pin, add wire, foil

void playTone(int tone, int duration) {
  for (long i = 0; i < duration * 1000L; i += tone * 2) {
    digitalWrite(speakerPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite(speakerPin, LOW);
    delayMicroseconds(tone);
  }
}

void playNote(char note, int duration) {
  char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
  int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };

  // play the tone corresponding to the note name
  for (int i = 0; i  threshold) {
     playNote('c', 100); 
    }
    
    if (total_2 > threshold) {
     playNote('d', 100); 
    }
    
    if (total_4 > threshold) {
     playNote('e', 100); 
    }
    
    if (total_6 > threshold) {
     playNote('f', 100); 
    }
    

//    Serial.print(millis() - start);        // check on performance in milliseconds
//    Serial.print("\t");                    // tab character for debug windown spacing
//
//    Serial.println(total);                  // print sensor output 1
    

    delay(10);                             // arbitrary delay to limit data to serial port 
}

Prototype 3: We extending prototypes 1 and 2 so that now the notes play continuously until the user releases his/her finger from the key. The potentiometer can shift the note while it is playing.

#include <CapacitiveSensor.h>


/*
 * CapitiveSense Library Demo Sketch
 * Paul Badger 2008
 * Uses a high value resistor e.g. 10 megohm between send pin and receive pin
 * Resistor effects sensitivity, experiment with values, 50 kilohm - 50 megohm. Larger resistor values yield larger sensor values.
 * Receive pin is the sensor pin - try different amounts of foil/metal on this pin
 * Best results are obtained if sensor foil and wire is covered with an insulator such as paper or plastic sheet
 */
 
int speakerPin = 7;

int knobPin = 1;

int threshold = 5000;

int knobVal = 0;


CapacitiveSensor   cs_0 = CapacitiveSensor(3,8);        // 10 megohm resistor between pins 4 & 2, pin 2 is sensor pin, add wire, foil

CapacitiveSensor   cs_2 = CapacitiveSensor(2,10);        // 10 megohm resistor between pins 4 & 2, pin 2 is sensor pin, add wire, foil

CapacitiveSensor   cs_4 = CapacitiveSensor(4,12);        // 10 megohm resistor between pins 4 & 2, pin 2 is sensor pin, add wire, foil

CapacitiveSensor   cs_6 = CapacitiveSensor(6,13);        // 10 megohm resistor between pins 4 & 2, pin 2 is sensor pin, add wire, foil

void playTone(int tone, int duration) {
  for (long i = 0; i < duration * 1000L; i += tone * 2) {
    digitalWrite(speakerPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite(speakerPin, LOW);
    delayMicroseconds(tone);
  }
}

void playNote(char note, int duration) {
  char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
  int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };

  // play the tone corresponding to the note name
  for (int i = 0; i  threshold) {
     note_playing = true;
     playNote('c', 100); 
    }
    
    if (total_2 > threshold) {
     note_playing = true;
     playNote('d', 100); 
    }
    
    if (total_4 > threshold) {
     note_playing = true;
     playNote('e', 100); 
    }
    
    if (total_6 > threshold) {
     note_playing = true;
     playNote('f', 100); 
    }
    
    if (!note_playing) {
     noTone(speakerPin); 
    }
    

//    Serial.print(millis() - start);        // check on performance in milliseconds
//    Serial.print("\t");                    // tab character for debug windown spacing
//
//    Serial.println(total);                  // print sensor output 1
    

    delay(10);                             // arbitrary delay to limit data to serial port 
}

List of parts:
4 1MegaOhm resistor
1 potentiometer

4 pieces of aluminum foil
4 alligator clips
1 Arduino
1 Buzzer

Detailed Instructions:
To make the keyboard, tape four strips of foil to a piece of paper, making sure to leave one end lose so you can connect them later and the top of the other end exposed so you can actually touch the foil. To make the key sensors themselves, take a 10M Ohm resistor and connect it to a digital output pin. Then connect the other end to a digital input pin. Connect one end of an alligator clip to the input-side of the resistor and connect the other end to the exposed end of one of the pieces of foil. Repeat this process for the three other keys.
For the pitch control, take a potentiometer and connect one pin to 5V, the middle pin to an analog input pin, and the last pin to ground.

L2 – Dohan Yucht Cheong Saha

Team Members:

  • Andrew Cheong (acheong@)
  • David Dohan (ddohan@)
  • Shubhro Saha (saha@)
  • Miles Yucht (myucht@)

Group Number: 21

Description

For our project, we built an instrument that allows a person to conduct the tempo of a piece of music by walking. The primary components of the instrument are piezos attached to each foot and two buzzers. Taking a step moves the song along to the next note, and each song can have both a bass and treble part play simultaneously. We built this project because we like the idea of being able to control existing music through motion. We are pleased overall with the final product because it works as we envisioned it and is actually pretty fun to use. There are a number of possible improvements that we would like to add, including the ability to change to different songs and read music from arbitrary midi files. Additionally, the device is somewhat difficult to attach to your body: perhaps this could be made more portable by the use of a piezo sensor integrated into your shoes (along with a battery pack for the Arduino). We are also limited to songs which change on each tap of the foot, as opposed to songs that might have several pitches play per beat. Other possibilities would be to synthesize the sound using processing or use a similar interface to create music (e.g. a different drum for each foot) as opposed to controlling existing music.

Prototypes

Before building out final product, we built three separate prototypes, with the third leading to our final product.

Instrument 1 – Conducting a Choir

When building our first prototype, we set out to be able to control the volume and pitch of a song by raising and lowering our hands (as if conducting a musical group). While the final result worked, it did not perform as well as we had hoped. The main issue with the instrument is that it is difficult to properly estimate changes in position from the accelerometer (although it naturally works very well for detecting actual accelerations).

Instrument 2 – Anger Management

We liked the idea of using the force of a knock on a piezo to control sound. In this project, hitting your computer results in it playing sound back at you that corresponds to how hard you hit it.

Instrument 3 – Walking Conductor

This prototype is the core of our final instrument and is composed of piezos attached to each foot and a beeper. Knocks (e.g. steps) on the piezos trigger the next note in a melody to play.

 

Final Instrument

We decided to modify the walking conductor instrument to allow multiple parts to play at once. The control mechanism remained the same, but the addition of a second beeper allows us to play a bass part at the same time as the melody.

Parts list:

  • 2 piezo elements
  • 2 beepers
  • 2 rotary potentiometers
  • 2 1-megaohm resistors
  • 1 Arduino Uno
  • 4+ alligator clip cables
  • Electrical tape

Assembly Instructions:

  1. On a breadboard, connect one end of one resistor to analog pin A0 and the other end to ground. Connect one end of other resistor to analog pin A1 and the other end to ground.
  2. Connect one piezo element in parallel with each resistor, attaching it to the breadboard using the alligator clip cables.
  3. On a breadboard, connect pin 1 of one potentiometer to digital pin 3, pin 2 to one beeper, and pin 3 to ground. Connect pin 1 of the other potentiometer to digital pin 6, pin 2 to the other beeper, and pin 3 to ground.
  4. Connect the other pins on each beeper to ground.
  5. Attach the piezo elements to your shoes using electrical tape.
  6. Run around to your favorite song!

Source Code Instructions:

  1. This code makes use of the “Arduino Tone Library” which allows one to play multiple notes simultaneously using the arduino. It is required to run our code, so download it using the link above. The library comes from the Rogue Robotics project.
  2. Download our code below, and begin controlling Thus Spoke Zarathustra as you walk! Different music can be played by replacing the trebleNotes and bassNotes arrays with different note sequences.

Code:

/*
 * COS 436 Lab 2: Sensor Playground
 * Author: Miles Yucht, David Dohan
 * Plays "Thus Spoke Zarathustra" by Richard Strauss on beats measured by piezo elements.
 */
#include "pitches.h"
#include "Tone.h"
#ifdef REST
# undef REST
#endif
#define REST -1

Tone bassTone;
Tone trebleTone;

int treblePin = 3;
int bassPin = 6;
int piezoPin1 = A0;
int piezoPin2 = A1;

int threshold = 50;

int currentNote = 0;

int pauseTime = 100;

//melody to Thus Spoke Zarathustra
int trebleNotes[] = {NOTE_C4, NOTE_G4, NOTE_C5, REST, NOTE_E5, NOTE_DS5, REST, REST, REST, REST, REST, REST, REST, REST, REST, REST, REST, REST, 
    NOTE_C4, NOTE_G4, NOTE_C5, REST, NOTE_DS5, NOTE_E5, REST, REST, REST, REST, REST, REST, REST, REST, REST, REST, REST, REST, NOTE_C4, NOTE_G4,
    NOTE_C5, REST, NOTE_E4, NOTE_A4, NOTE_A4, NOTE_B4, NOTE_C5, NOTE_D5, NOTE_E5,
    NOTE_F5, NOTE_G5, NOTE_G5, NOTE_G5, NOTE_E5, NOTE_F5, NOTE_G5, NOTE_A5, NOTE_B5, NOTE_C6, REST};

//bassline to Thus Spoke Zarathustra
int bassNotes[] = {NOTE_C4, NOTE_C4, NOTE_C4, NOTE_C4, NOTE_C4, NOTE_C4, NOTE_C4, NOTE_G3, NOTE_C4, NOTE_G3, NOTE_C4, NOTE_G3, NOTE_C4, NOTE_G3, 
NOTE_C4, NOTE_G3, NOTE_C4, NOTE_G3, NOTE_C4, NOTE_C4, NOTE_C4, NOTE_C4, NOTE_C4, NOTE_C4, NOTE_C4, NOTE_G3, NOTE_C4, NOTE_G3, NOTE_C4, NOTE_G3, NOTE_C4, NOTE_G3, 
NOTE_C4, NOTE_G3, NOTE_C4, NOTE_G3, NOTE_C4, NOTE_C4, NOTE_C4, NOTE_C4, NOTE_C4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_C4, NOTE_C4, NOTE_G4, NOTE_E4,
NOTE_C4, NOTE_G3, NOTE_G3, NOTE_E3, NOTE_A3, NOTE_G3, NOTE_C4, REST};

void waitForKnock() {
  int sense1, sense2;  
  while (true) {
      sense1 = analogRead(piezoPin1);
      sense2 = analogRead(piezoPin2);
      if (sense1 > threshold || sense2 > threshold)
        break;
      /*
      Serial.print(threshold - sense1);
      Serial.print(", ");
      Serial.println(threshold - sense2);
      */
    }
    /*
    Serial.println(sense1);
    Serial.println(sense2);
    */
}

void playTone(Tone tone, int notes[]) {
  if (notes[currentNote] == REST)
    tone.stop();
  else
    tone.play(notes[currentNote]);
}

void playNextNote() {
  if (currentNote <= 57) {
    playTone(trebleTone, trebleNotes);
    playTone(bassTone, bassNotes);
  } else
    currentNote = -1;
  currentNote++;
}

void setup() {
  bassTone.begin(3);
  trebleTone.begin(6);
  /*
  Serial.begin(9600);
  */
}

void loop() {
    waitForKnock();
    playNextNote();
    delay(pauseTime);
}

Lab 2 – Team Chewie (Chewbacca)

Team Members
Stephen Cognetta (cognetta@)
Eugene Lee (eugenel@)
Jean Choi (jeanchoi@)
Karena Cai (kcai@)

Group Number: 14

Description
Our musical instrument was a head-banging music maker. The accelerometer, which is attached to a hat, detects when the user has done a sudden motion (like head banging). When this motion is detected, the tempo of the song that is playing will match the rate at which you are banging your head. By varying the location of touch along a linear sensor, the pitch of the song can also be changed. We thought that our project was a success because we were able to become familiar with the accelerometer while also making a cool project that created music with the motion of the user’s body. As an extension of this project, we could somehow attach the accelerometer to someone’s feet so that when they exercised, the beat of the music would match the rate at which they were running. We also thought that our design could be improved so it was less visible and less bulky.

PROTOTYPE 1 : Ambient Music Generator

This instrument by default emits an ambient noise. When a sudden jerk in the accelerometer is detected, it will emit a dolphin noise. Such a device could be attached to children’s toys that make playing with toys even more fun!
Used CHuck and Processing.
PROTOTYPE 2 : Two-Dimensional Music Player

This instrument uses a two-dimensional sensing technique to change both the pitch and the tempo of a song. If force is applied to the FSR, the tempo decreases. Meanwhile, by sliding the FSR along the soft potentiometer (linear sensor), the pitch will vary.

Head-Banging Music Maker. Final project for this lab. We created a hat that would respond to the movements of the head, if the head jerks fast, the music would play faster, and vice versa. It won’t play at all if the head isn’t moved.

List of Parts
– Arduino Uno
– jumper wires
– accelerometer
– Buzzer
– Hat

Instructions on how to recreate the Head-Banging Music Maker
We attach the buzzer and accelerometer to the device as shown in the picture below. (basically, the accelerometer is wired in as was done in Step 5 of the lab, using the AREF pin, and the buzzer is hooked up to the arduino board). Then attach to the hat as shown. Most of the work is performed in the code, which is shown below.

ttt

hat

Head Bangin’ Source Code

/*
  Graph

 A simple example of communication from the Arduino board to the computer:
 the value of analog input 0 is sent out the serial port.  We call this "serial"
 communication because the connection appears to both the Arduino and the
 computer as a serial port, even though it may actually use
 a USB cable. Bytes are sent one after another (serially) from the Arduino
 to the computer.

 You can use the Arduino serial monitor to view the sent data, or it can
 be read by Processing, PD, Max/MSP, or any other program capable of reading 
 data from a serial port.  The Processing code below graphs the data received 
 so you can see the value of the analog input changing over time.

 The circuit:
 Any analog input sensor is attached to analog in pin 0.

 created 2006
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe and Scott Fitzgerald

 This example code is in the public domain.

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

// ******************************************************
// CHORD INITIALIZATION
// ******************************************************

const int C = 24,
          D = 27,
          E = 30,
          F = 32,
          G = 36,
          A = 40,
          B = 45,
          C2 = 48,
          H = 0;

int twinkleStar[] = { C, C, G, G, A, A, G, H,
                      F, F, E, E, D, D, C, H,
                      G, G, F, F, E, E, D, H,
                      G, G, F, F, E, E, D, H,
                      C, C, G, G, A, A, G, H,
                      F, F, E, E, D, D, C, H};
int songLength = 48;
int songStep = 0;

int singleNote[] = { 1, 1, 1, 1 };
int majorChord[] = { 4, 5, 6, 0 };
int minorChord[] = { 10, 12, 15, 0 };
int seventhChord[] = { 20, 25, 30, 36 };
int majorChordLength = 3;
int *chords[] = { singleNote, majorChord, minorChord, seventhChord };
const int chordsLength = 4;

int chordType = 0;                // changes between chords[]
int arpStep = 0;                  // changes between chord frequencies

// ******************************************************
// INPUT INITIALIZATION
 // ******************************************************
const int linPin = A1;
const int xPin = A5;
const int yPin = A4;
const int zPin = A3;
const int tonePin = 10;
const int groundpin = A2; // analog input pin 2
const int powerpin = A0; // analog input pin 0
const int proxPin = A6; // analog input pin 6

// ******************************************************
// MAIN LOOP
// ******************************************************

unsigned int tempo;
unsigned int frequency;
unsigned int chordFrequency;
int currentBang;
int bangInterval = 0;
int minimumBangInterval = 70;
int maximumBangInterval = 200;

void setup() {
  // initialize the serial communication:
  Serial.begin(9600);

  pinMode(groundpin, OUTPUT);
 pinMode(powerpin, OUTPUT);
 digitalWrite(groundpin, LOW); 
 digitalWrite(powerpin, HIGH);
}

int prevX = 400;
boolean rising = false;
boolean falling = false;
int mini, maxi, diff;

void loop() {
  int linReading = analogRead(linPin);
  int xReading = analogRead(xPin);
  int yReading = analogRead(yPin);
  int zReading = analogRead(zPin);

  // send the value of analog input 0:
  //int potReading = analogRead(potPin);
 // int btnReading = digitalRead(btnPin);
  // send the value of analog input 0:

  // wait a bit for the analog-to-digital converter 
  // to stabilize after the last reading:
  delay(2);

  int x, y, z;
  x = xReading;
  y = yReading;
  z = zReading;
  if (prevX < x) {
    rising = true;
    falling = false;
  } else {
    rising = false;
    falling = true;
  }
  prevX = x;
  if (falling == true)    mini = x;
  if (rising == true)     maxi = x;
  diff = maxi - mini;

  /*Serial.print(x);
  Serial.print("\t");
  Serial.print(prevX);
  Serial.print("\t");
  Serial.print(mini);
  Serial.print("\t");
  Serial.print(maxi);
  Serial.print("\t");
  Serial.println(diff);*/

  int * chord = twinkleStar;

  //measure the time
  if (bangInterval < maximumBangInterval)     bangInterval++;   //when head bang is detected      if (diff > 80 && bangInterval > minimumBangInterval) {
    currentBang = bangInterval;
    bangInterval = 0;

  //  Serial.print(tempo);
  //  Serial.print(",");
    Serial.println(chordFrequency);

    unsigned int tempo = currentBang*2;
    unsigned int duration = tempo - tempo / 20;

    float chordFactor = (float)chord[songStep] / (float)chord[0];
    if (linReading < 1020)
      frequency = 500;
    chordFrequency = frequency * chordFactor;
    tone(tonePin, chordFrequency, duration);

     Serial.print(songStep);
    Serial.print(" ");
    Serial.print(chordFrequency);
    Serial.print(" ");
    Serial.print(chordFactor);
    Serial.print(" ");
    Serial.println(currentBang);

    delay(tempo);
    songStep = songStep < songLength - 1 ? songStep + 1 : 0;

     chordFactor = (float)chord[songStep] / (float)chord[0];
    /*if (linReading < 1020)
      frequency = linReading;*/
      frequency = 500;
    chordFrequency = frequency * chordFactor;
    tone(tonePin, chordFrequency, duration);

    Serial.print(songStep);
    Serial.print(" ");
    Serial.print(chordFrequency);
    Serial.print(" ");
    Serial.print(chordFactor);
    Serial.print(" ");
    Serial.println(currentBang);

    songStep = songStep < songLength - 1 ? songStep + 1 : 0;
  }

}

L2 – Team EyeWrist

Team Members: Evan Strasnick, Joseph Bolling, Xin Yang Yak, Jacob Simon

Group Number: 17

What We Built: We built a system that overlays tunes on top of a bass beat, using an accelerometer to select notes from within a given chord so that the result is always in tune for a specific key. A rotary pot allows the user to control the tempo, a push button on the larger breadboard varies the chord being used – either to toggle to the next set of notes or to modulate the sound through a continuous hold, the accelerometer picks out a note from within the currently selected chord, and the push button on the hand-held component plays the tune. To play our musical instrument, the user simply holds the hand-held controller (the smaller breadboard) in one hand and presses the button to create sound while controlling pitch via rotation. The user can also vary the tempo with the Tempo Knob and change the chord by pressing the Chord Progression button. For our demonstration, we chose a CM, FM, GM chord progression, but the instrument could theoretically support any arrangement or number of chords the user desires. This instrument was not only a success in terms of offering a number of ways in which the user could create an original beat, but it was also surprisingly  addicting to play. We would have liked to use more speaker elements to offer different instrumental options as well.

Prototypes:

1) Our first prototype was a simple mapping of the accelerometer tilt to allow the user to play melodies over a certain range of musical pitches. While this offered the most control over pitch in theory, we wanted the user to not have to worry so much about tilting correctly for the pitches that they wanted, allowing them to focus more on the beat that they were dropping. This philosophy inspired our next design…  http://www.youtube.com/watch?v=2g6CM7rNnuk&feature=youtu.be

2) Our second prototype instead preserved the fun of using the accelerometer to play, but aided the user by mapping its output to the notes within specific chords. After adding in the push button users were able to program in their own chord progressions for a given song and then simply iterate through them. http://www.youtube.com/watch?v=VkYfAKPzM4Q&feature=youtu.be

3) Our third prototype added in a constant bassline, which was always tuned to match the accelerometer’s output, keeping things easy for the user. Further, we added a potentiometer which allowed the user to control tempo. http://www.youtube.com/watch?v=C6CM0272D44&feature=player_detailpage#t=23s

 

Final Performance: Entitled “Lab 2 in A Minor,” this piece is a satire on satire, and a celebration of celebratory pieces (and poor percussionists). Enjoy: http://www.youtube.com/watch?v=QrFFuBdYg8k&feature=youtu.be

 

Parts Used:

Wires + Crocodile clips
Arduino
Accelerometer
Buzzer
Piezo element
2 push buttons
1 rotary pot
1 * 220 ohm resistor
1 * 330 ohm resistor

Instructions to Recreate:

To build our instrument, mount the accelerometer and a push button on a small breadboard or other device that can be held and manipulated with one hand.  Connect the accelerometer Vin, 3Vo, Gnd, and Yout to the A0, A1, A2, and A4 pins on the Arduino, respectively.  Ground one terminal on the pushbutton, and connect the other to the Arduino’s digital pin 2.  Be sure to keep your wiring tight on this section-You may want to bundle your wires out of the way and secure the connections with electrical tape or solder, as this part of the device will be moving a lot as you play.

Connect the buzzer in series with a 220Ω resistor between ground and digital pin 3.  Use alligator clips to connect the piezo element between digital pin 3 and ground.  These two components will produce your sound, so feel free to experiment with different physical setups to see what kind of tonality you can get- we found that covering the sound hole on our buzzer actually made it considerably louder.

Mount the second pushbutton and the potentiometer on a separate breadboard.  Ground one leg of the pushbutton, and connect the other to digital pin 4 on the Arduino. Connect the center leg of the potentiometer to pin A5, and connect the outer two legs to the Arduino’s +5V and Gnd pins.  When wiring this section, try to keep your wiring tight and out of the way- you’ll want to have uninhibited access to the pushbutton and potentiometer as you play. Then just upload our code to your Arduino and have fun!

 

Source Code:

/*
::::::::::::::
PIN LAYOUT
::::::::::::::
*/

// Accelerometer's power & ground pins
const int groundpin = A2;
const int powerpin = A0;

// Accelerometer's Y axis
const int ypin = A4;
const int tempopin = A5;

// Speaker pins ===
const int piezopin = 3;
const int buzzerpin = 5;

// Button pins ===
const int buttonpin = 2;
const int chordpin = 4;

int** progression;
int chordindex;
int basscounter;

boolean basson;
boolean buttonpressed;

/*
::::::::::::::
MUSIC VARS
::::::::::::::
*/

int scaleN = 8;
int chordN = 4;

// C Major Scale: c, d, e, f, g, a, b, c
int CMajorScale[] = {3830, 3400, 3038, 2864, 2550, 2272, 2028, 1915};
char CMajorScaleNotes[] = "cdefgabc";

// C Major Chord: c, e, g, c
int CMajor[] = {3830, 3038, 2550, 1915};
char CMajorNotes[] = "cegc";

// G Major Chord: g, b, d, f
int GMajor[] = {5100, 4056, 3400, 2864};
char GMajorNotes[] = "gbdf";

// F Major Chord: f, a, c, f
int FMajor[] = {2864, 2272, 1915, 1432};
char FMajorNotes[] = "facd";

// A Minor Chord: a, c, e, g
int AMinor[] = {4544, 3830, 3038, 2550};
char AMinorNotes[] = "aceg";

int* CFCAC[] = {CMajor, FMajor, CMajor, AMinor, CMajor};
int* CFCGC[] = {CMajor, FMajor, CMajor, GMajor, CMajor};

/*
::::::::::::::
SETUP
::::::::::::::
*/

void setup() {

// initialize the serial communications:
Serial.begin(9600);

pinMode(groundpin, OUTPUT);
pinMode(powerpin, OUTPUT);
digitalWrite(groundpin, LOW);
digitalWrite(powerpin, HIGH);

// Input pins
pinMode(ypin, INPUT);

pinMode(buttonpin, INPUT);
digitalWrite(buttonpin, HIGH);
pinMode(chordpin, INPUT);
digitalWrite(chordpin, HIGH);

// Output pins
pinMode(buzzerpin, OUTPUT);
pinMode(piezopin, OUTPUT);

progression = CFCGC;
chordindex = 0;
basson = true;
basscounter = 0;

}

/*
::::::::::::::
FUNCTIONS
::::::::::::::
*/

// ===
#define THRESHOLD 270

// Returns a value between lo and hi
// by taking in and subtracting the threshold
int mapToRange(int in, int lo, int hi) {

// Subtract threshold value
int result = in - THRESHOLD;

if (result > hi) return hi;
else if (result < lo) return lo;
else return result;

}

//
int convertToTone(float value, float range, int* notes, int n) {

// do this until we find something better

if (value >= range)
return notes[n-1];

int i = (value / range) * n;
return notes[i];

}

// Plays a note with period through speaker on pin
void playTone(int period, int duration, int pin) {

// Time between tone high and low
int timeDelay = period / 2;

for (long i = 0; i < duration * 1000L; i += period * 2) {
digitalWrite(pin, HIGH);
delayMicroseconds(timeDelay);
digitalWrite(pin, LOW);
delayMicroseconds(timeDelay);
}
}

void playTwoTones(int period, int duration, int pin, int bassperiod, int basspin) {

// Time between tone high and low
int timeDelay = period / 2;

for (long i = 0; i < duration * 1000L; i += period * 2) {
if (buttonpressed) {
digitalWrite(pin, HIGH);
}
if (basson) {
digitalWrite(basspin, HIGH);
}
delayMicroseconds(timeDelay);
if (basson) {
digitalWrite(basspin, LOW);
}
if (buttonpressed) {
digitalWrite(pin, LOW);
}

delayMicroseconds(timeDelay);
}
}

// Not using this right now but keeping for reference
void playNote(char note, int duration) {

char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };

// play the tone corresponding to the note name
for (int i = 0; i < 8; i++) {
if (names[i] == note) {
playTone(tones[i], duration, buzzerpin);
}
}
}

/*
::::::::::::::
MAIN LOOP
::::::::::::::
*/

void loop() {

basscounter++;
if (basscounter == 4)
{
basscounter = 0;
}
if (basscounter == 0)
{
basson = true;
}
else basson = false;

if (digitalRead(chordpin) == LOW) {
chordindex++;
if (chordindex == 4) chordindex = 0;
}

// Play sounds if the button is pressed
buttonpressed = (digitalRead(buttonpin) == LOW);

Serial.println("Button pressed!");

// Analog Read
int analog = analogRead(ypin);
int tempo = analogRead(tempopin) + 10;

// Debug: Print the analogRead value
Serial.print("AnalogRead: ");
Serial.println(analog);

// Map the Y-axis value to the range [0, 250]
float yValue = mapToRange(analog, 0, 135);

// Calculate the tone (period value)
int tone = convertToTone(yValue, 135, progression[chordindex], chordN);
int basstone = progression[chordindex][0];

// Debug: Print out the yValue and tone (period)
Serial.print("yValue: ");
Serial.println(yValue);
Serial.print("tone: ");
Serial.println(tone);
Serial.println("------------");

// Actually produce some sound!
playTwoTones(tone, 100, piezopin, basstone, buzzerpin);

// Delay before next reading:

delay(tempo);

}

Team X – Lab 2

Group 10:

  • Osman Khwaja (okhwaja)
  •  (av)
  • Igor Zabukovec (iz)
  • Junjun Chen (junjunc)

Prototype 1: The Buzz Drum

The piezo element picks up knocks (of varying loudness), causing the buzzer to buzz.

This prototype uses the Piezo sensor and a buzzer. When the piezo sensor senses a vibration, like when we knock on the surface, it sends a signal to the Arduino which then causes the buzzer to buzz. So, essentially, when you drum it, it buzzes.

 

Prototype 2: The Flex Buzz

The flex sensor changes the frequency of the buzzer tone.

This prototype uses the buzzer and the flex sensor. When the sensor is flexed, the tone of the buzzer was changed. In theory, it sounded like a good idea. In reality, we didn’t have much control over the flex sensor’s output values and the change in the buzzer was not as apparent as we had hoped.

Final Prototype/Prototype 3: DJ Breadboard

Our last prototype uses a potentiometer, accelerometer, and a button all located on the breadboard to control the output sound from the computer.

We thought this would be really cool because, using a couple of sensors, we could control many different aspects of the sound. The potentiometer controls frequency of the synthesized sound (just a triangle wave and a sine wave together). The x and y axis of the accelerometer control the left-right panning of the triangle and sine wave, respectively.  Lastly, the button fades the sound in or out. We used Arduino and Processing’s Sound Module (Minim)
Final System Parts:

  1. Arduino + USB cord + Breadboard
  2. Wires
  3. 1 10 kohm resistor
  4. 1 ADXL335 accelerometer
  5. 1 Button
  6. 1 Rotary Potentiometer

Instructions:

Connect the accelerometer to the Arduino (Vin to A0, 3Vo to A1, Gnd to A2, Yout to A4, Xout to A5). Note that we don’t connect Zout to the Arduino, as we won’t be using the Z axis, and we need A3 for the rotary pot. Connect the button to digital pin 2 (as well as 5V and the 10kohm resistor to ground).  Connect the rotary pot to A3 (and 5V and ground). Run the following code in Arduino and Processing

Arduino Code:

// these constants describe the pins. They won’t change:

const int groundpin = A2; // analog input pin 2

const int powerpin = A0; // analog input pin 0

const int xpin = A5; // x-axis of the accelerometer

const int ypin = A4; // y-axis

// const int zpin = A3; // z-axis

const int pot = A3;

const int button = 2;

void setup()

{

// initialize the serial communications:

Serial.begin(9600);

// Provide ground and power by using the analog inputs as normal

// digital pins. This makes it possible to directly connect the

// breakout board to the Arduino. If you use the normal 5V and

// GND pins on the Arduino, you can remove these lines.

pinMode(groundpin, OUTPUT);

pinMode(powerpin, OUTPUT);

pinMode(button, INPUT);

pinMode(pot, INPUT);

digitalWrite(groundpin, LOW);

digitalWrite(powerpin, HIGH);
establishContact();

}

void loop()

{
if (Serial.available() > 0) {
// print the sensor values:
double b = (digitalRead(button) == HIGH) ? 1 : 0;

double a = analogRead(pot) / 1023.0;

double x = (343.0 – analogRead(xpin)) / (413.0 – 343.0);

double y = (341.0 – analogRead(ypin)) / (411.0 – 341.0);
Serial.print(x);

// print a tab between values:

Serial.print(“,”);

Serial.print(y);

Serial.print(“,”);

Serial.print(b);

Serial.print(“,”);

Serial.println(a);

}
}

// Establish contact with processing.
void establishContact() {
// Send an initial string until connection made
while (Serial.available() <= 0) {
Serial.println(“0,0,0”);
delay(300);
}
}

Processing Code:

import ddf.minim.*;
import ddf.minim.signals.*;
import controlP5.*;
import processing.serial.* ;

Serial port;

Minim minim;
AudioOutput out;
SineWave sine;
TriangleWave tri;
ControlP5 gui;

public float triAmp = 0.5;
public float triPan = 0;
public float triFreq = 880;

public float sinAmp = 0.5;
public float sinPan = 0.5;
public float sinFreq = 440;

void setup()
{
size(512, 400, P3D);
minim = new Minim(this);
// get a stereo line out from Minim with a 2048 sample buffer, default sample rate is 44100, bit depth is 16
out = minim.getLineOut(Minim.STEREO, 2048);
// create a sine wave Oscillator, set to 440 Hz, at 0.5 amplitude, sample rate 44100 to match the line out
sine = new SineWave(440, 0.5, out.sampleRate());
// set the portamento speed on the oscillator to 200 milliseconds
sine.portamento(200);
// add the oscillator to the line out
out.addSignal(sine);
// create a triangle wave Oscillator
tri = new TriangleWave(880, 0.5, out.sampleRate());
tri.portamento(200);
out.addSignal(tri);

// set up the gui
gui = new ControlP5(this);
gui.addKnob(“triFreq”, 40, 5000, 10, 250, 60);
gui.addKnob(“triAmp”, 0, 1, 0.5, 85, 250, 60);
gui.addKnob(“triPan”, -1, 1, 0, 165, 250, 60);
gui.addKnob(“sinFreq”, 40, 5000, 280, 250, 60);
gui.addKnob(“sinAmp”, 0, 1, 0.5, 355, 250, 60);
gui.addKnob(“sinPan”, -1, 1, 0, 430, 250, 60);

/* Get serial data. */
println(“Available serial ports:”);
println(Serial.list());

port = new Serial(this, Serial.list()[0], 9600);

port.bufferUntil(‘\n’); /* Read in one line at a time. */
delay(1000);

}

void draw()
{
background(0);
gui.draw();
stroke(255);
// draw the waveforms

}

void stop()
{
out.close();
minim.stop();

super.stop();
}

void serialEvent(Serial port) {

String myString = port.readStringUntil(‘\n’); /* Read in a line. */
myString = trim(myString); /* Remove leading / tailing whitespace. */
float sensors[] = float(split(myString, ‘,’));

if (sensors.length == 4) {
tri.setFreq(sensors[3] * 1000);
tri.setAmp(triAmp);
tri.setPan(sensors[0]);
sine.setFreq(sensors[3] * 1000);
sine.setAmp(sinAmp);
sine.setPan(sensors[1]);

if (sensors[2] < 0.5) { tri.setAmp(0); sine.setAmp(0); } if (sensors[2] > 0.5) {
tri.setAmp(1);
sine.setAmp(1);
}

// Print out sensor values:
for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) {
print(“Sensor ” + sensorNum + “: ” + sensors[sensorNum] + “\t”);
}
println();
}

port.write(“A”); // Send byte to get more data from Arduino program.
}

Lab 2 – Team Cake

Members: Connie, Angie, Kiran, Edward
Lab Group 13

We built two sets of hardware interfaces: our final instrument was a wind instrument that played chords when you blew into “pipes” (straws), and our alternate interface was a “force-sensitive softpot” that combined the two sensors into a single control element. In our final instrument, we blew on a thermistor to change its temperature and combined three of these to create a wind-like instrument. We liked the weirdness of using heat to play music, as well as the quirky design: we used straws as the blowholes on our Arduino. The simple but exotic interface also lent itself well to our eerie synthesis mappings. However, it would have been better if we could have had a larger array of thermistors. Then, instead of mapping each thermistor change to a scale of notes, we could have done more complicated things and given the user more control. All in all, we were very satisfied with the sounds created by our final instrument – the ambiance that it gave off was really cool, and we thought it went really well together with our wind instrument interface.

Force-sensitive Softpot Instrument

For our first two instruments, we used the same hardware interface. We wanted to design an instrument that deeply combined two sensors to create a different experience than we made in previous labs, where all the sensors were separate in the interface. Thus, we decided to make a Force-sensitive Softpot, that sensed not only where on a slider you were touching but also how hard. Combining the two dimensions of input like this made controlling two parameters into one action, allowing for more artistic effects.

We created two different mappings for our FSS instrument. The first was very simple, where position along the softpot mapped directly to frequency and the force on the FSR mapped to volume. Our choice of waveform (sine wave with a slight reverb) this created an eerie-sounding howling effect. We found after some experimentation that the softpot required a certain minimum level of force to give stable readings, so we adapted the FSR mapping to be thresholded instead (only mapping readings above the threshold to volume).

Our second mapping was a little bit more radical. We mapped force on the FSR to timbral parameters used in waveshaping synthesis, to make a sine tone sound more “sharp” or “buzzy”. We also changed the softpot mapping to a discrete frequency mapping, so that tones were constrained to the 12 notes of the western chromatic scale. The timbral effects were especially cool – we could make sounds that almost sounded like speech, since the different levels of timbre sounded almost like different vowels, and changing between them sounded like “Wa” noises.

Final Instrument: Wind instrument


This “wind instrument” used the user’s breath to warm up thermistors placed at the bottom of the “pipes” (straws). Each pipe is responsible for a different chord and a different tempo. For example, in our demonstration we have a fast Fm6, a fast Cm9, and a slower, lower Cm9. The actual pitch classes played are randomly selected from the chord. The temperature reading controls the octave in which the chord is played: as you blow into the pipe, the chord gets higher, and as you stop blowing, the chord gradually falls down to a lower range as the thermistor cools off. This causes a fancy decaying effect, almost like the fading resonance of a struck bell.

Parts List

  • 3x Thermistor
  • 3x 330K Resistors
  • 3x Straws
  • Arduino Uno
  • Wires
  • Straws

We also require a computer installed with Processing and ChucK (and Arduino, of course).

Instructions

  1. Connect one thermistor to 5V and to A0. Connect A0 to ground through a 330K pull down resistor.
  2. Cut a straw so it is about 5cm in length. Place it on top of the thermistor
  3. Repeat steps 1 and 2 twice more for your two remaining thermistors, connecting them to A1 and A2.
  4. Loosely tape the straws together.
  5. Take some readings of the thermistor with the straws on, but without blowing into them. Set the maximum such value as the baseline in the ChucK code.
  6. To play the instrument, blow into the straws. The raised temperature of your breath should warm up the thermistors, which will gradually cool. Take off the straws if you want it to cool down faster.

Source Code

Arduino Code

/*
 Temperature Blow Straw Music Instrument
 Lab 2
 COS 436: Human-Computer Interfaces
 March 6, 2013
 Arduino Code
 */

//variables 
int temperature1; //temp sensor 1
int temperature2; //temp sensor 2 
int temperature3; //temp sensor 3

//pins
int pinT1 = A0; 
int pinT2 = A1; 
int pinT3 = A2; 

void setup()
{
  // initialize the serial communication:
  Serial.begin(9600);
}

void loop() {
  temperature1 = analogRead(pinT1);
  temperature2 = analogRead(pinT2);
  temperature3 = analogRead(pinT3);
  
  //Serial.print("Temperature 1: ");
  Serial.print(temperature1);
  Serial.print(" ");
  Serial.print(temperature2);
  Serial.print(" ");
  Serial.println(temperature3);
  
  delay(100);
}

Processing Code

/* Generic numerical message forwarding from Arduino to OSC */
import java.util.*;
import oscP5.*;
import netP5.*;
import processing.serial.*;

Serial myPort;

OscP5 oscP5;
NetAddress dest;
int port = 6448;
String oscName = "/arduinoData";

String data;

void setup() {
  size( 400, 300 );
  myPort = new Serial(this, Serial.list()[0], 9600);
  myPort.bufferUntil('\n');
  oscP5 = new OscP5(this,12000);
  dest = new NetAddress("127.0.0.1",port);
}

void serialEvent(Serial myPort) {
  String instr = myPort.readStringUntil('\n');
  data = instr;
  sendOsc();
}

void draw() {
 ;
}

void sendOsc() {
  OscMessage msg = new OscMessage(oscName);
  String[] tokens = data.split("\\s");
  for (int i = 0; i  0) {
      msg.add(Float.parseFloat(tokens[i]));  
    }
  }
  oscP5.send(msg, dest);
}

ChucK Code

// HCI Lab 2 - Wind Instrument 
// ChucK Synthesis Script
// Generates random notes in chords, with the octave based on the readings from the arduino.
JCRev r => Gain g => dac;
.1 => r.mix;
.7 => r.gain; 
.5 => g.gain;

// ---------------- Globals ---------------
32 => float baseline;   // Ambient temperature readings for thermistors

1 @=> float octave[];  // Current octave
1 @=> float in[];      // Current reading
// ----------------------------------------

// ---------------- Chords ----------------
[0, 2, 4, 7] @=> int chord1[];    // I9
[5, 7, 9, 12] @=> int chord2[];   // IV
[7, 11, 14, 17] @=> int chord3[]; // V7

[0, 2, 3, 7] @=> int chord4[];    // i9
[5, 8, 12, 14] @=> int chord5[];  // iv6
[7, 11, 14, 17] @=> int chord6[]; // V7
// ----------------------------------------


// Function that plays notes in appropriate chord
fun void playstuff(int chord[], int index, int tonic, int speed) {
    SinOsc s => r;
    .2 => s.gain;
    3 => int x;
    1 => int off;
    while (true) {
        if (in[index] >= baseline) {
            Math.round((in[index] - baseline)/2) => octave[index];
            0.5 => s.gain;
            if (Math.random2(0,1) == 0) {
                1 => off;
            } else {
                3 => off;
            }
            Std.mtof(tonic + chord[(x + off)%4] + 12*octave[index]) => s.freq;
        } else {
            0 => s.gain;
        }
        x + 3 => x;
        if (x > 3) x - 4 => x;
        speed::ms => now;
    }
}

// Initialize one thread for each thermistor
spork ~ playstuff(chord4, 0, 60, 150);
spork ~ playstuff(chord5, 1, 60, 150);
//spork ~ playstuff(chord6, 2, 60, 150);
spork ~ playstuff(chord4, 2, 48, 600);


// --------------------- OSC Processing -------------------------
OscRecv recv;
6448 => recv.port;

recv.listen();

recv.event("/arduinoData, f f f") @=> OscEvent @ oe;

while(true) {
    oe => now;
    while(oe.nextMsg()) {       
		oe.getFloat() => in[0];
        oe.getFloat() => in[1];
        oe.getFloat() => in[2];
        <<>>;
    }
}

  1. ,0.,0.
  2. ,0.,0.

L2: Bop It

Group 15: Prakhar Agarwal (pagarwal@), Gabriel Chen (gcthree@), and Colleen Carroll (cecarrol@)

Initial Prototypes:

Our first attempt at making an instrument out of a frisbee. One prong has a flex sensor underneath so the prong can be bent to control pitch.

Source Code: See source code for final design.

Prototype 2 uses the same base to control different elements. This time we have added a button to make the tone play only when it is pressed, as well as a rotary potentiometer for volume control.

Source Code: See source code for final design.

For the last prototype, we tried something completely different, and came up with a pretty good Halloween or horror movie music maker.

Source Code:

/*

ADXL3xx

Reads an Analog Devices ADXL3xx accelerometer and communicates the

acceleration to the computer. For AdaFruit ADXL335 breakout board.

Modified from code at

http://www.arduino.cc/en/Tutorial/ADXL3xx

The circuit:

analog 0: Vin

analog 1: 3vo

analog 2: ground

analog 3: z-axis

analog 4: y-axis

analog 5: x-axis

test pin is hanging off the edge :)

created 2 Jul 2008

by David A. Mellis

by Tom Igoe

modified 19 Feb 2013

by Rebecca Fiebrink

This example code is in the public domain.*/

// these constants describe the pins. They won't change:

const int groundpin = A2; // analog input pin 2

const int powerpin = A0; // analog input pin 0

const int xpin = A5; // x-axis of the accelerometer

const int ypin = A4; // y-axis

const int zpin = A3; // z-axis

void setup()

{

// initialize the serial communications:

Serial.begin(9600);

// Provide ground and power by using the analog inputs as normal

// digital pins. This makes it possible to directly connect the

// breakout board to the Arduino. If you use the normal 5V and

// GND pins on the Arduino, you can remove these lines.

pinMode(groundpin, OUTPUT);

pinMode(powerpin, OUTPUT);

digitalWrite(groundpin, LOW);

digitalWrite(powerpin, HIGH);

}

void loop()

{

// print the sensor values:
Serial.print(analogRead(xpin));

// print a tab between values:

Serial.print("\t");

Serial.print(analogRead(ypin));

// print a tab between values:

Serial.print("\t");

Serial.print(analogRead(zpin));

Serial.println();

int xfreq = analogRead(xpin);
int yfreq = analogRead(ypin);
int zfreq = analogRead(zpin);

tone(8, xfreq+yfreq+zfreq);
// delay before next reading:

delay(100);

}

Description of Final Design:

Our group built a an instrument that can be played by 1-3 people. Our inspiration was essentially creating a musical Bop-It. Each end of the three-prong instrument has a different control over the sound. We liked that the instrument can be played by a range of people, our project can be the basis for a solo, duet, or trio piece. The device is limited in the range of interactions. While there are multiple useful controls, each sits on the unmoving object. With one more iteration we may have included the accelerometer to make a moving object. Additionally, we can only play within one octave because of limitations with the size of the Overall, we found the final product a fun and interesting challenge for multiple players.

In this instrument, as mentioned before, each prong of the frisbee controls a different musical aspect of the sound that the buzzer plays. One has a button to control when the tone is made. A second has a rotary potentiometer to control volume. The third will have a sliding potentiometer that determines the pitch.

Source Code:

#include "pitches.h"
/* FSR simple testing sketch.

Connect one end of FSR to power, the other end to Analog 0.

Then connect one end of a 10K resistor from Analog 0 to ground

For more information see www.ladyada.net/learn/sensors/fsr.html */

int slidePin = 0; // the FSR and 10K pulldown are connected to a0

int buttonPin = 9;

int slideReading; // the analog reading from the FSR resistor divider

int buttonReading;

void setup(void) {

// We'll send debugging information via the Serial monitor

Serial.begin(9600);

}

void loop(void) {

slideReading = analogRead(slidePin);

Serial.print("Analog reading = ");

//Serial.println(slideReading); // the raw analog reading

Serial.println(slideReading);

int freq;
if (slideReading < 125) {
freq = NOTE_C7;
}
else if (slideReading < 250) {
freq = NOTE_D7;
}
else if (slideReading < 375) {
freq = NOTE_E7;
}
else if (slideReading < 500) {
freq = NOTE_F7;
}
else if (slideReading < 625) {
freq = NOTE_G7;
}
else if (slideReading < 750) {
freq = NOTE_A7;
}
else if (slideReading < 875) {
freq = NOTE_B7;
}
else {
freq = NOTE_C8;
}
/* buzzer in 8th pin */
while (true) {
tone(8, freq);
buttonReading = digitalRead(buttonPin);
if (buttonReading == 0) {
noTone(8);
break;
}
}
}

Materials:

Three-Prong Frisbee
Buzzer
10K Resistor
Potentiometer
Button
3 Small (Red) Breadboards
1 Large Breadboard
Arduino
Electrical Tape
Wire

Instructions:

Firstly, wire the buzzer on the large breadboard and hook it up to the Arduino.
Set the button in one of the small breadboards and connect it to the buzzer so that the buzzer will now only play when the button is pressed.
In one prong, cut a hole and place the button through it. Tape it in place.
Next, set the rotary potentiometer in another small breadboard. You will wire this to the buzzer, replacing the resistor in the buzzer circuit with the rotary pot.
Cut a hole in another prong and place the rotary pot though it. Tape it in place.
Lastly, wire the sliding potentiometer on a small breadboard and attach the output to an input pin on the arduino. The code below shows how we map the potentiometer readings to buzzer frequencies.
Cut a hole in the frisbee on the last prong and slip the sliding pot through it. Tape it in place. You now have a musical bop-it!