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

Motion Sensor Jingle Player – Big Picture

The goal of this project is to create a motion detected alarm system with a button to turn the alarm on or off and toggle between different jingles.

When the PIR motion detector is triggered, a Honeytone speaker will play a jingle, controlled by a custom C++ library. The jingle won’t play if the alarm isn’t set; the user can tell because of an LED that is lit up when the alarm is on. The pushbutton, when long pressed, turns the alarm on or off; if short pressed, it will toggle between different preset jingles.

The project uses an Arduino board because of the built-in library to output single-frequency tones. Originally, the project also used interrupts, but it conflicted with the Arduino’s library; instead, logic for all inputs and outputs is handled within the loop() method.

The project was a success: the motion detector will trigger and the speaker play the selected jingle when the alarm is on, but won’t do anything when the alarm is off.

Basic Demonstration Video

Motion Sensor Jingle Player – Schematics

Motion detector
Cardboard walls

The final design made use of a PIR Motion Sensor. The sensor is powered to 5V, grounded, and connected to digital input pin 2 on the Arduino board. The motion sensor has two potentiometers on its side, one which controlled the sensitivity and another which controlled the delay between detection signals.

The motion detector is able to detect motion from across a room, which caused some issues with staying as still as possible while trying to test and eventually led to the design of cardboard walls for the sensor. The walls act as blinders to narrow the sensor’s detection range and simplifies testing. In a general purpose design, the walls would make sure the sensor only detects motion it’s supposed to.

Full Schematic