Lab 5 — Piezo Buzzer

J M
8 min readOct 5, 2021

--

Joanne Ma. Professor Kimiko Ryokai. INFO C262, Fall 2021

Description

This week’s lab takes what we’ve been learning about pulse width modulation (PWM) from the beginning of the semester, building circuits with Arduino and different I/O to make some more noisy design artifacts. We used the piezo buzzer and tone() function to incorporate sound to create a theremin, played with Professor Howell’s sketch for playing sounds from the serial port, and had to use an input/output transductor to design an artifact where both input and output occur at the same place. We have to manipulate the frequency of the duty cycle, and Professor Ryokai reminded us that to calculate period, we need to solve for frequency (hz) = 1/ period (sec).

During class, we learned that applying oscillating voltage will oscillate the physical disc. Oscillating the disc will cause it to flex, release, and contract. There’s a ceramic disc housed in the black plastic, which supports the disc to be in the middle. Professor Ryokai described the role of the black plastic casing as something that serves as a resonant cavity.

The sound of a piezo buzzer is quite harsh, so learning how to “soften” the PWM was something I got to observe other students exploring during invention lab hours and something I definitely wanted to try out for the homework. One student was able to create a sine wave using pressure applied from a steel ruler with a piezo that had its plastic shell completely removed. I’m quite surprised that the plastic casing of the piezo–which acts as a transductor by converting between electrical energy and physical movement–makes such sharp and piercing noises, so I definitely wonder what affordances are possible with different casing/dampening materials.

Components used

  • arduino
  • breadboard
  • jumper cables
  • 10k resistor, 200 ohm resistor
  • piezo buzzer
  • potentiometer

Part 1 — The Piezo Buzzer

I followed the Arduino tutorial for toneMelody to make the piezo buzzer play a melody. While the piezo wires were thin, this was the first time that I constructed the circuit without issues. It was very satisfying to hear the little melody play, which got me excited for the other parts of the lab.

Part 2 — Make a Theremin

I was a bit intimidated by this section because of all of the issues I encountered when using the photocell in the previous lab. Luckily, Zeke was there to catch my errors in constructing the circuit, where I accidentally swapped where A0 and GND should be connected to the breadboard. It was super satisfying to see the photocell working! I played around with the source code and changed the duration of the notes to see what would change. Honestly, I could barely detect a difference between the notes duration, but I attribute that to my lack of musical training to know what to pay attention to.

Sound serial (noura howell)

I was so excited to see an I School alum’s work that I admire so much being incorporated into our class! I was super confused as to how to get the sound serial code working, and then realized that I just needed to create a separate sketch. If I had more time, I would have liked to play around with the code to see if I could incorporate sharp and flat notes to play different songs (albeit all at the same tempo).

Homework — Input-output coincidence exercise

I initially planned to use a potentiometer to lower the volume of the piezo buzzer since I was so irritated with how harsh the piezo buzzer sounded. However, I wanted to work on a more hackery project and explore more of the invention lab, so I decided to do my input-ouput coincidence exercise using a 3.5mm cable.

While I didn’t end up using the Mozzi library, I was inspired to work on an input-output coincidence exercise by using an audio jack so I could learn more about analog. A huge shoutout to Zeke for supporting this crazy experiment to basically see if we could use the piezo like a speaker for richer songs (the short answer is, not quite).

Components used:

  • arduino
  • breadboard
  • jumper cables
  • wire stripper
  • soldering iron
  • lead-free solder
  • shrink wrap
  • heat gun
  • 3.5mm jack and cable
  • electrical tape
  • a video of your favorite edm song, and your favorite acoustic song

I first committed what felt like a sacrilegious act and cut off an audio jack from a speaker. I used a wire stripper to remove about 3cm of plastic from the 3.5mm cable — Zeke taught me that the uncovered copper wire was ground, whereas the yellow and white thinner wire were the left and right sides of the speaker audio you experience.

I needed to strip the cables to connect the 3.5mm cable to a jumper cable that can be inserted into the breadboard. I then set up the arms to hold up the two wires that needed to be soldered together. Unlike the soldering experience we had in class where it was just soldering one thick wire onto a formed sheet of metal, soldering wire involves spreading out the filaments, and then meshing them together, then twisting those filaments to offer structure that can withstand being shoved by the solder. I repeated this process for all three of the wires that make up the 3.5mm cable. I also secured the exposed wires post soldering with electrical tape, then shrink wrap with a heat gun.

soldered wires, with yellow shrink wrap already on to protect the of the 3.5mm cable extended with jumper wires from fraying more
big shrink wrap for all of the 3.5mm cable!

We were ready to experiment with the 3.5mm cable! We first connected the audio cable to the arduino to make sure that the audio cable was in working order. I chose to play my favorite gentle and existential song at the moment, Castaways by the Backyardigans covered by Martina DeSilva. We started by keeping the volume relatively low since we were afraid to blow out the piezo buzzer. Turns out, even at full computer volume and video volume, we really had to put our ear up against the piezo to hear the song. It played music!

An absolute banger.

But, it was so quiet. To understand why this was happening, we drew upon our knowledge that audio is sound waves, which can look like sine waves (think of audio visualizations). A big disclaimer that I have never taken a signals processing class and never studied music growing up so please let me know in the comments if there are more accurate ways of explaining this!

When we write sound to a speaker, we represent that through voltage over time. The piezo has two paths, and one of the paths moves up and down (vibrates). When we send voltage into the piezo buzzer, this controls the movement and thus the vibration. The issue is that the sound wave that would make the noise is really quiet. We hypothesized that in order to make the audio louder, we needed to increase the amplitude of the sound wave. To make the wave bigger, we tried analog reading in values at A0, which is connected to the negative of the input voltage. A1 is connected to the positive input voltage. The black wire, ground, has relative voltage to that of the Arduino.

Circuit schematic and graphical representations of the sound waves (I realized I should have used more contrasting colors for the first graph)
Crunchy audio represented by a graph.

audio_booster Code

//double lastMillis = 0;
double loops = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int ground = analogRead(A0);
// Serial.println(ground); // computer's ground, which can be different from the arduino's ground
Serial.println(loops / (millis() / 1000.0)); //count how many times looping, and then divide it by
loops++;
int in = analogRead(A1);
int out = 1023 - (in-ground);
analogWrite (9, out);
long current = millis();
loops++;
// here, we were trying out example code from arduino to see how many times we loop over a period
// if (current - lastMillis > 1000) {
// Serial.println(loops);
//
// lastMillis = current;
// loops = 0;
// }
}

Our first instinct was to multiply the input by 2. This made the audio sound so crunchy, but the beat of Peggy Gou’s Starry Night was still very much recognizable. We then tried to account for relative voltage by subtracting in (arduino) from ground (computer) and multiplying that by 2, but that made the audio sound fried.

I decided to try this code out on Martina DeSilva’s version of Castaways, which sounded very muddled and hard to recognize. After seeing the serial monitor, we noticed that the waves were very angular with sharp drop offs. That made us think that the Arduino must be only sampling parts of the song. Zeke, drawing on his signals processing knowledge, explained that Arduino is actually fast enough to sample the Hz of the song audio, but since the function analogRead takes too long to execute, we end up missing more nuanced parts of the song.

Additionally, when I tried playing the song faster, the song would also get muddled, which confirmed our suspicion that we had a low sample rate — this was confirmed by the serial monitor, which showed a sampling rate at 120 Hz per second. For comparison, CDs play 44000 Hz a second. For a song like Castaways, which has more high resolution sounds (aka sounds with more nuance), it was even harder for the song to be played by the piezo. I was able to notice that despite the crunchy audio of Starry Night, we could tell that the song was playing correctly because the low resolution changes in the song are very apparent. We still get to hear the general intonations of both songs. Basically, analog read and write calls take too long to execute, meaning parts of the song get skipped out on, meaning that we simply cannot listen to audio the same way that we would hear it through our lovely computer speakers.

Further extensions and related work

I had a lot of fun learning about how people talk about music this week as a byproduct of this lab — shout out to Annais for teaching me about acoustic waves. If I had more time, I would try to understand in more technical depth what “sounds” and “genres” makes different waves. Since the Castaways cover was by Martina DeSilva, a frequent collaborator with Adam Neely, I figured I would listen to videos in the background as I was writing this Medium post to keep me away. As someone super new to thinking about music in both a technically applied, signals processing way and a more historical/cultural way, I never realized how much the language used to describe music in American contexts is so grounded 18th century European music and music theory from that perspective. Since the song Castaways draws from the musical patterns of Bossa Nova, I also really enjoyed Neely’s video on Girl from Ipanea, which elegantly weaves together the importance of citation practices (and showed the impact careless citations resulting in cultural context/loss/white-washing of bossa nova), cultural influences in musical taste, the context in which music is created, all these super HCI/STS questions weaved into the medium of music. Neely’s Youtube videos seem to be super carefully researched and well done, so I’m excited to continue deepening my appreciation for music through his videos and finding ways to apply this knowledge in future labs.

--

--

J M
J M

Written by J M

Grad student @ UC Berkeley’s School of Information. Interests include social computing, usable security, Being Online™️ and reflective tech.

No responses yet