Wax Eloquently

This is my life — or at least part of it. Enjoy!

Wax Eloquently header image 2

Knobs and Tones

October 18th, 2007 · 3 Comments

I’m building a 16-step tone sequencer using the Arduino Diecimila prototyping platform!

200710181042

I’ve reached the first milestone: potentiometers for Volume, Tone, and Duration are all responding as expected (after correcting a few mistakes).  Here’s a movie showing how it all currently works!

The toughest bit to get working was the momentary button that will eventually play the currently selected tone.  I had it hooked up to digital pin 13 originally, and it seemed to work for a minute or two.  Then it stopped.  Maybe I had it wired wrong and fried that pin?  Hmm.

So I’ve moved to using pin 3 instead.  And I’m being more careful.

The tones that can be generated are limited to an array I filled with the frequencies of all of the piano keys from G2 to C8.  It felt like a reasonable range to start with, but I’m noticing that the sheer number of frequencies makes it tough to dial-in to an intended note easily!  I might add another pot to control octave, and then just reduce the tone pot to a single octave range.

The construction of the tones themselves is done using Pulse Width Modulation.  This is to say that for tone being created, the microprocessor is pulsing HIGH voltage for half of the frequency length and then LOW voltage for the other half.

200710181040-1

For instance, the frequency of the note A4 is 440Hz.  Hz (or Hertz) is a measure of how many cycles of a wave occur per second.  A frequency of 440Hz means that there are 440 wave cycles for each second of sound; conversely this could be understood to mean that one entire wavelength lasts for 1/440th of a second.

Sound waves tend be split into two equal sections: a peak and a valley.  I am able to represent these to the speaker using HIGH and LOW voltage values.  Since each value represents half of the wave, I need to pulse HIGH at for 1/880th of a second (half of 1/440th of a second) and then LOW for another 1/880th of a second.

200710181040-2

The processor goes back and forth between sending HIGH and LOW to the speaker for as long as I want the sound to last.

So that’s how the tones work!

Next I will be tuning up the duration, limiting it to quantities that will represent eighth, quarter, half, and whole notes and rests.  And dotted of the same, maybe.  Then I’ll use my last pot to control tempo.

Here is a brief summary describing how everything is set up:

  • Rocker switch between digital pin #2 and GND, not currently in use.
  • Momentary pushbutton between digital pin #3 and GND, with the pin’s built-in pull-up resistor activated in code.
  • 100K Ohm audio taper potentiometer: first lead on digital pin 11 (PWM speaker out), middle lead to speaker, third lead to GND.
  • 100K Ohm linear taper potentiometer: first lead on 5V, middle lead to analog pin 0 (tone control), third lead to GND.
  • 100K Ohm linear taper potentiometer: first lead on 5V, middle lead to analog pin 1 (duration control), third lead to GND.
  • 8 Ohm mini speaker between audio taper potentiometer and GND.

And here’s the code that is currently used to drive it all… Tone_Generator_v1.pde.txt

Enjoy!

Tags: science · toys

3 responses so far ↓

  • 1 Scott Robinson // Oct 18, 2007 at 2:40 pm

    Very cool. Keep us appraised of the progress!

  • 2 Tom // Oct 18, 2007 at 2:42 pm

    Yes sir! Updates will be forthcoming.

  • 3 Scott F. // Oct 20, 2007 at 1:29 pm

    Tres’ neato. What we need more of is music..derived from science!

Leave a Comment