Concept
For this assignment, we decided to remake a piano, but add some adjustments to its stage presence. We all know that there are a lot of stage lights mechanisms when a pianist performs, but what happens when there is no light or lights are directed at people? Our piano changes its tunes and how it sounds. The main technology behind this piano is the usage of the photoresistor which sends different sensor values and with the changing frequency of the sensor, the note fluctuates.
Materials used-
- LED
- 3 Switches (digital)
- Photoresistor (analog)
- Wires
- Resistors – 10 K ohm and 330 ohm
Here is the spotlight session in progress,
The code that we used starts off with the assignment of a variable to each component of the circuit. The piezo buzzer is connected to three switches that produce a different tone each time a different switch is pressed. After arranging the switches in a series, we added an LED that lights up every time a piano note is played. We mainly added the tone() function to generate a square wave of a certain frequency on three pins that were attached to their respective switches. Lastly, to play with the concept of a stage spotlight, we added a photoresistor and mapped the values within it so that the frequency of the note that is playing fluctuates when a flashlight is shone or the stage is put in the dark.
int piezoPin = 8; int LED = 13; int button1 = 5; //Set up the input pins connected to the buttons. int button2 = 4; int button3 = 3; int frequency = 0; int sensorPin = 0; int sensorValue = 0; const int delayTime = 500; //Set up a constant for the variable of delay time in the tone() function. void setup() { pinMode(button1, INPUT_PULLUP); pinMode(button2, INPUT_PULLUP); pinMode(button3, INPUT_PULLUP); pinMode(LED, OUTPUT); } void loop() { sensorValue = analogRead(sensorPin); //Map the different values of the potentiometer to a set of frequencies for each of the three buttons. if (digitalRead(button1) == LOW) { frequency = map(sensorValue, 0, 1023, 400, 499); digitalWrite(LED,HIGH); } else if (digitalRead(button2) == LOW) { frequency = map(sensorValue, 0, 1023, 300, 599); digitalWrite(LED,HIGH); } else if (digitalRead(button3) == LOW) { frequency = map(sensorValue, 0, 1023, 500, 599); digitalWrite(LED,HIGH); } else { frequency = 0; digitalWrite(LED,LOW); } tone(piezoPin, frequency, delayTime); //Set up the tone() functions with variables. }
Reflections and Future Improvements
Overall, we are happy with the playfulness of the output but would like to experiment with other notes. We had some difficulties with creating more audible differences when the light settings changed. Perhaps, it was due to the little difference photoresistor could detect, or we could play around changing the value, but it didn’t really work out as it was making the noise bad as the mapped values were being changed. Moreover, the LED just switches on and off when the switch is pressed perhaps its brightness could also be changed when a new note is played.