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.
http://www.youtube.com/watch?v=m4fnaxtYZm0
// 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.
http://www.youtube.com/watch?v=LjhAQpXjqIY
#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.
http://www.youtube.com/watch?v=QjxADA7NE1E
#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.