-1

I have the following code that I use to try to play a melody on my Arduino, but there is no melody just a tapping noise.

I am using the built in tone() function to play on a speaker/buzzer.

I know my hardware setup is correct because running sample code online plays a nice melody.

void setup() { }
void loop() {

    noTone(6);
  // C7 in eighth
    tone(6, 2093, 250); delay(250);
    noTone(6);
    //B7 in eighth
    tone(6, 3951, 250); delay(250);
    noTone(6);    
    //G7 in fourth
    tone(6, 3136, 500); delay(500);
    noTone(6);
    //G7 in eighth
    tone(6, 3136, 250); delay(250);
    noTone(6);
    //F7 in eighth
    tone(6, 2794, 250); delay(250);
    noTone(6);
    //E7 in eighth 
    tone(6, 2637, 250); delay(250);
    noTone(6);
    //E7 in fourth
    tone(6, 2637, 500); delay(500);
    noTone(6);
    //G7 in eighth
    tone(6, 3136, 250); delay(250);
    noTone(6);
    //G7 in halves
    tone(6, 3136, 1000); delay(1000);
    noTone(6);
    //C6 in fourth
    tone(6, 1047, 500); delay(500);
    noTone(6);
    //B6 in eighth
    tone(6, 1976, 250); delay(250);
    noTone(6);
    //G6 in eighth
    tone(6, 1566, 250); delay(250);
    noTone(6);
    //C6 in eighth
    tone(6, 1047, 250); delay(250);
    noTone(6);

}

This is supposed to be the melody for poker face using the tone() function

2
  • you don't need noTone if you start another tone. – Juraj Dec 12 '18 at 5:02
  • 2
    The sample code you link to shows pin 8 as the connection, but your code shows pin 6. If your hardware setup is "Correct" because the sample code works, you have to look at what is then different between your code and the sample code that is known to work. – jose can u c Dec 12 '18 at 17:39
1

I just downloaded it, and it works for me.

Hmmm. Try downloading the other examples again, just to make sure you haven't moved a jumper.

Another way to check this out is to cut down the program to one or two lines, and see if that does or doesn't work.

0

What is the speaker/buzzer you are connecting to? It may need more current then the pin can support (a few tens of mA, absolute max of 40mA to prevent damaging the pin).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.