Pages: [1]   Go Down
Author Topic: How to make audible sound wave on piezzo buzzer?  (Read 1638 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So after I looked up modulation as it pertains to audio I understand now smiley-grin

My new code:(It makes a sin wave but also modulates the pitch really fast up and down.)
Code:
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);
}
Logged

Dubai, UAE
Offline Offline
Edison Member
*
Karma: 21
Posts: 1670
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged


Offline Offline
Newbie
*
Karma: 1
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: