How do i run two buzzers with one Uno at the same time

hello, i wanted two use piezo buzzers at the same time. how do i go about doing this?

Buzzer_Despacito.ino (18 KB)

Use one output for each buzzer.

Railroader: Use one output for each buzzer.

i did, the problem is the second one plays after the ist one. i want to play both at the same time. you will find two ouputs in the code -_-

I thought that a buzzer just used current or no current. That's the ones I have used. You use speakers.. Check the Arduino reference… https://www.arduino.cc/reference/en/language/functions/advanced-io/tone/

Firstly, the structure of your calls to midi1() and midi2() from loop() is going to finish midi1() before it gets to midi2().

void loop() 
  {
  midi1();
  midi2();
  }

So surely that's not even trying to use tonePin2 before tonePin1's work is done?

But apart from that, you need to see the what the tone() man page says:

Only one tone can be generated at a time. If a tone is already playing on a different pin, the call to tone() will have no effect.

ardy_guy: Firstly, the structure of your calls to midi1() and midi2() from loop() is going to finish midi1() before it gets to midi2().

void loop() 
  {
  midi1();
  midi2();
  }

So surely that's not even trying to use tonePin2 before tonePin1's work is done?

But apart from that, you need to see the what the tone() man page says:

but can i run both the tones at once with 2 buzzers?

VetKifayat: but can i run both the tones at once with 2 buzzers?

Not according to the part of the man page I quoted but which you didn't re-quote:

Only one tone can be generated at a time. If a tone is already playing on a different pin, the call to tone() will have no effect.

Maybe there's a workaround, to somehow "interleave" tones. Perhaps someone else will have some ideas?