For a class project I have to generate a musical note, “Middle C”. I’ve chosen to use a microcontroller and a speaker, and I looked up the frequency of “Middle C” to see that it’s around 260 Hz.
I’ve hooked up a small speaker and output a frequency of 260 Hz, but the speaker just makes a small buzzing noise and doesn’t sound like a note…nor is it LOUD ENOUGH. I’ve tried speakers several times the size, and still nothing remotely close to what I need.
Has anyone done something like this before? 260 Hz just seems to be too low a frequency to generate a note. 1 kHz sounds fine.
Please let me know what to consider. Thank you!
Try to use a Piezo insted of a speaker. Just note that you cant hook the Piezo up directly, you need a resistor and a diode.
Just Google Arduino and Piezo and you find what you need.
I've hooked up a small speaker and output a frequency of 260 Hz, but the speaker just makes a small buzzing noise and doesn't sound like a note...nor is it LOUD ENOUGH. I've tried speakers several times the size, and still nothing remotely close to what I need.
A small speaker should work fine. I've connected a typical ("8 ohm") speaker to an arduino through about 100ohms of extra resistor (for current limiting), and it's plenty loud enough to annoy everyone else in the room. There are examples in the playground, and code for a chromatic scale has been posted in the forums somewhere.
Did you remember to set your pin to be an OUTPUT? What does your code look like?
Just note that you cant hook the Piezo up directly, you need a resistor and a diode.
All the examples I can find that include a piezo, resistor, and diode are for a knock sensor. The examples for generating sound have the piezo wired directly to a pin with no other components.
Can you provide a link or example? I really don't want to fry a $30 board because I incorrectly wired a 50¢ piezo!
Please remember that you are probably outputting a square wave. This is rich in odd harmonics and so will sound buzzy, it will not sound like a pure note as say produced by a flute.
To get it to have a bigger fundamental component you can change the sketch so you use the PWM capability, or add a filter. A simple RC will help but you need a higher order one for it to sound much better.