Hi,
I need to use a piezo buzzer, but I can't use tone(). It doesn't work in my program. Do you have any alternative?
Thanks
Hi,
I need to use a piezo buzzer, but I can't use tone(). It doesn't work in my program. Do you have any alternative?
Thanks
HINT - The [u]Blink Example[/u] makes a 1/2Hz square wave. You probably want a square wave somewhere around 2kHz. The Blink Without Delay example also makes a (slow) square wave.
HINT - You'll probably want to use microseconds instead of milliseconds.
...The advantage of tone() is that it runs on chip-timers in the background. The blink-style timing runs along with any other code you're running so the other code can mess-up the sound and the tone-generating code can interfere with (or slow down) your other code.
Also, if you want to generate different tones make sure you have a piezo transducer/speaker. A transducer/speaker reproduces the AC audio fed-into it.
A "buzzer" has a built-in circuit to generate sound when you apply DC voltage... It won't work with tone().
A buzzer may work for you but you can't control the frequency and it may take more current than you can get from an Arduino I/O pin.
There are some alternative versions of tone() but whether they'd be any use to you depends on why tone() won't work in your program.
Steve
I can't use the tone () because I am using a stepper motor and when I use tone() the stepper doesn't work
Yes, read reply #2 again.
Lily_B:
I can't use the tone () because I am using a stepper motor and when I use tone() the stepper doesn't work
That doesn't tell me much but if the problem is a timer conflict you could try the NewTone library. That uses a different timer from the normal tone() function.
Steve