For another project I needed to make an Arduino Uno play music using a buzzer. I wrote a sketch that was in my opinion a nice solution, and I was able to make the Uno play some simple music.
But when I tried to replicate the Super Mario Bros tune, it became apparent how time consuming it would be to compose many songs and sound effects manually. Writing the notes and time intervals in an array the sketch would iterate trough already took quite a while, but the endless adjusting afterwards wasn’t worth the effort.
So I tried to think of a solution.

Enter Piarduano for OS X

The solution I made became Piarduano: a Mac app written in Swift, that lets you easily compose and record songs for use by an Arduino. Your keyboard is converted to a piano: a certain key correspondents to a certain note, which is sent trough serial to the Uno. The Uno outputs the note to a buzzer using the tone() function. So you hear in real time what you are playing.
After you’ve recorded your song or sound effect, you can replay it, edit it, and most importantly, export it to code which you can copy and paste to you sketch. It couldn’t be any easier!


You can download the app or view the source code on GitHub!

Using Piarduano

You’ll need:

  • A Mac with Yosemite (I haven’t tried older versions)
  • An Arduino board with serial (e.g. an Uno)
  • A buzzer
  • A resistor (I used a 270Ω)
  • A breadboard and some wires or another way to connect the buzzer

Installation and wiring

Download the latest version of the Piarduano.app and the piarduano_receiver sketch from the ‘Releases’ tab in GitHub. Open the sketch in the Arduino IDE and upload it to the Arduino board.
Close the Arduino IDE but leave the Arduino connected to your computer.
Now connect the buzzer and the resistor in series between Digital Pin 8 (default) and Ground.

Open the Piarduano app. Select the correct serial port (should be something like /dev/cu.usbmodemfaXXX) and click on ‘Start’ to start the serial communication.
From now on, until the connection is closed, keyboard keys will trigger the Arduino to play a note.

Playing a song

By default, the app knows four rows of 12 keys:

  • 1234567890-=
  • qwertyuiop[ ]
  • asdfghjkl;’\
  • `zxcvbnm,./ ENTER

The notes assigned to each key in a key row are in the order C Db D Eb E F Gb G Ab A Bb B. So for example the key S would trigger a Db note to be played.
The first row has the highest pitch, and the last row has the lowest. Since four rows are not enough to cover 8 octaves, you can select the range of octaves in the main window (using the “Shift” selection).
The rest of the functions are quite self-explainatory. Press ‘Export to C’ to get the C code (two arrays and a #define) you can copy and paste to an Arduino sketch.
Of course, this isn’t enough by itself: you’ll have to add the code that will play the song. An example of such code can be viewed by pressing the ‘Show sample sketch’ button.
If you have any suggestions or questions, please let me know! Just leave a comment below.