Go Down

Topic: How to make audible sound wave on piezzo buzzer? (Read 2160 times) previous topic - next topic

Xadiant

Hello, I am new here but I have already made a few projects on the arduino.  I am on the hunt currently on how to make a specific sound on an arduino with a piezzo buzzer.

Here is what I have:
Code: [Select]
void loop() {
  a=a+1;
  tone(13,sin(a)*50+2000);
  delay(60);
  tone(13,0);
  delay(10);
}


Here is what I want:
http://downloads.bbc.co.uk/doctorwho/sounds/sonicscrewdriver.mp3

My code generates something similar in terms of pitch and timing... but it is very harsh when compared to the link above.  Is there an easy way to modulate a tone or make it softer?

Xadiant

So after I looked up modulation as it pertains to audio I understand now :D

My new code:(It makes a sin wave but also modulates the pitch really fast up and down.)
Code: [Select]
void loop() {
b=b+1; //for the sine wave
a=a+mod; //for the pitch modulation
if(a>40){mod=-mod;}
if(a<1){mod=-mod;}  //these loop modulation back and forth
c=75*sin(.004*b)+1600+a*5;  //all the numbers added up.
tone(13,c);
}

DuaneB

Hi,
   If you precalculate all the sin wave values and store them in an array, you can congratulate yourself on building your first wave table synthesizer.

   Here is a link to one I have done some work on recently -

http://rcarduino.blogspot.com/2012/08/the-must-build-arduino-project-illutron.html

   Here is a link for adding an audio amp to your project to make much better and louder audio from your Arduino -

http://rcarduino.blogspot.com/2012/08/adding-audio-to-arduino-projects.html

   There also are some clips of various peoples Auduinos (arduino based granualar) synth at the end of the second link

   All of these are a good base for music or sound effect production.

Duane B

rcarduino.blogspot.com
Read this
http://rcarduino.blogspot.com/2012/04/servo-problems-with-arduino-part-1.html
then watch this
http://rcarduino.blogspot.com/2012/04/servo-problems-part-2-demonstration.html

Rcarduino.blogspot.com

Quote
it is very harsh


I'm not completely sure what the function does above but I see a 2000 that I assume to be Hz with a rising action.

I make my living as an audio engineer.  If I want to make someone's ears bleed 2000-3000 is where I'd start.  At this frequency sin waves can be more harsh than other options which, for whatever reason, sound more pleasant with upper harmonics.  If you have access to square or saw I'd look at those and I'd look to get to lower frequency registers, if possible. 

The frequency response of the piezo is going to be limited for sure and that may make things tricky in that you may not ever heard a fundamental frequency of 500Hz or something.

Xadiant, you are my hero!  I've been trying to bruteforce this problem all day and I never thought to solve it with math.  <3

Go Up