The Science of Sound

Sound is composed of a series of vibrations in the air. To get an idea of how it works re-do the circuit for Analog Read and a Potentiometer. Once you get your potentiometer varying the flash rate of an LED attach the red lead from your piezo to the LED pin and the black lead to your negative rail.

As the LED flashes you should hear a click. As the flashing gets faster eventually you'll have trouble seeing the flashing, but you can still hear it. As the flash rate gets faster eventually the clicking sounds more like a constant tone. The piezo really is just clicking, but our ear can no longer pick out the individual clicks because they happen too quickly.

To make higher frequencies you can use a new command. As you should recall, delay is used to pause for a number of milliseconds, so the lowest you can go is 1 millisecond, this would give us a maximum frequency of 500 hz. If we want higher pitches we need smaller pauses. The easiest way to do this is use delayMicroseconds which, as you might guess delays for the number of microseconds instead of milliseconds. If we simply replaced delay with delayMicroseconds we'll produce a range of frequenceis we can't actually hear, so first you'll need to rescale the values.

So you can use something like: (If you don't recall the "map" command then you should go back to the lesson on Analog Read with a Photo-resistor)
note = analogRead(potPin);                 //read the value of a potentiometer
note = map(note, 0, 1023, 500, 2500); //re-scale the potentiometer value to 500 to 2500
delayMicroseconds (note);                 //delay for "note" microseconds

Don't like the way it sounds? Change the numbers and see what happens.
Comments