Sing a Song

CurieBot loves to sing! You can have her drive up and serenade someone by adding a piezo buzzer and some software.

Open the Ada_CurieBot_RC_Song sketch in the Arduino IDE and upload it to your robot.

In this code snippet you can see how you'll use the tone() command to make music. The melody[] array and noteDurations[] array are used to describe the pitch and time value of each note. 

CurieBot will play "Shave and a Haircut" by default, but you can change the song to anything you like, or even add other tunes, each one controlled by a different number on the Bluefruit LE app.

Download: file
      //music
      if (buttnum == 2){
        int melody[] = {262, 196, 196, 220, 196, 0, 245, 262 };
        int noteDurations[] = { 4,8,8,4,4,4,4,4 };
        for (int thisNote=0; thisNote < 8; thisNote++){
          int noteDuration = 1000 / noteDurations[thisNote];
          tone(12, melody[thisNote], noteDuration);
          int pauseBetweenNotes = noteDuration * 1.30;
          delay(pauseBetweenNotes);
          noTone(12); 
        }
      } 

Now, use the Bluefruit LE app to drive CurieBot, and then whenever you press the "2" button, CurieBot will play a song!

Now that you've built your own robot friend, what kinds of modifications to hardware and software will you make next?

This guide was first published on Apr 01, 2017. It was last updated on Apr 01, 2017. This page (Sing a Song) was last updated on Sep 17, 2019.