The Ambient Tuner

Saummya Kaushal (sk868)

Madhuvanthi Jayakumar (mj299)

Table of Contents

Introduction

Overview

Background

High Level Design

Rationale and Sources of Project Idea

Background Math

Logical Structure

Workflow

Hardware/Software Tradeoffs

Relationship of Design to available IEEE, ISO, ANSI, DIN, and other standards

Existing Patents, Copyrights and Trademarks

Hardware Design

Motion Sensing - PIR

User Inputs

Light Sensing

Temperature Sensing

LED

LCD

Speaker

Voltage Shifter

Challenges

Software Design

FatFS

Matrices

Categorization

Tasks/Documentation

Results

Speed

Accuracy

Safety

Interference

Usability

Conclusion

Analyze Design - Meeting Expectations

Intellectual Property

Ethical Considerations

Legal Considerations

Appendix A: Commented Program Listing

Appendix B: Schematics

Appendix C: Cost Details

Appendix D: Specific Tasks Carried out by each team member

References

Data Sheets

Vendor Sites

Code / Designs borrowed / Old Projects

Background sites / Paper / Parts

Acknowledgements

 

Introduction

The Ambient Tuner determines and plays music based on the mood of the environment. It senses light and temperature to determine mood and will play music through FM modulation. In addition to this, it will start playing music when it when it senses motion. The user interaction is primarily meant to be passive and the Ambient Tuner will adjust the mood of the environment in real time.

Overview

Project Description
The Ambient Tuner selects music from a playlist based on surrounding environmental factors i.e. lighting, temperature and human motion.

Background

The Ambient Tuner is a very practical, applicable and usable product for everyone, especially music-lovers like yours truly! This is one of the primary reasons that we chose to play music from a playlist rather than creating Markov matrices from notes. Although this means we choose the tradeoff of having more hardware and less flexibility in using visual aids, this also meant that TAT will be more practical for those who want to have an automatic and smart music player.
The primary focus of TAT will be on producing automated choices of music based on environment but an extension of the project could have a human interaction part that can override the automation based on musical preferences.

High Level Design

Rationale and Sources of Project Idea

The rationale behind our idea was to build a music player that would change dynamically based on changes in the environment and what kind of mood it sensed. People want to listen to different kinds of music different environments and different situations. Automated process to detect the ambience and select music accordingly ( a smart-dj, if you would) would ease the task of music-lovers who would otherwise have to change music themselves.
This idea came about through a combination of considering things along the lines of a music device or a project using solar energy and the final idea sprung up as a combination of the two to use light and temperature to control music selection. It is practical since there is often a correlation between the ambience of the room and the mood. The lighting and temperature dictates the feel of a room and the activity that goes on in the room and The Ambient Tuner will provide appropriate music for the situation. Noting that music is a prominent part of most peoples lives, whether it’s background music for studying, background music for dining or get together, or prominent music for dancing and socializing. Instead of having to manually create playlists or choose songs for each scenario, having the Ambient Tuner will take care of this for you.

Background Math

We used some basic math for timing purposes. The same timer 0 and 1 were used that we did for Lab 3. Since timer 1 ticks at 8 KHz, the time period we get from a “time” variable is 125 microseconds. We use this variable to get various time periods. For example, to get a time period of 50 ms, we multiply it by 400. To get a bigger time period (5 seconds for the temperature and light sensing), we used another task which is called every 50 millisecond. This task increments a counter variable and when the counter = 100, we call the sensing task. (50*100 = 5,000 milliseconds = 5 seconds).

Logical Structure

The logical structure of the device is the following. It starts off displaying “Welcome to the Ambient Tuner”. When it detects motion, it knows that there is someone in the vicinity, so it proceeds to detect the lighting and temperature of the surrounding. When it gets the value for this, it will make a music selection accordingly and will play music. It will keep taking measurements of lighting and temperature and when it changes significantly enough to go onto the other categories according to our specifications; it will change the nature of the music to reflect on the new setting.

Workflow

The flow chart below demonstrates the process we used to build our device. We used an incremental design process and version control to develop and test each piece using environmental factors and the UART before moving onto the next. We started off building wiring up the light sensor and testing it under room light (neutral) extra lighting (bright) and by covering it up (dark) and determined the average voltage value for each of these cases and used those as cut-off values for determining the lighting of the environment. Then we did the same with temperature and made it warm by putting our hand over the temperature sensor or focusing light on it. We used the combination of these two values to set categories. Next we added the PIR sensor and a state machine so it only starts playing and detecting values when it senses motion.  Next, depending on the values read, the state machine will direct what will be displayed on the LCD. The LEDs were then hooked up with the purpose of flashing them according to settings, and an attempt at hooking up the SD cards were made. We built the voltage shifter circuit using diodes and resistors, set up the SD card on the breakout board, connected the inputs and outputs of SPI and added the voltage regulator (since the SD card runs on 3.3 V and the MCU outputs 5 V). When we ran into issues, we decided to go ahead with the matrix FM-modulation to fulfill the purpose of the device to play music depending on mood. Once we created the matrix, we hooked up the speakers to play the music.

Hardware/Software Tradeoffs

We considered a lot of tradeoffs both between hardware and software as well as design tradeoffs for usability and practicality.


Hardware Tradeoffs
We started off considering red, green and blue LEDs to detect lighting since not all LEDs respond to the various colors of light due to band gap since the fixed bandgap sets the color. The light of longer wavelength won’t excite the band gap so they are spectrally sensitive. The three LEDS would have filled the gap and detected the amount of incoming light based on the voltage they provide. Using the measured voltage and taking into account the amounts of different colors of light, it would’ve been possible to determine the amount of light coming in. Since the voltage output is proportional to intensity this would’ve been straight forward. Red LEDs would’ve responded to green and blue and green LEDs would’ve responded to red but not blue and blue would not respond to green but it would respond to ultraviolet. We could’ve also used the TSLR235 for more linearity or higher sensitivity. It is an intensity to frequency converter and it has a log-linear response rate from 10^-2 lumen to 10^5 lumen.

We also could’ve used a thermistor, which is a negative temperature coefficient device and decreases about 4percent per degrees C. Another thing we decided to forgo was to use thermally coupled dissimilar metals that would be welded together. They would’ve been accurately calibrated and would’ve been highly accurate but would have been hard to work with.

Software Tradeoffs

Another thing we had to consider was how to categorize songs. We considered the possibility of having the controller automatically choose songs after parsing through the tones to determine what kind of song it was. However, we quickly decided against this as it is not realistic to attempt to do this with a limited amount of time. Then we decided to have prefixes for the songs to let the controller know which to choose, if we were to use the sd-card for music.

Hardware vs. Software Tradeoffs
1. Using SD Card with MP3 or waveform files (waveform eliminates need of MP3-converter) to select songs from a playlist based on the filename prefixes. This adds to hardware and software complexity but makes our player a lot more practical and useable. In this case, the user can put their own playlist (with a few constraints on how the file is named) on the SD card giving them more flexibility.

2. Building multiple matrices of music that would be reflective of different moods. The incoming parameters of light and temperature will choose one of the matrices and play a song that will be created by the matrix but will simulate a song by an artist. This would eliminate the need for the SD card and have more software involvement.
3. Machine Learning Markov Matrix that has a memory of more than one note, and would learn based on user inputs that override the automation. This would be something we could do as a long term project. This would also eliminate SD card (hardware) and have much more involvement in software.

Relationship of Design to available IEEE, ISO, ANSI, DIN, and other standards

Our project adheres to the IEEE Code of Ethics, standards set by the SD Association for using the SD card through an SPI interface.

Existing Patents, Copyrights and Trademarks

We do not know of any existing patents, copyrights or trademarks that exist with respect to this project.

Hardware Design

 Our hardware is described in the block diagram schematic below.

Each additional section below will go into more detail about how the hardware was connected.
On the input side, we have the following hooked onto the controller:

  1. Light sensor (Connected to A0)
  2. Temperature sensor (Connected to A1)
  3. Motion sensor (Connected to A2)

On the output side, we have the following:

  1. LCD panel to display the mood detected and the song playing. (Connected to Port C)
  2. 10 LEDs (red, green and yellow) which blink with different frequencies depending on the mood (Connected to A3 – A6 and D2 – B7)

Motion Sensing - PIR

The PIR (Pyroelectric ("Passive") InfraRed) Sensor is used to detect the presence of human in the near vicinity. If it detects someone, then it will send a signal to the MCU which will then proceed to change the state of the machine to start playing music.

It is a pyro electric device that detects motion by measuring changes in the infrared levels emitted by surrounding objects.  This motion can be detected by checking for a high signal on a single I/O pin. The idea behind using this was that we only play music if there’s activity detected and hence, save energy. Additionally, we connected the sensor to a red LED which lights up when motion is detected. This LED was initially added by us for debugging purposes but we kept it there since it’s a good visual way for the user to see the system light up before it starts playing music.

Light Sensing

We used a photocell (photo resistor) as a light sensor. This gives variable resistance under different light intensity - high resistance under dim light and low resistance under bright light. So, we built a voltage divider with the photocell as one resistor and a 51 kΩ as the other one. So, in the following figure, r = 51 kΩ and R is the photocell. Ain is the voltage measured and instead of calculating the value of R and using that to determine the light intensity, we directly used the value of Ain. After doing some measurements with the light sensor, we decided on the following ranges:
>200 - Bright, 150-200 Neutral, <150 - Dark

 

Temperature Sensing

It is a precision integrated-circuit temperature sensor, whose output voltage is linearly proportional to the Fahrenheit temperature. Since the scale factor of the temperature sensor is 10mV/˚F and one unit in the ADC result is 2.56/256 = 10 mV, the ADC result reading is exactly the actual temperature reading in Fahrenheit. This made it easier for us to categorize songs. We decided on the following ranges:

>80˚F – Warm, <80 ˚F - Cold

LED

In addition to the LED we used with the PIR sensor, we used 10 other LEDs (5 red, 3 green and 2 yellow) to create a triangular structure which blinks when music is playing. Depending on the mood, the LEDs blink at different frequencies. The LEDs are connected to the MCU in the following manner:

LCD

The LCD display will start of displaying “Welcome to the Ambient Tuner” and then it will proceed to display the kind of mood detected, one of the following: Summery, Wintery, (?) , etc, etc.

Speaker

We connected the speakers to an audio port which was then connected to a pwm output, voltage and ground.

Voltage Shifter

Challenges

Integrating the use of timer0 for both PWM output for music through the speakers as well as the use of sensors was one challenges. We got the two parts (sensors and music) working separately but to integrate it was a challenge, since we had to change everything else to use timer1.  (how we fixed it?)
We were pre-warned about the difficulties of using SD card from past projects but decided to give it a try. We formatted the card and first attempted to read the files from it. It mounted the file system but got stuck on a line to open root directory. When this didn’t work we moved onto creating music from matrices as a backup to fulfill the main idea of the project to play music based on the ambience. If we had more time we would’ve pursued this more and gotten the SD card to work as it would be more practical for the average user.

Software Design

FatFS

?

Matrices

We created Markov matrices to generate and play different kinds of music. We used the following matrices and parameters to go along with the various moods:
We created the Pirates of the Caribbean tone which plays with different instruments (and parameters) for different moods.

It’s a huge case statement which goes through the notes for the music which we got from this video: http://www.youtube.com/watch?v=gNbFkU4s3DM

The notes are:

Part 1
A3 C4 D4 D4 D4 E4 F4 F4 F4 G4 E4 E4 D4 C4 D4

Part 2

The same that the part one.
Part 3 
A3 C4 D4 D4 D4 F4 G4 G4 G4 A4 A4# A4# A4 G4 A4 D4 D4 E4 F4 F4 G4 A4 D4, D4 F4 E4 E4 F4 D4 E4
Part 4
A4 C5 D5 D5 D5 E5 F5 F5 F5 G5 E5 E5 D5 C5 D5 
Part 5

The same that the part four

Here are the following instruments which have different settings for parameters decay_main, rise_main, depth_fm1, decay_fm1 and inc_fm1:

Summery - Plucked String

Indie - Bowed String

Party - Small, Stiff Rod

Christmassy - Bell

Instrumental - Chime

Categorization

We split up the music into five categories and did this in the following way:
Categories of Lighting:
Voltage                                                Lighting
>200                                      Bright
<=150 & >=200                  Neutral
<150                                      Dark
Voltage                                                Temperature
>=80                                      Hot
<80                                         Cold
Combo Mood                    Setting
Hot & Bright                       Summer
Hot & Neutral                    Indie
Hot & Dark                          Party
Cold & Bright                      Christmassy
Cold & Neutral                  Indie
Cold & Dark                        Instrumental

Tasks/Documentation

All of our data is in FINAL.c(?). We split up the code into the following tasks:
ISR(void)
Detect_control(void)
Task1()
                This tasks gets the input from the light sensor, temperat
Task2()
Increments counter to keep track of 5000 milliseconds.
playmusic()
                This task contains a state machine that determines when the tool should start playing (which is determined by when the PIR detects motion)
LCDtask()
                This task controls the LCD display. It has the following format:
                -----------------------------------
                Mood Detected:
                SongType
                -----------------------------------

LEDtask()
This task flashes LED based on mood of environment. The rate that this task gets called depends on the mood of the environment and/or notes so it can either flash fast or slowly.
getParam()

  1. Has matrix of notes
  2. Selects matrix, and variable for instruments based on mood

Initialize()

  1. Sets port A as input for first three pins for input from sensors and output for last five pins for the four LEDS.
  2. Sets port D as output for six LEDS
  3. Sets port B3 as output for the speaker
  4. Sets C as output for LCD
  5. Initializes sine table for audio
  6. Sets timer 0 and timer 1 variables
    1. (expand on this more?)
  7. Set timer variables and play state to idle, choose ini

Init_lcd()

  1. Initializes and clears LCD

Main()

  1. Calls Initialize to set appropriate variables and internal controls (?)
  2. Initializes LCd
  3. Infinite loop to call tasks at certain intervals that do the following things – increment counter, set parameter for matrix, gets sensor inputs, detects human motion, flashes ledsState Machines

Results

Speed

?

Accuracy

We tested all the different categories of music – by covering it up and making it dark, shining light on it to make it hot and bright (summery),

Safety

Our device is mostly contained within an un-conducting cardboard box. The only things outside of the box were the speakers, the wire supplying power to the MCU and the cables. The MCU, breadboards, devices, wires were within the box and away from the reach of the user. The outside of the box contained the LCD screen, sensors and flashing LEDs.

Interference

The Ambient Tuner does not interfere with other devices in many ways. If there were other devices recording sound then our Ambient Tuner would interfere with it because of the sound it produces. Besides that, it is a passive device, getting input from the surrounding and giving off no other forms of interference on to the environment.

Usability

The Ambient Tuner is user-friendly. It will detect human motion in the near vicinity and play music accordingly. The volume of the music can be controlled on the speakers themselves according to user preference. Right now it is a stationary device as it is contained within a 8x6x2.5in box and has to be connected to the cables and power supply and speakers. The LCD display on the box also informs the user of the mood of the surroundings. It starts detecting motion about 10 second after it is first turned on. After that, it detects motion right away.

Conclusion

As for future project extensions, we have a lot of things in mind. A starting point would be to add the use of SD cards as opposed to playing FM modulated music or in addition to FM-modulated music. This would be more accessible and user-friendly as the user can easily load up the SD-card with MP3 files, attach it to the device and listen to music at their ease. Another idea would be to make it smaller by building our own mega644 board, using smaller portable speakers, adding batteries and making it a mobile device. Still another easier extension is to add a user input portion to allow the user to override the automated music/mood selection in cases where the user either wants to completely override the song or category, or change the default settings for the threshold temperature and light to move from one setting to another. Further additions could be to make these user inputs through a touch screen selection, and to consider more inputs that are correlated with ambience to get a more accurate sense of the surroundings. Furthermore, human motion can be used for more than just determining when to start the Ambient Tuner. If no motion is detected for about 15 minutes, then the music should stop.

Analyze Design - Meeting Expectations

We started off wanting to control music based on the mood of the environment. We had ideas to do it through using light, temperature and motion sensors to select songs from a playlist that would be stored in SD-cards that would have prefixes for the different categories. Our projects evolved as we were building it. We changed the number of categories to six to account for the three changes in light (dark, neutral, bright) and two categories of temperature (high and low) and used human motion not to determine mood but to determine if there’s a presence of humans in the near vicinity to start music.
We also used a light sensor to detect lighting rather than using three LEDs to determine incoming rays – we discuss this more in the trade-off section of the report.
Our use of SD card has been evolving from the very beginning. We began wanting to store MP3 files as this will be the most user friendly. Since this required the MP3 decoder and extra hardware, we decided instead to use waveform files, though they take more space on the SD card but it would eliminate the need to use the MP3 decoder. Towards the end, we decided to generate our own music in matrices because of the challenges and variability of getting the sd card to use as well as having more control over the generation of notes and instrumentation used.  
We met some of our basic expectations for the project, but evolved it to better fit our needs throughout the five weeks. Changes we’d consider for the next time would be to order our parts earlier next time,
See above this section for Design approaches for extensions of the project.

Intellectual Property

We came up with the idea for our project when we were considering designing a project that could possibly be powered by solar energy and one that involved music. We combined this idea to come up with the Ambient tuner which uses lighting in addition to temperature and motion sensing to control music from a playlist. Our brainstorming of ideas was influenced by Professor Bruce Land who helped us come up with ideas related to music and otherwise and provided ideas on implementation while discussing our idea with him. He also talked about “Ambient Tuning” which directed us towards the name we used for the project. The implementation of this project is our own work and we used many references on the internet, including data sheets and previous projects which used similar technologies which we discuss more in the references section of this report. Some libraries and files we use for this lab include – LCD_lib, uart, fatfs file system.
There may be patent opportunities for this project, though we are not planning on applying for patent. We believe that no such product exists in research or in the marketplace currently. It was a fun project and idea that has very practical applications and we would personally use our device as an auto-smart-DJ for our apartment. Future considerations for this project could be to make it portable and have headphone ports so the user could have the option of keeping it stationary or having it with them at all times. Other additions would be to have recommendation systems and a machine learning process to learn the taste of the user so the music wouldn’t have to be preset for the five “mods”.
We also got the idea to use a PIR sensor from this project and learned about the equipment we needed to use for the SD card from this project (though we circumvented one of their steps by directly uploading .wav files instead of using an MP3 decoder to convert this).

Ethical Considerations

We followed IEEE Code of Ethics and our reports are accurate to the best of our knowledge. Our device poses does not pose any health risks. The only thing that we did that could’ve disturbed others in the lab was testing music playing which we didn’t do until the last week, even then we kept the music at a low enough level that it wouldn’t have significantly disturbed other students. Besides that, we worked on light, temperature and motion sensors which are relatively low radar work in terms of how it affects our lab neighbors.
We made decision choices taking into consideration safety and IEEE Code of Ethics. In order to avoid hazards with wires, we eliminated the use of multiple wires by using the jumper cables so we only had three main connections to the MCU. In addition, we made our wiring as compact as possible, and confined all electronics within a non-conducting cardboard box to keep away from harming the user through shocks or overheating of devices. The sensors are relatively small and do not pose risk.
No one was ever injured in lab and all dangerous wiring was always kept out of everyone's ways and contained. The 4760 lab provided a friendly and welcoming atmosphere to work, ask for help, learn and contribute. The open source code of previous 4760 projects also offered a collaborative environment to share ideas and constantly create new and interesting products that are innovative, cutting edge and practical.
Our product is meant to be useful in a day-to-day manner for everyone, especially music enthusiasts. It  can be seen as a smart-DJ that adapts to the mood of the environment and we’ve uploaded the code along with this document for use of others who want to improve upon our device and/or learn from it.

Legal Considerations

Our device is safe to use, it is fully contained within the box so the wiring does not pose as danger to the user. Only the Port wires and power wire would need to be attached and the rest is preconfigured. It should be kept dry and relatively cool.

Appendix A: Commented Program Listing

FINAL.c

Appendix B: Schematics and Images

1. Figure 1.1: Sensors

2. Figure 1.2: Sensors and LED

3. Figure 1.3: Sensors, LEDs, LCD

4. Figure 1.4: Ambient Tuner Top View

5. Figure 1.5: Ambient Tuner with Speakers

\

1. Figure 2.1: LED circuit

2. Figure 2.2: Light Sensing Circuit

3. Figure 2.3: PIR Circuit

4. Figure 2.4: Temperature Sensor Bottom View

Appendix C: Cost Details
     

Part Name  Quantity Unit Price ($) Total Price ($) Vendor Part Number
STK500 1 15.00 15 Lab N/A
RED LED 6 0.07 .42 Lab N/A
GREEN LED 3 0.07 .21 Lab N/A
YELLOW LED 2 0.07 .14 Lab N/A
PIR Sensors  1 N/A N/A Lab  
SD card   1 10.00 10.00 Previously Owned  
Speakers  2 N/A N/A Lab  
Temperature Sensor  1 N/A N/A Lab LM34
LCD 1 8.00 8.00 Lab  
Light Sensor  1 N/A N/A Lab  
Jumper Cables  3 $1 $3 Lab  


Appendix D: Specific Tasks Carried out by each team member

Task Saummya Madhu
High Level Design yes yes
Software yes yes
Hardware yes yes
Drawing Schematics yes yes
Sourcing Components yes yes
Sensors yes yes
LCD yes yes
LEDs yes yes
SD card yes yes
Matrix yes yes
Debugging yes yes
STA013 yes yes
Status Reports to TA yes yes
Webpage and documentation yes yes

 

References

Data Sheets

  1. Motion Sensing – PIR
  2. User Inputs
  3. SD Card Holder
  4. MP3 Decoder  VS1011E-L
  5. Light Sensing (Saummya – datasheet?)
  6. Temperature Sensing
  7. Speaker
  8. Voltage Shifter

Vendor Sites

Digikey
SparkFun

Designs Referenced

1) Solar Hot Water Heater Net Energy Monitor - for temperature sensing and sd cards

2) GPS Data Logger with Wireless Trigger - for Reading and Writing to SD card

3) LightRover Light Sensing Robot - for Light Sensing

4) Motion Sensing PowerPoint Controller - for SD card to Audio and PIR

5) Music Playing Alarm Clock - for SD card and fatfs file system

Background sites / Paper / Parts

We decided to use PIR Sensors to detect when a person enters the room to start playing music
http://www.adafruit.com/blog/2009/08/21/how-to-use-pyroelectric-passive-infrared-sensors-pir/

Acknowledgements

A big thanks to Bruce Land for his help and guidance throughout the semester, and making the lab space and equipment available for our use and experimentation. We would like to give a special thanks  to Michael Lyons for helping us fix our timer and for helping us tremendously throughout the semester. We would also like to thank the other TAs, Pavel, Joe and Ninoshka for their help.