Speaker wont work?

Hello and good day.
I have a circuit where i have three speakers, one connected to 8, another to 9, another to 10. They are all connected to ground.
My friend's code works perfectly.
My code does not. I initially ran my code and found that my speaker 10 was barely doing anything even when it the code it has the largest workload. I tested it with another speaker so it was not the speaker. I took all of my code for speaker 10 and placed it over to speaker 8:
Ex.

Originally

tone(10,NOTE_E4,500);
tone(8,NOTE_E1,500);
tone(9,NOTE_B4,500);

then i changed it into

tone(8,NOTE_E4,500);
tone(10,NOTE_E1,500);
tone(9,NOTE_B4,500);

=========================================
I used the same circuit for my friend's code and it worked with no errors so I suspect it being my code. I get no errors when uploading the code either. It just..doesn't run speaker 8(originally the code for speaker 10). Speaker 9 also gets a pretty high workload yet it runs smoothly.

Here is my code:

#define NOTE_B0  31
#define NOTE_C1  33
#define NOTE_CS1 35
#define NOTE_D1  37
#define NOTE_DS1 39
#define NOTE_E1  41
#define NOTE_F1  44
#define NOTE_FS1 46
#define NOTE_G1  49
#define NOTE_GS1 52
#define NOTE_A1  55
#define NOTE_AS1 58
#define NOTE_B1  62
#define NOTE_C2  65
#define NOTE_CS2 69
#define NOTE_D2  73
#define NOTE_DS2 78
#define NOTE_E2  82
#define NOTE_F2  87
#define NOTE_FS2 93
#define NOTE_G2  98
#define NOTE_GS2 104
#define NOTE_A2  110
#define NOTE_AS2 117
#define NOTE_B2  123
#define NOTE_C3  101
#define NOTE_CS3 109
#define NOTE_D3  147
#define NOTE_DS3 156
#define NOTE_E3  165
#define NOTE_F3  175
#define NOTE_FS3 185
#define NOTE_G3  196
#define NOTE_GS3 208
#define NOTE_A3  220
#define NOTE_AS3 233
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_CS4 277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4 370
#define NOTE_G4  392
#define NOTE_GS4 415
#define NOTE_A4  440
#define NOTE_AS4 466
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_CS5 554
#define NOTE_D5  587
#define NOTE_DS5 622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5 740
#define NOTE_G5  784
#define NOTE_GS5 831
#define NOTE_A5  880
#define NOTE_AS5 932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6 1109
#define NOTE_D6  1175
#define NOTE_DS6 1245
#define NOTE_E6  1019
#define NOTE_F6  1097
#define NOTE_FS6 1480
#define NOTE_G6  1568
#define NOTE_GS6 1661
#define NOTE_A6  1760
#define NOTE_AS6 1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7 2217
#define NOTE_D7  2349
#define NOTE_DS7 2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7 2960
#define NOTE_G7  3106
#define NOTE_GS7 3322
#define NOTE_A7  3520
#define NOTE_AS7 3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8 4435
#define NOTE_D8  4699
#define NOTE_DS8 4978
//========================================================================================================================================
void thing() 
{
 //INTRO
     //Measure 1:
   tone(10,NOTE_C3,800);
   delay(800);
   tone(9,NOTE_E4,590);
   tone(8,NOTE_C5,390);
   delay(400);
   tone(8,NOTE_C5,190);
   delay(200);
   tone(9,NOTE_E4,790);
   tone(8,NOTE_C5,590);
   delay(600);
   tone(10,NOTE_C5,190);
   delay(200);
   tone(9,NOTE_E4,790);
   tone(8,NOTE_C5,590);
   delay(600);
   tone(8,NOTE_C5,190);
   delay(200);
   tone(9,NOTE_E4,200);
   tone(8,NOTE_B4,200);
   delay(200);
     //Measure 2
   tone(9,NOTE_E4,500);
   tone(10,NOTE_E3,800);
   tone(8,NOTE_B4,500);
   delay(800);
   tone(9,NOTE_E4,190);
   tone(8,NOTE_B4,190);
   delay(200);
   tone(9,NOTE_E4,590);
   tone(8,NOTE_B4,590);
   delay(600);
   tone(9,NOTE_E4,390);
   tone(8,NOTE_B4,390);
   delay(400);
   tone(9,NOTE_E4,190);
   tone(8,NOTE_B4,190);
   delay(200);
   tone(9,NOTE_E4,390);
   tone(8,NOTE_B4,390);
   delay(400);
   tone(9,NOTE_E4,190);
   tone(8,NOTE_B4,190);
   delay(200);
   tone(9,NOTE_E4,190);
   tone(8,NOTE_B4,190);
   delay(200);
   tone(9,NOTE_E4,390);
   tone(8,NOTE_B4,390);
   delay(400);
   //measure 3
   tone(10,NOTE_C3,800);
   tone(9,NOTE_E4,390);
   tone(8,NOTE_C5,390);
   delay(800);
   tone(9,NOTE_E4,590);
   tone(10,NOTE_C5,390);
   delay(400);
   tone(10,NOTE_C5,190);
   delay(200);
   tone(9,NOTE_E4,790);
   tone(10,NOTE_C5,590);
   delay(600);
   tone(10,NOTE_C5,190);
   delay(200);
   tone(9,NOTE_E4,790);
   tone(10,NOTE_C5,590);
   delay(600);
   tone(10,NOTE_C5,190);
   delay(200);
   tone(9,NOTE_E4,200);
   tone(8,NOTE_B4,200);
   delay(200);
   //measure 4
     tone(9,NOTE_E4,590);
   tone(10,NOTE_E3,800);
   tone(8,NOTE_B4,590);
   delay(800);
   tone(9,NOTE_E4,190);
   tone(8,NOTE_B4,190);
   delay(200);
   tone(9,NOTE_E3,590);
   tone(8,NOTE_B3,590);
   delay(600);
   tone(9,NOTE_E3,290);
   tone(8,NOTE_B3,290);
   delay(200);
   tone(9,NOTE_E3,190);
   tone(8,NOTE_B3,190);
   tone(10,NOTE_E2,200);
   delay(200);
   tone(9,NOTE_E3,100);
   tone(10,NOTE_B4,100);
   delay(200);
   tone(9,NOTE_E3,300);
   tone(10,NOTE_B3,300);
   delay(400);
   tone(9,NOTE_E3,100);
   tone(10,NOTE_B3,100);
   delay(200);
   tone(9,NOTE_E3,100);
   tone(10,NOTE_B3,100);
   delay(200);
   tone(9,NOTE_E3,300);
   tone(10,NOTE_B4,300);
   delay(400);
   //measure 5
   tone(8,NOTE_A3,1500);
   tone(9,NOTE_E3,300);
   tone(10,NOTE_C4,300);
   delay(400);
   tone(9,NOTE_E3,300);
   tone(10,NOTE_C4,300);
   delay(400);
   tone(10,NOTE_D4,300);
   delay(400);
   tone(9,NOTE_E3,300);
   tone(10,NOTE_C4,300);
   tone(8,NOTE_G3,1500);
   delay(400);
   tone(10,NOTE_D4,300);
   delay(400);
   //measure 6
   tone(9,NOTE_E3,300);
   tone(10,NOTE_C4,300);
   tone(8,NOTE_FS3,400);
   delay(400);
   tone(10,NOTE_D4,300);
   delay(400);
   tone(9,NOTE_D3,500);
   tone(10,NOTE_C4,100);
   delay(200);
   tone(10,NOTE_D4,100);
   delay(200);
   tone(9,NOTE_D3,200);
   tone(10,NOTE_C4,200);
   delay(200);
   tone(10,NOTE_D4,700);
   tone(9,NOTE_D3,700);
   delay(800);
   tone(8,NOTE_D2,700);
   delay(800);
   //measure 7
    tone(8,NOTE_C3,800);
   delay(800);
   tone(9,NOTE_E3,500);
   tone(10,NOTE_C4,300);
   delay(400);
   tone(10,NOTE_C4,100);
   delay(200);
   tone(9,NOTE_E3,700);
   tone(10,NOTE_C4,500);
   delay(600);
   tone(10,NOTE_C4,100);
   delay(200);
   tone(9,NOTE_E3,700);
   tone(10,NOTE_C4,500);
   delay(600);
   tone(10,NOTE_C4,100);
   delay(200);
   tone(9,NOTE_E3,200);
   tone(10,NOTE_B3,200);
   delay(200);
   //measure 8
    tone(9,NOTE_E3,500);
   tone(8,NOTE_E2,800);
   tone(10,NOTE_B3,500);
   delay(800);
   tone(9,NOTE_E3,100);
   tone(10,NOTE_B3,100);
   delay(200);
   tone(9,NOTE_E3,500);
   tone(10,NOTE_B3,500);
   delay(600);
   tone(9,NOTE_E3,300);
   tone(10,NOTE_B3,300);
   delay(400);
   tone(9,NOTE_E3,100);
   tone(10,NOTE_B4,100);
   delay(200);
   tone(9,NOTE_E3,300);
   tone(10,NOTE_B3,300);
   delay(400);
   tone(9,NOTE_E3,100);
   tone(10,NOTE_B3,100);
   delay(200);
   tone(9,NOTE_E3,100);
   tone(10,NOTE_B3,100);
   delay(200);
   tone(9,NOTE_E3,300);
   tone(10,NOTE_B4,300);
   tone(8,NOTE_D2,300);
   delay(400);
   
   
   
}

void setup() {
  pinMode(8,1);
  pinMode(9,1);
  pinMode(10,1);

}

void loop() {
  thing();

}

And your electric circuit is what ? (One should NOT connect true speakers directly to pins. If you connected the speaker directly to the arduino, you have likely damaged your arduino pin by pulling too much current from it. It might still Appear to work but should not be relied upon)

Okay to clarify,btw thanks for the help, I am using 3 5v piezo speakers as normal. I connected the positive pin of the speaker to their corresponding pin(Ex. Speaker 8 is connected to pin 8 on the arduino.) and i have connected all of them to ground. As I said, the same circuit, and in turn the same speakers, works in my friends's code. If you need my friend's code, you can ask and i shall post it here

OK Piezzo are fine :slight_smile: (a small resistor can help limit the current just in case)

Which tone() function are you using? (I don't see any specific library).

if this is the built in one, if you read the tone() documentation you'll see that it's documented:

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. If the tone is playing on the same pin, the call will set its frequency.

Use of the tone() function will interfere with PWM output on pins 3 and 11 (on boards other than the Mega).

...

NOTE: if you want to play different pitches on multiple pins, you need to call noTone() on one pin before calling tone() on the next pin.

Also one should know that the tone() function call returns immediately

So in your INTRO if I separate things out:

//Measure 1:
tone([color=red]10[/color],NOTE_C3,[color=purple]800[/color]);
delay([color=purple]800[/color]);

--> here it's OK because you have 1 note playing on pin 10 for 800ms and you wait for the same 800ms in the delay. So once the delay() is complete, your pin is no longer used and the timer associated to tone() is ready to be used for another pin.

but the next one is a problem:
tone([color=blue]9[/color],NOTE_E4,[color=purple]590[/color]); You trigger pin 9 for 590ms
tone([color=green]8[/color],NOTE_C5,390); and you don't wait to trigger pin 8 so no sound will come out
delay([color=purple]400[/color]); more over you don't wait long enough as 400 is less than 590 and you exit the delay with NOTE_E4 still playing on pin 9

tone([color=green]8[/color],NOTE_C5,190); so this won't work either.

delay(200);

does it make sense on why you are having issues now?

that being said, if you look at The Tone Library it will supports playing more than one note at a time.

As you are limited to one tone per timer, the number of simultaneous notes depends on the number of timers available to you. On the Arduino Uno there are three timers but one is locked up by the core functions so you can play up to two tones at once. if you want three, you need to get an Arduino MEGA for example.

Oh I get it. Thanks a lot! But to clarify, in my understanding, to get more than three speakers playing you would need an arduino MEGA, then do I still get to use two speakers at the SAME time with an Arduino UNO or still just one? Also is my syntax(tone(10,NOTE_C1,300):wink: function as the same in The Tone Library documentation or are they different in both functionality and syntax?

Edit: Oh nevermind. I ran a few tests and discovered my Arduino Uno only plays one speaker at a time...
But my latter question still holds about my syntax and the syntax in the Tone Library documentation?

you need to use the new Arduino Tone Library I pointed above, download the library and its functions, then on your UNO you can play 2 tones

it's from 2010, so you might have to adapt a few things for it to work...

that's a small example on how things would work

They declare an array with two notePlayers

  notePlayer[0].begin(11);
  notePlayer[1].begin(12);

one on pin 11, the other on pin 12 and when they want to play a note on one of the pin they do notePlayer[0 or 1].play(frequency) and to stop a sound on one of the player notePlayer[0 or 1].stop();

// Duelling Tones - Simultaneous tone generation.
// To mix the output of the signals to output to a small speaker (i.e. 8 Ohms or higher),
// simply use 1K Ohm resistors from each output pin and tie them together at the speaker.
// Don't forget to connect the other side of the speaker to ground!

// This example plays notes 'a' through 'g' sent over the Serial Monitor.
// 's' stops the current playing tone.  Use uppercase letters for the second.

#include <Tone.h>

int notes[] = { NOTE_A3,
                NOTE_B3,
                NOTE_C4,
                NOTE_D4,
                NOTE_E4,
                NOTE_F4,
                NOTE_G4 };

// You can declare the tones as an array
Tone notePlayer[2];

void setup(void)
{
  Serial.begin(9600);
  notePlayer[0].begin(11);
  notePlayer[1].begin(12);
}

void loop(void)
{
  char c;

  if(Serial.available())
  {
    c = Serial.read();
    
    switch(c)
    {
      case 'a'...'g':
        notePlayer[0].play(notes[c - 'a']);
        Serial.println(notes[c - 'a']);
        break;
      case 's':
        notePlayer[0].stop();
        break;

      case 'A'...'G':
        notePlayer[1].play(notes[c - 'A']);
        Serial.println(notes[c - 'A']);
        break;
      case 'S':
        notePlayer[1].stop();
        break;

      default:
        notePlayer[1].stop();
        notePlayer[0].play(NOTE_B2);
        delay(300);
        notePlayer[0].stop();
        delay(100);
        notePlayer[1].play(NOTE_B2);
        delay(300);
        notePlayer[1].stop();
        break;
    }
  }
}

// To mix the output of the signals to output to a small speaker (i.e. 8 Ohms or higher),
// simply use 1K Ohm resistors from each output pin and tie them together at the speaker.

you need only one speaker

The link for the download is a 404 error for me... looks like my dreams were dashed once again... looks like I gotta stay with one speaker.
Thanks for the help though! Hope you have a good day(i don't know what time is it for anyone that reads this so yeah just have a nice 'day') :smiley:

Go to the tone library, click on download in the left side bar, find what is called Arduino-Library-Tone.zip if this links does not work and click there to download