Multiple Piezo Output Same Freq.

Hi guys, I have been hanging around this great forum for a while but this is my first post - I hope you can help! I am pretty new to everything arduino although I have built one from scratch.

I have been reading up on connecting multiple piezo's but they all seem to focus on creating polyphonic tones. My project is slightly different.

I want to connect 10 piezo buzzers that all make the same tone but each can be switched on and off individually. I know that that the tone() uses one of the internal timers to generate the frequency to pulse one pin and that you have to call noTone() in order to change the pin / freq. But is it possible to keep the same frequency going and just send it to more or less pins as required? Or am I am being stupid?

The idea is to make a touch feedback trainer to use on musical instruments such as sax and flute.

Cheers!

I am not precisely sure what you are trying to do, but if it doesn't matter what the tone is, and you are just trying to indicate a position on the instrument, then you could just use a load of piezo buzzers with built-in electronics. You just have to supply these with 5V and they buzz.

Check, but I'm pretty sure they are under the 40mA that a digital output can supply.

Hi, thanks for the replies. Using buzzers is certainly a simpler way of doing things but ergonomically I don't think they will work. The idea behind piezo's it to mount them on the keys, being fairly low-profile. In my case all the pearls have fallen out of my old sax which actually gave me the idea of replacing them with electronic gadgetry!

Thanks for the 555 suggestion Richard, I definitely think thats the way forward. Would you suggest that I have the piezo's connected in parallel to the 555 and have each circuit going through the arduino to switch it on/off ?

Cheers.

I don't see why you need a 555 to do this.

The tone command plays a square wave. The digital pin is simply turned on an off X times a second. I see no reason why you could not connect 10 peizos and turn the pins they are conenctoed to on and off together.

Of course there is the question of what else you need to do while you are doing this, but if you're just playing musical notes, a 440hz tone would only require you to change the state of the pins 440 times a second. And that is easily accomplished.

Sweet, thanks for all the help. I just ordered all the bits and will get going as soon as they arrive. If I come up with a decent training system then I will post a video and my sketch. Perhaps some Coltrane wannabes (like me) will find it useful :slight_smile:

Also, if you want all the piezos to play the same tone at the same time, and never turn any of them off individually (I don't understand why you would want to do this, but...) then there's no reason you couldn't connect them all to a single pin.

Don't forget to use a resistor to limit the current, btw. A piezo acts like a capacitor. It'll draw a bunch of current for a moment when turned on.

Ah scswift it seems we were posting at the same time.

What I want to do is turn the piezo's on when that particular key needs to be pressed. The tone is the same for all the keys as they are simply providing vibrations that physically tell you when you need to press that key. So they do need to be on different pins and have individual control.

Are you saying that I could use the tone command to generate the square wave and send it to all the pins, then just turn each pin off separately? That was my original thought but as Richard said, tone() can only be used on one pin at a time.

This is all theory at the moment, as soon as I get the piezo's and start doing REAL work that's when things become clear to me.

For a somewhat different but also simple application I used this code here (I think exactly the thing scswift suggested). Note that it is blocking, but can easily be modified to work interrupt driven...

byte pinArray[] ={.....,0};  // add pin numbers here
boolean pinActive[sizeof(pinArray)-1];
boolean state;
const unsigned long someMS =1;

void loop(){

//set the pins you want output on in pinActive

 delay(someMS);

 state = !state;
 for (byte pin, i=0; (pin = pinArray[i])>0; ++i)
   digitalWrite(pin, state&&pinActive[i]);
}//loop

Are you saying that I could use the tone command to generate the square wave and send it to all the pins, then just turn each pin off separately?

No, I'm saying you don't need the tone() command. All the tone command does is turn a pin on and off rapidly. You can do that yourself though in code, easily.

The tone() command exists so you don't have to code your own command to play simple tones, and because it uses an interrupt attached to a timer or a clock or whatever so you don't need to pay attention to it after you start playing the tone and so the tone won't be interrupted when you do other things that require a lot of processor time.

But if all you need to do is vibrate the piezos, then I see no reason why you cannot simply hook each up to a different pin with a 1000 ohm resistor to provide 5mA at 5v to each piezo, for a total of 50mA, and then turn the pins on and off rapidly in code.

A 440hz tone produces middle C. I don't know what frequency you plan to vibrate your piezos at, but turning a pin on and off 440 times a second is well within the Arduino's capabilities. And I'm pretty sure turning 10 pins on and off 440 times a second is as well. Though it's possible you may need to write some messy code to set all the pins at once. I don't think so though.