Output

From Control Systems Technology Group
Revision as of 00:08, 21 March 2016 by S141268 (talk | contribs)
Jump to navigation Jump to search

Back to main page: PRE2015_3_Groep4

To the input: Input

To the code: Code

Light Brightness

Heating

Play Sound

The SparkFun MP3 Player Shield

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, so we chose a cheaper option. More info about this product can be found at https://www.sparkfun.com/products/12660.

Buzzer module for Arduino

To create sound, 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. The script is written below and the result can be seen in the pictures to the right. The blue graph represents Alarm1 and the red one Alarm2.

Script result when tWake > tEnd
Script result when tStart < tWake < tEnd

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]);
legend('Alarm1','Alarm2');

Feedback Statistics

Graphic Simulation