Lab5 - Draw the Music

Submitted by katehsiao on Mon, 03/04/2013 - 11:10

 

Description

By using the combination of 3 photocell sensors and 1 Piezo speaker, the user can draw the notes on a paper, putting the paper on the clip trays, and pull to play the notes.
 

Components Used

1- Arduino Uno
1- Breadboard
3- Photocell sensors
1- Piezo speaker
3- 10kΩ Resistor
1- Pen & paper
 

Code

/*
 * Draw the Music
 * (now only support Do, Fa, So) 
 *
 * Created 3 Mar 2013
 * Kate Hsiao
 */
 
int aPin = 0;
int bPin = 1;
int cPin = 2;
int speakerPin = 7;
 
int aVal = 0;
int bVal = 0;
int cVal = 0;
int freq = 0;
 
void setup() {
  pinMode(speakerPin, OUTPUT); 
  Serial.begin(9600);
}
 
void loop() {
  digitalWrite(speakerPin, LOW);
  
  aVal = analogRead(aPin);
  bVal = analogRead(bPin);
  cVal = analogRead(cPin);
  /* Need to adjust the threshold value based on the lighting condition
  Serial.print(aVal); 
  Serial.print(","); 
  Serial.print(bVal); 
  Serial.print(","); 
  Serial.println(cVal); 
  */
  if (aVal<300) {
    freq = 1136;
    for( int i=0; i<150; i++ ) {
      digitalWrite(speakerPin, HIGH);
      delayMicroseconds(freq);
      digitalWrite(speakerPin, LOW);
      delayMicroseconds(freq);
    }
  } 
  if (bVal<640) {
    freq = 1275;
    for( int i=0; i<150; i++ ) {
      digitalWrite(speakerPin, HIGH);
      delayMicroseconds(freq);
      digitalWrite(speakerPin, LOW);
      delayMicroseconds(freq);
    }
  }
  if (cVal<690) {
    freq = 1915;
    for( int i=0; i<150; i++ ) {
      digitalWrite(speakerPin, HIGH);
      delayMicroseconds(freq);
      digitalWrite(speakerPin, LOW);
      delayMicroseconds(freq);
    }
  }
 
}
 
 

Video

 
image1.png
image2.png
IMG_3844.JPG
5
Your rating: None Average: 5 (3 votes)
Drupal theme by Kiwi Themes.