Lab 5 — Output: Piezo Speakers

Ryan Qiao
3 min readOct 5, 2021

--

Ryan Qiao. Professor Kimiko Ryokai. Info C262 Fall 2021.

Description

In this week’s lab, we explored outputting sound using piezo buzzers.

It was a lot of fun controlling the speaker output with the photocell input. I find myself trying out different gestures to see how the photocell, and thus the sound, would be influenced. Because I didn’t need to touch anything to change the sound the Theremin makes, in a way it felt like I was magically conducting the music (noise)!

For the homework section, I explored inspirations from nature.

Components Used

  • Arduino
  • Breadboard
  • Wires
  • 10K Resistor
  • Piezo buzzer
  • Paper
  • Pin
  • Scissors

Part 1: The Piezo Buzzer

At first, I was a bit confused because after connecting the circuit, the sample code ran into errors. From the error thrown, I realized I haven’t saved the pitches.h file. After fixing that, my piezo buzzer started working!

Part 2: Theremin

I followed the instructions to make the theremin. A hiccup I had was that I connected the 5v from the Arduino to the negative side on the breadboard without noticing it, and so my circuit was open. After spending a whole hour debugging, I found the error and realized how much trouble color-coding the wires would have saved me. (i.e., red for positive, blue for negative, etc.)

Homework: Bird Beak

For our homework, we were encouraged to create an object that has both input and output.

I spent a lot of time playing with the theremin in part 2, and at a certain point, I felt like the resulted sound reminded me of nature, perhaps a forest, and more specifically bird chirping.

So I thought about when birds chirp, what input can I sense with a photocell? Then I thought about how the output of the chirp comes from the bird's mouth, what if I design the opposite, where the inside of the mouth takes input? I body stormed with my hands (pretending they are the bird’s beak) and experimented with movements that would result in the chirping sound.

Finally, I made an origami bird beak and secured the photocell inside of the beak. By opening and closing the bird's beak, you can control the amount of light let into the beak, and the chirping sound is produced!

It was also interesting to note when the bird’s beak is facing the window, the chirping sounds happier! (There’s a slight change in tone because more light is let in.)

Code

/* Theremin
* --------
*
* Created 24 October 2006
* copyleft 2006 Tod E. Kurt tod@todbot.com
* http://todbot.com/
*
* Adapted by Noura Howell, 2 October 2017
* http://nourahowell.com/
*/
int photocellPin = 0;
int speakerPin = 8;
int photocellVal = 0;
int toneVal;
// try changing the noteDuration to hear how that changes the sound
int noteDuration = 10; // ms
void setup() {
pinMode(speakerPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
// read the value from the sensor
photocellVal = analogRead(photocellPin);
Serial.print("photocellVal: ");Serial.println(photocellVal);

// decide what tone to play based on the sensor value
// try changing this calculation to hear how that changes the sound
toneVal = photocellVal * 5;

// play the tone
tone(speakerPin, toneVal, noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
// try changing the pauseBetweenNotes to hear how that changes the sound
int pauseBetweenNotes = noteDuration * 1.2;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(8);
}

--

--

Ryan Qiao
0 Followers

I’m a second year MIMS student at UC Berkeley. My focus is in product management, and my interests are in HCI, arts + tech, and entrepreneurship.