baltimore's makerspace for hackers, makers, diy and crafters

Barebones Arduino Synth

(cross posted from my personal blog)

Two potentiometers, one speaker, and an hour of spare time combined to form my first (real) Arduino circuit and the beginning of a beautiful friendship. The speaker came from one of my kids’ toys.

Aside: As a house rule, we don’t do electronic sound making toys (“Seriously, you gave them a fire truck that yells? Really?”), so I end up with a good bit of sound capable electronic spare parts (ask me about my unfinished laser-eye screaming chicken t-shirt sometime). Lights are fine, and we’ve even got an old school tape recorder for impromptu dance parties. Just no bleepy robots, princes sprinkles, sirens, or pretend sports announcers.

Anyways, the potentiometers and the breadboard came with my Arduino Starter Pack from http://www.adafruit.com/.

// based on "Arduino Sound Hello World"
// originally by David Fowler of uCHobby.com
// modifications and adaptations by
// Adam Bachman of adambachman.org

// Open the Arduino serial monitor at 9600 baud to see debug output

/*
circuit:

digital pin 9 -> pot 1 outer -> speaker A
speaker B -> ground
analog pin 0 -> pot 2 inner
5V in -> pot 2 outer 1
pot 2 outer 2 -> ground
*/

int soundPin = 9;      // the I/O pin for our sound output
int sensorPin = 0;     // input pin for the potentiometer
int sensorValue = 0; // control frequency

void setup(void){
  //Set the sound out pin to output mode
  Serial.begin(9800);
  Serial.println("I'm alive!");
  pinMode(soundPin,OUTPUT);
}

void loop(void){
  sensorValue = analogRead(sensorPin);

  //Set the pin high and delay for sensorValue uS
  digitalWrite(soundPin,HIGH);
  delayMicroseconds(sensorValue);

  //Set the pin low and delay for sensorValue uS
  digitalWrite(soundPin,LOW);
  delayMicroseconds(sensorValue);

  // spit out the sensor value (sanity check)
  Serial.println(sensorValue);
}

The scene of the crime. I had to sit close enough to the computer to program the ‘duino and read the references. All soldering (wires to speaker) was done elsewhere.

The circuit (as described in the code) is one potentiometer between the speaker and the arduino to control volume, and one sending data directly to the analog input to control frequency. When I took the second potentiometer out, frequency was all over the place. Depending on where I touched the wires, I could pretty reliably get some interesting electronic pops and squeals. Almost more fun than twisting dials.

Nowhere to go but up. I cannot recommend enough that if you have something in mind you’d like to try, JUST DO IT. Very rarely will someone invite you to be awesome, and never will someone be awesome for you.