Project: ArduinoPhotosensitiveAlarmI

Due to I can hardly hear my alarm every morning and I do want to wake up early than before, maybe wake up by dawn. I’d like to make a Photosensitive Alarm. And this alarm should ring when the light shows.

And also, normal alarm rings very boring so I will let it play some music I like to make me delightful in the morning. The song’s rhythm and melody are make by Arduino code.

First, design the circuit to make sure the audio ring can be controlled when the photo resistor’s value changes. The graph shows below:circuit1

Then, connecting the circuit.

5.pic

Next, wrote the song melody and rhythm with Arduino. The music score I choose is below (my favorite childhood song, and the reference of music tone and note is in the bottom of the page).

huluwa.png

#define NOTE_D0 -1
#define NOTE_D1 294
#define NOTE_D2 330
#define NOTE_D3 350
#define NOTE_D4 393
#define NOTE_D5 441
#define NOTE_D6 495
#define NOTE_D7 556

#define NOTE_DL1 147
#define NOTE_DL2 165
#define NOTE_DL3 175
#define NOTE_DL4 196
#define NOTE_DL5 221
#define NOTE_DL6 248
#define NOTE_DL7 278

#define NOTE_DH1 589
#define NOTE_DH2 661
#define NOTE_DH3 700
#define NOTE_DH4 786
#define NOTE_DH5 882
#define NOTE_DH6 990
#define NOTE_DH7 112
//define the music note with frequency in D tone
#define WHOLE 1
#define HALF 0.5
#define QUARTER 0.25
#define EIGHTH 0.25
#define SIXTEENTH 0.625
//define the beats
int tune[] =
{
NOTE_DH1,NOTE_D6,NOTE_D5,NOTE_D6,NOTE_D0,
NOTE_DH1,NOTE_D6,NOTE_D5,NOTE_DH1,NOTE_D6,NOTE_D0,NOTE_D6,
NOTE_D6,NOTE_D6,NOTE_D5,NOTE_D6,NOTE_D0,NOTE_D6,
NOTE_DH1,NOTE_D6,NOTE_D5,NOTE_DH1,NOTE_D6,NOTE_D0,
NOTE_D1,NOTE_D1,NOTE_D3,
NOTE_D1,NOTE_D1,NOTE_D3,NOTE_D0,
NOTE_D6,NOTE_D6,NOTE_D6,NOTE_D5,NOTE_D6,
NOTE_D5,NOTE_D1,NOTE_D3,NOTE_D0,
NOTE_DH1,NOTE_D6,NOTE_D6,NOTE_D5,NOTE_D6,
NOTE_D5,NOTE_D1,NOTE_D2,NOTE_D0,
NOTE_D7,NOTE_D7,NOTE_D5,NOTE_D3,
NOTE_D5,
NOTE_DH1,NOTE_D0,NOTE_D6,NOTE_D6,NOTE_D5,NOTE_D5,NOTE_D6,NOTE_D6,
NOTE_D0,NOTE_D5,NOTE_D1,NOTE_D3,NOTE_D0,
NOTE_DH1,NOTE_D0,NOTE_D6,NOTE_D6,NOTE_D5,NOTE_D5,NOTE_D6,NOTE_D6,
NOTE_D0,NOTE_D5,NOTE_D1,NOTE_D2,NOTE_D0,
NOTE_D3,NOTE_D3,NOTE_D1,NOTE_DL6,
NOTE_D1,
NOTE_D3,NOTE_D5,NOTE_D6,NOTE_D6,
NOTE_D3,NOTE_D5,NOTE_D6,NOTE_D6,
NOTE_DH1,NOTE_D0,NOTE_D7,NOTE_D5,
NOTE_D6,
};
// the song’s whole melody
float duration[]=
{
1,1,0.5,0.5,1,
0.5,0.5,0.5,0.5,1,0.5,0.5,
0.5,1,0.5,1,0.5,0.5,
0.5,0.5,0.5,0.5,1,1,
1,1,1+1,
0.5,1,1+0.5,1,
1,1,0.5,0.5,1,
0.5,1,1+0.5,1,
0.5,0.5,0.5,0.5,1+1,
0.5,1,1+0.5,1,
1+1,0.5,0.5,1,
1+1+1+1,
0.5,0.5,0.5+0.25,0.25,0.5+0.25,0.25,0.5+0.25,0.25,
0.5,1,0.5,1,1,
0.5,0.5,0.5+0.25,0.25,0.5+0.25,0.25,0.5+0.25,0.25,
0.5,1,0.5,1,1,
1+1,0.5,0.5,1,
1+1+1+1,
0.5,1,0.5,1+1,
0.5,1,0.5,1+1,
1+1,0.5,0.5,1,
1+1+1+1
};

Add the following code in, testing what value is best for the previous situation and change the photo resistor’s value number.
int length;
int tonePin=12;
int sensorValue;
void setup(){
    // put your setup code here, to run once:
Serial.begin(9600);
pinMode(tonePin,OUTPUT);
length = sizeof(tune)/sizeof(tune[0]);
}

void loop(){
// put your main code here, to run repeatedly:
for(int x=0;x<length;x++){
if(sensorValue<600){

                 break;
}
tone(tonePin,tune[x]);
delay(400*duration[x]);
noTone(tonePin);
}
}
melody
Publicités
Publié dans Uncategorized
Web2PDF