Start/Stop/Reset the melody using buttons I have 2 buttons.  Button 1 will start/stop the melody while the button 2 will reset the melody. My melody is "Happy Birthday".

How am I going to use the buttons to start/stop/reset the melody?

Here's the code:

#include "pitches.h" 

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

int noteDurations[] = { 
    8,8,4,4,4,2,8,8,4,4,4,2,8,8,4,4,4,4,3,8,8,4,4,4,2
}; 

boolean needtoPlay;

void setup() { 
    pinMode(4, OUTPUT); 
    pinMode(2, INPUT); //START/STOP
    pinMode(3, INPUT); //PAUSE
} 

void loop() { 
    for (int thisNote = 0; thisNote &lt; 26; thisNote++) { 
        int noteDuration = 1000 / noteDurations[thisNote]; 
        tone(4, melody[thisNote], noteDuration); 
        int pauseBetweenNotes = noteDuration * 1.60; 
        delay(pauseBetweenNotes); 
        noTone(4);

        if (needToPlay == true) {
        }
    } 
}
Modify your code so notes will play using timer interrupts instead of delay(). Once your program is inside delay(), no button will be responded. Done that, you just have to read buttons either by polling them with digitalRead or using interrupts.