Lab 5: Piezo Speakers and I/O Coincidence

Posted by raghavchandra

raghavchandra's picture
Objective:
In this lab, we used a Piezo Speaker as an output device. We coupled the sensors from the previous labs and the speaker from this lab to further explore the domain.

In Lab, we used the speaker to play notes. This was done in three ways: pre-fed notes, taking input from the user using the serial monitor, and taking input from the user using our sensors.

As Homework for this lab, we were asked to make an artifact which uses the different Input/Output devices we have learnt about in classes. This artifact was to be a stand-alone device  i.e. both the input and the output occur on the same device, hence an Input/Output Coincidence.

I/O Coincidence Artifact(Object-Free Portable Music Keyboard):

In this lab, we used a Piezo Speaker as an output device. We coupled the sensors from the previous labs and the speaker from this lab to further explore the domain.

My Artifact revolved around the idea of having a portable, ready-to-use musical instrument, in this case, more like a keybaord. Using any flat object as your keyboard, you could create music.

The way it works is that the FSR senses the touch on the object. This gives the feel of the user actually pressing the keys. The Photocell is used to read the notes the user wants to play, depending on how far the user is from the device.

Click here for the video.

Components Used:
  • Arduino Micro-controller
  • 1 Resistor (1K Ohms)
  • Wires/Bread Board
  • Sensors (FSR and Photocell)
  • Ambient light
  • Piezo Speaker


Arduino Code:
/* ---Portable musical Keyboard ---
 *
 * This is the code for the Object Free Potable Keyboard.
 * Using Photocells, it senses the note a user wants to play.
 * Using FSR,, it senses if the user is touching/pressing the used object.
 *
 */
 
 
int drumPin = 1;    // Input pin for the drum
int sensorPin = 5; // input pin for the tone sensor
int speakerPin = 7; // output speaker pin
 
int val = 0;
 
void setup() {
  pinMode(speakerPin, OUTPUT); 
  Serial.begin(9600);
  Serial.println("ready");
}
 
void loop() {
  digitalWrite(speakerPin, LOW);
  
  val = 8 * analogRead(sensorPin);    // read value from the sensor
  Serial.println(val);
   if (analogRead(drumPin) > 600) { 
      digitalWrite(speakerPin, HIGH);
      delayMicroseconds(val);
      digitalWrite(speakerPin, LOW);
      delayMicroseconds(val);
   }
}
 

 

0
Your rating: None