Don’t be quite, Make noises with Arduino!

1

The aim of this tutorial is to explore Arduino which is an open source hardware as well as software platform!

AIM:- Making sounds from Arduino

Requirements:-

  • Arduino  (preferably UNO)
  • Breadboard
  • USB cable
  • Buzzer ( or a speaker)
  • Some wires
  • Battery (optional)

We can develop sounds or annoying noises from Arduino and even Melody’s (just that like from a piano) on an arduino using the instructions below.

Let’s Begin

What we need to do is to just plugin  the positive and the negative of the buzzer in breadboard.

Now comes the question how to identify the buzzer’s +ve and  -ve……well that’s child play just as one do with LEDs, longer part is +ve and the smaller one is -ve.

FAIR ENOUGH :-

One might say what if the both leads are equal or are made intentionally equal?

That again is not difficult to figure out …..just use your Digital multimeter in Diode mode and see what is +ve or -ve?

CIRCUIT:

  • Take a wire and put it in Digital PWM pin (* pins) on Arduino (in this case 11).
  • Put the other end of your  wire in the +ve lead of buzzer through the breadboard.

  • Similarly take a wire from ground or gnd pin from Arduino and put it to -ve of buzzer through breadboard

  • Finally put the buzzer in the positive and the negative holes in the breadboard

And here is the code:

//make sounds with Arduino!

int buzzpin=11;              //PIN11 IS USED FOR BUZZER

void setup()

{

pinMode(buzzpin,OUTPUT);

}

void loop()

{

digitalWrite(buzzpin,HIGH);

delay(10);    //giving a delay of 10 milliseconds or a frequency of 100 Hz

digitalWrite(buzzpin,LOW);             

delay(100);    //wait for one-tenth of a second

}

 

Voila! What did we just do? Well Amazing! Mission accomplished or may be no!

Method used above is just  OK! But seems quite boring and actually we did not do anything more software oriented……..So to begin again Let’s have a look on tone function    http://arduino.cc/en/Reference/Tone

PS: tone() can be used with a pin only one at a time

Syntax of the tone is as follows :

tone(pin number, frequency (in Hz),duration(in ms))

thus tone(11,20,000,1000);

means generating a 20,000 Hz  sound on pin 11 for 1 second.

Now we gonna produce  different frequency sounds using the code as follows:-

int buzz=11;      //buzzer on pin 11

void setup()

{

pinMode(buzz,OUTPUT);

}

 

void loop()

{

for(int i=20;i<=20000;i+i+1000)  

                                                                       /*start with 20Hz and go through 20,000 Hz with multiples                         

                                                                           of 1000*/
tone(11,i,2000);

delay(1000);                                                         //gap of 1 second

 

}                                     

Share.

About Author