Introduction: Photocell Piano

This tutorial is a how to construct a 6 note “Photocell Piano”. When the user runs their hand over the top of the keys (photoresistors) they turn on audio notes, which can be tuned with potentiometers. This project utilizes Arduino to turn the notes on and off. The tutorial includes a parts list, schematics and the code required to operate this musical device.

This device requires two separate circuits and an Ardunio code.

1) A circuit that contains all the notes.
2) A circuit that mixes all the notes.
3) The code

Step 1: Note Maker

Part One

Note Maker

PARTS

100n Capacitor- (x6)
10u Capacitor- (x6)
100nf Capacitor- (x6)
1k Resistor- (x6)
220k ohm Resistor- (x6)
Photoresistor- (x6)
10k Variable Resistor- (x6)
Arduino Uno- (x1)
10” by 4”Prototype Board- (X1)
555 Chip- (X6)
Mono Audio Jack- (x6)
Switch- (x1)
9V Battery- (x1)
Prototype Shield for Arduino- (x1)
Arduino Prototype Shield- (x1)
1/8” Audio jumper cables-(x6)
Small Speaker with 1/8” cable- (x1)

Note: The 100nf capacitor is added so that the variable resistors only control their individual note. If they were not present all the variable resistors would control all the notes making the circuit only have one tone. 

Solider all parts to the 10” by 4” prototype board. Please note that the photo resistors control the notes so place them in a location that is convenient to play. Use stranded wire and an Arduino prototype shield to interface Arduino to the 555 circuits.

Step 2: Audio Mixer

Part Two

Audio Mixer


6” by 4”Prototype Board- (X1)
741 Chip- (x1)
Mono Audio Jack- (x7)
10k Resistor- (x8)
Switch- (x1)
10k Variable Resistor- (x1)
9V Battery- (x2)

Note: The notes will sound if the audio mixer if off. This is because the sound travels through the 10k resistor into pin 6. The reason for the mixer make the sound less distorted.  

Note: This circuit requires +9v and -9v. This can be tricky so refer to the drawing above.


Step 3: The Code


Part Three

The Code


Note: This code is comprised of  6 “if else statements” that tell each individual note to sound when its corresponding photoresistor reaches a value which is below the set threshold. The code takes a reading of the ambient light for five seconds when it is first turned, which in turn, sets its own threshold. Pin D3 (first note) will sound when the instrument is ready to be played.

COPY CODE AND UPLOAD TO ARDUINO:

/*


*/

//setup for analog pins (Photo resistor)
const int photofor1 = A0;   
const int photofor2 = A1;   
const int photofor3 = A2;   
const int photofor4 = A3;   
const int photofor5 = A4;   
const int photofor6 = A5;   

//setup for digital pins (gets the sound from the 555 chip)
int sound1 = 3;
int sound2 = 5;
int sound3 = 6;
int sound4 = 9;
int sound5 = 10;
int sound6 = 11;

//setting up a for loop to auto set sensor values
int sensorPin[6] = {A0,A1,A2,A3,A4,A5}; // pin that the sensors are attached to

int sensorValue = 0;        
int sensorMin[] = {1023,1023,1023,1023,1023,1023};      
int sensorMax[] = {0,0,0,0,0,0};          

void setup() {
  pinMode(sound1, OUTPUT); 
  pinMode(sound2, OUTPUT);
  pinMode(sound3, OUTPUT);
  pinMode(sound4, OUTPUT);
  pinMode(sound5, OUTPUT);
  pinMode(sound6, OUTPUT);

  digitalWrite(sound1,LOW);
  digitalWrite(sound2,LOW);
  digitalWrite(sound3,LOW);
  digitalWrite(sound4,LOW);
  digitalWrite(sound5,LOW);
  digitalWrite(sound6,LOW);

  Serial.begin(9600);

  // Calibrate during the first five seconds
  while (millis() < 5000) {
    for(int i = 0; i <= 5; i++)
    {
      sensorValue = analogRead(sensorPin[i]);

      // record the maximum sensor value (for all)
      if (sensorValue > sensorMax[i]) {
        sensorMax[i] = sensorValue;
      }

      // record the minimum sensor value (for all)
      if (sensorValue < sensorMin[i]) {
        sensorMin[i] = sensorValue;
      }
    }
  }
  //prints all the numbers out for each photo resistor (high and low)
  Serial.print("\n\n");
  for(int i = 0; i <= 5; i++)
  {
    Serial.print(sensorMin[i]);
    Serial.print('\t');
  }   
  Serial.print('\n');

  for(int i = 0; i <= 5; i++)
  {
    Serial.print(sensorMax[i]);
    Serial.print('\t');
  }
  Serial.print("\n\n");
//Done with auto calibration

//turns a note on when it is ready to be played
  digitalWrite(sound1, HIGH); 
  delay(500);            




}

void loop() {

  int analogValue1 = analogRead(photofor1);
  delay(1);     
  int analogValue2 = analogRead(photofor2);
  delay(1);    
  int analogValue3 = analogRead(photofor3);
  delay(1);    
  int analogValue4 = analogRead(photofor4);
  delay(1);    
  int analogValue5 = analogRead(photofor5);
  delay(1);    
  int analogValue6 = analogRead(photofor6);
  delay(1);    



//note 1
  if (analogValue1 < (sensorMin[0] - 50 )) {
    digitalWrite(sound1, HIGH);
  }
  else {
    digitalWrite(sound1,LOW);
  }


//note 2
  if (analogValue2 < (sensorMin[1] - 50 )) {
    //Serial.println("note 2");
    digitalWrite(sound2, HIGH);
  }
  else {
    digitalWrite(sound2,LOW);
  }



//note 3 
    if (analogValue3 < (sensorMin[2] - 50 )) {
    digitalWrite(sound3, HIGH);
  }
  else {
    digitalWrite(sound3,LOW);
  }



//note 4
  if (analogValue4 < (sensorMin[3] - 50 )) {
    digitalWrite(sound4, HIGH);
  }
  else {
    digitalWrite(sound4,LOW);
  }




//note 5
  if (analogValue5 < (sensorMin[4] - 50 )) {

    digitalWrite(sound5, HIGH);
  }
  else {
    digitalWrite(sound5,LOW);
  }




//note 6
    if (analogValue6 < (sensorMin[5] - 50 )) {
    digitalWrite(sound6, HIGH);
  }
  else {
    digitalWrite(sound6,LOW);
  }


}

Step 4: Closing

The schematics for the 555 Tone Maker and the 741 Audio Mixer were adapted from Forrest Mims III. Thank you for taking an interest in my project feel free to contact me for any questions that may arise.

GOOD LUCK!

Asa