user-1: I have figured out how to make a piezo buzzer play two tones at once with analogWrite() and tone() but how would I make an actual song by playing both bass and treble, such as this one. Here is the circuit I had to do it:

and here is the code I had to do it:
int buzzer1 = 9;
int buzzer2 = 10;

void setup() {
  pinMode(buzzer1, OUTPUT);
  pinMode(buzzer2, OUTPUT);
}

void loop() {
  analogWrite(buzzer1, 100);
  tone(buzzer2, 262);
}


user15180: First of all - You can drain max 20mA via pin, when one of the pins is HIGH and the other LOW, there is 5V between them, so there should be at least 250 Ohm resistor placed there, if you do not want damage your Arduino. I sugest add, to each of the red wires, at least a 200 Ohm resistor (to be safe).
For playing melody you have to save it somewhere, probabely easiest way is in arrays, and then play it note by note at regular intervals.
something like this (but insert your notes and set the length correctly):
int num_tones=6;
int tones1[] = {100,200,400,200,100,50};
int tones2[] = {262,131,131,262,131,524};

void loop() {
  for (int i=0;i<num_tones;i++){
    analogWrite(buzzer1, tones1[i]);
    tone(buzzer2,tones2[i]);
    delay(250);
  }
}


-1: <p>I have figured out how to make a piezo buzzer play two tones at once with <code>analogWrite()</code> and <code>tone()</code> but how would I make an actual song by playing both bass and treble, such as <a href="http://makingmusicfun.net/images/thumbs/twinkle-twinkle-little-star-piano-solo.jpg" rel="nofollow noreferrer">this one</a>. Here is the circuit I had to do it:</p>

<p><a href="https://i.stack.imgur.com/H2Q1R.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/H2Q1R.png" alt="Circuit"></a></p>

<p>and here is the code I had to do it:</p>

<pre><code>int buzzer1 = 9;
int buzzer2 = 10;

void setup() {
  pinMode(buzzer1, OUTPUT);
  pinMode(buzzer2, OUTPUT);
}

void loop() {
  analogWrite(buzzer1, 100);
  tone(buzzer2, 262);
}
</code></pre>
 15180: <p>First of all - You can drain max 20mA via pin, when one of the pins is HIGH and the other LOW, there is 5V between them, so there should be at least 250 Ohm resistor placed there, if you do not want damage your Arduino. I sugest add, to each of the red wires, at least a 200 Ohm resistor (to be safe).</p>

<p>For playing melody you have to save it somewhere, probabely easiest way is in arrays, and then play it note by note at regular intervals.</p>

<p>something like this (but insert your notes and set the length correctly):</p>

<pre><code>int num_tones=6;
int tones1[] = {100,200,400,200,100,50};
int tones2[] = {262,131,131,262,131,524};

void loop() {
  for (int i=0;i&lt;num_tones;i++){
    analogWrite(buzzer1, tones1[i]);
    tone(buzzer2,tones2[i]);
    delay(250);
  }
}
</code></pre>
