Concept: Create a feedback loop between a motion sensor and MP3 player volume
I wanted to create a positive feedback system to encourage more activity during a workout. What I came up with is an MP3 player that is controlled by continuous activity. After working with it and discussing the project with friends, I believe this concept could be implemented many different ways and maybe even directly embedded in a media player. Someone even brought up that they change the volume on their iPod to hear the songs as they workout or run harder just to hear the song better. Yeah Power Song!
My proof of concept uses a SparkFun MP3 Trigger, Parallax PIR Motion Sensor, and an ioBridge IO-204 Controller. When motion is detected by the PIR sensor, the IO-204 sends serial commands to the MP3 player to raise or lower the volume. An added benefit to using the IO-204 as the controller is that I have the ability to data log my activity when it's net-connected.
Step 1: Gather Up Components
Time to gather up your system components:
SparkFun MP3 Trigger
Parallax PIR Sensor
ioBridge IO-204 Controller
Micro SD Card with Favorite Songs
Step 2: Modify Enclosure
After finishing up my cup of General Foods French Vanilla Cafe, I noticed that the container would be a perfect project enclosure - kind of like a taller Altiods tin so many people use.
I drilled four holes in the bottom and placed screws to act as standoffs for the MP3 Trigger. I also drilled out a larger hole on the font side to support the motion sensor. On the back, I made holes for the speaker connection and hookup wires to the IO-204.
Step 3: Setup the SparkFun MP3 Trigger
Program 9600 Baud Firmware (optional)
I wanted the MP3 Trigger to support 9600 baud for more controller flexiblity, so a friend reprogrammed the MP3 Trigger with new firmware. He found the firmware and instructions on the creator's website. To re-burn the firmware you will need a Cypress MiniProg.
Load Songs onto Micro SD Card
Copy songs over to a microSD card. The card must be formatted using FAT16. The songs support a constant bit-rate sampling up to 192kpbs.
The MP3 has three pins that are required to be connected to the IO-204 - GND, USBVCC, and RX. There is also a switch that should have "USB" selected. This will allow the MP3 trigger board to powered by the USBVCC pin. Connect the corresponding pins to the IO-204.
Control Playback and Volume
The serial protocol is simple. Send the serial string "O" to start / stop the MP3 player. Send "v%01" to set the volume to the maximum. To lower the volume send serial strings of "v%XX" where XX is a number between 01 and 40 - "01" is the loudest and "40" is really low.
Step 4: Setup the Parallax PIR Motion Sensor
The PIR sensor has two modes: High and Low. When the sensor is placed in "high" mode, the sensor will go high and stay high as motion is detected. In "Low" mode, the sensor pulses when motion is detected. (Also used this guy on the Half-Hour Halloween Hack)
I used the High mode to interface with a digital input on the IO-204. Connect the "+" and "-" to the +5v and GND of the IO-204.
Motion Sensor Notes
The PIR sensor can detect motion up to 20 feet away. I found that the sensor works best after a minute of no activity right after the sensor receives power. Parallax mentions this is the sensor calibration phase.
Step 5: Setup the IoBridge IO-204 Controller
The IO-204 acts as the controller taking input from the PIR sensor and controlling the MP3 Trigger. I used two different channels in my demo, but afterwards I figured out how to use one channel.
Each channel has Serial Out, Analog Input, and Digital Input. The PIR sensor connects to the Digital Input (pin 2) and the MP3 Trigger's receiver connects to the digital output (pin 3) of any open channel.
Create Onboard Rules
The IO-204 is programmed via a web interface. You want to create "Onboard Rules". They are "programming-lite" or "logical triggers - if then", if you will. Once the rules are programmed, they reside on the IO-204 with or without a network connection. That feature came out in one of the recent firmware revs, so make sure you're up to date. The IO-204 has a dual red/green LED to indicate it's network status. RED is offline and GREEN is online.
I wanted the IO-204 to change the volume of the MP3 track as motion is detected. As more motion is detected, the volume should increase to a maximum level by stepping through volume levels. I decided on 4 volume levels as a first attempt. When the MP3 player starts a track the volume is low. I also decided to check the motion status every two seconds. If there is continuous motion, over 8 seconds the MP3 player will reach the highest volume level. The volume will step down in volume as activity decreases.
When you have created your states, make sure you click "Sync Rules" to transfer your rules to the IO-204 module.
Log Your Activity
When the IO-204 is online, the module can push data to the ioBridge servers to be data logged. I created a digital input log (for both the high and low states). The data is accessible via an API. With a simple PHP script my friend was kind enough to assist with, I added up all of the the high states to see how much activity the system logged.
Step 6: Stay Healthy
After some tweaks and tuning, I got the volume states to where I wanted them. Overall I am very happy how the proof of concept turned out. In the process, I also found another use - motion detector, IO-204 sending email when motion is detected or play a sound as an alarm that is triggered by motion. Or if I slack off too much, perhaps I will have it play some "encouraging words" from R.Lee Ermy (the Full Metal Jacket drill sergeant.).
Stay healthy my friends,