Arduino and piezo buzzer

This is a small project, to test a buzzer, that I just bought.

buzzer-2013-02-03 20.13.40

The funny thing about this project is that after I built the circuit, heard the buzzer at about 3KHz, I tried to tape it with my Samsung Phone Galaxy S.
I could not save the tone!! I had to talk something at the mic, to confirm it wasn’t recording the tone, I could only hear my voice, but not the tone! Looks like the mic is very limited, then, I borrowed my daughter´s ipod, which recorded it very nicely.

Here is how it sounds, the background noise are my kids on the computer, sorry… Tone recorded

The circuit is pretty simple. I used an online editor to draw it. The site is Circuit lab

circuit-buzzercircuito piezo buzzer

Now you have to upload a program on Arduino to play the buzzer

It´s very simple. YOu can use several digital outputs of Arduino, but only the pwm enabled oned
PWM: 3, 5, 6, 9, 10, and 11 on Arduino Nano and Uno,
and check your model if it is another one. The tone funcion uses analogWrite Funcion, wich generates the pwm signal.

// Buzzer Program – Ricardo Pecanha –
void setup(){
pinMode(10,OUTPUT);//define o pino 10 do arduino como saida digital

void loop(){
//play tone
tone(13,2999,800);// esta linha de código é usada especialmente para o buzzer
//O seu funcionamento é : o pino, a frequência e o tempo de duração em milissegundos

//delay (ms) between one tone and another.