Motion Sensor Jingle Player – Code

The code included a custom library we built, the Alarm library. The library contains functionality that lets users build their own Jingles to be played, as well as some built-in, default jingles.

The note() method

The main part of the Alarm library is the Jingle class’s note() method, which simplifies the process of playing tones for the user. The note() function makes use of the Arduino tone() and delay() functions. The tone() function outputs a specified frequency to a specified output pin for a specified duration. Since the tone() function doesn’t wait for the note to complete before moving onto the next command, the delay() function is called so that the notes can be properly spaced.

To let users make jingles more easily, different musical notes are pre-programmed. The notes are set to the corresponding frequency that the Arduino’s tone() function will use to play the note.

One of the preset alarms