Musical Instrument – Week #10

Concept:

Our idea for the musical instrument was drawn from the classic guitar mechanism. By integrating Light-Dependent Resistors (LDRs) as the sensory input and buzzers as the output, we’ve created a playful experience. Each LDR is strategically positioned to represent a distinct musical note, and when covered, it triggers a corresponding buzzer, simulating the act of plucking strings on a guitar. There’s also a digital switch, which, when pressed, records the notes being played. When the switch is released, the notes are played back.

Items used:
  • Arduino Uno
  • 6 Light-Dependent Resistors (LDRs)
  • 6 Buzzers (Speakers)
  • Resistors (for LDRs )
  • Jumper Wires (for connecting components)
  • 2 Breadboards
  • 1 Momentary Switch
Technical Implementation:

In our musical instrument, each Light-Dependent Resistor (LDR) is assigned to represent a specific musical note, creating a musical sequence reminiscent of a guitar tuning. The choice of notes – E, A, D, G, B, E – corresponds to the standard tuning of the six strings on a guitar. When an LDR is covered, it changes the resistance and triggers the Arduino to interpret this change as a command to play the designated note through the corresponding buzzer.

The Arduino continuously reads the analog values from the LDRs and, upon detecting a significant change, maps the input to trigger the corresponding buzzer connected to a digital output pin. The code is designed to be modular, allowing for easy adjustments to resistor values or the addition of more sensors and buzzers for expanded musical possibilities. 

When the digital switch is pressed, the notes which are played are recorded in an integer array. As soon as the switch is released, the notes in the array are played back using the regular tone() function. 

// check recording state
 if (digitalRead(SWITCH_PIN) == HIGH) {
   Serial.println("Recording");
   recordMode = true;


 } else if (digitalRead(SWITCH_PIN) == LOW) {
   if (noteCount > 0) {
     Serial.println("Playback");
     recordMode = false;
     for (int i = 0; i < noteCount; i++) {
       tone(playback_PIN, melody[i]);
       delay(200);
     }
     noTone(playback_PIN);
     noteCount = 0;
   }
 }
Future Improvements:

The array can only hold a maximum of 50 notes, and a future improvement could be adding some warning (LED flashing?) to indicate that the array capacity has been reached. There’s also no error handling at this stage, so there could be some unexpected errors if more than 50 notes are recorded.

Leave a Reply