Output: Difference between revisions
No edit summary |
No edit summary |
||
Line 41: | Line 41: | ||
ylabel('Amplitude'); | ylabel('Amplitude'); | ||
axis([0 3600 -1 1]); | axis([0 3600 -1 1]); | ||
=== Result === | |||
== Feedback Statistics == | == Feedback Statistics == | ||
== Graphic Simulation == | == Graphic Simulation == |
Revision as of 00:36, 14 March 2016
Back to main page: PRE2015_3_Groep4
To the input: Input
To the code: Code
Light Brightness
Heating
Play Sound
The best way to produce sound with an Arduino unit is probably by using the Sparkfun MP3 Player Shield, which is an extra circuit board for the Arduino which can play MP3 files from a microSD card (seen in the picture to the right). The costs, however, are $25, which is too much unless the TU happens to have one we can borrow, which we will find out as soon as possible. But it’s best to consider cheaper options. More info about this product can be found at https://www.sparkfun.com/products/12660.
The Arduino has one function that’s widely used to produce sounds, namely tone(). This function can be used to produce tones of a single frequency. A duration can be added as a parameter or the tone can be stopped by using the function noTone(). Multiple tones can be combined to form more complex noises, but playing a tune with chirping birds or something to wake someone up would probably be too difficult. More info about the tone() function can be found at https://www.arduino.cc/en/Reference/Tone.
To create a tone, a simple speaker or a piezo buzzer will do. This one here seems promising (seen in the picture to the right), and cheap: only €1,95 (€0,97 with the discount at the moment). And if that won’t do, there are a lot of similar modules for sale on the internet.
To simulate the production of sound, a quick script has been written in Matlab (because Matlab is easier to use). This script contains two alarm sounds which are both modeled as sine functions but with different frequencies. The first alarm sound, Alarm1, begins playing at time tStart, which is the right time to wake up the user as calculated by the main script. This alarm would ideally be a natural and more relaxing sound, like chirping birds, but that's probably nearly impossible to do with the tone() function, so we'll have to find something else. The intensity of this sound rises gradually and reaches its maximum at tEnd, the moment the user MUST wake up. Or it stops at tWake, which is the moment the user wakes up. If he hasn't woken op yet, Alarm1 stops playing and is replaced by Alarm2, which will be a standard alarm noise. The intensity is set on its maximum to make sure the user wakes up. When he does, at tWake, the sound stops.
Script
clear all;close all;clc; dt = 0.01; t = dt:dt:3600; Alarm1 = zeros(1,length(t)); Alarm2 = Alarm1; tStart = 900; tEnd = 2700; tWake = 3000; Index = 1; for i=t if (i >= tStart) && (i < tEnd) && (i < tWake) Alarm1(Index) = ((i-tStart)/(tEnd-tStart))*Alarm(0.01,i-tStart); elseif (i >= tEnd) && (i < tWake) Alarm2(Index) = Alarm(0.02,i-tEnd); end Index = Index + 1; end plot(t,Alarm1,t,Alarm2); title('Sound output'); xlabel('Time (s)'); ylabel('Amplitude'); axis([0 3600 -1 1]);