Week 11 Assignment – Zere

Concept

The concept of my project is to create a light-controlled musical instrument using Arduino. Instead of buttons or keys, the player controls pitch by covering or exposing a photoresistor to light, like waving your hand over it. A pushbutton switches between a low octave and a high octave, making the instrument feel expressive and playful. I wanted the interaction to feel unusual and fun, more like a theremin than a traditional instrument.

const int LDR_PIN = A0;
const int BTN_PIN = 2;
const int BUZZ_PIN = 8;

void setup() {
  pinMode(BTN_PIN, INPUT_PULLUP);
}

void loop() {
  int lightVal = analogRead(LDR_PIN);
  int btnState = digitalRead(BTN_PIN);

  int freq;
  if (btnState == LOW) {
    freq = map(lightVal, 0, 1023, 500, 2000);
  } else {
    freq = map(lightVal, 0, 1023, 100, 500);
  }

  tone(BUZZ_PIN, freq);
  delay(10);
}

I started by placing a photoresistor on the breadboard with a 10kΩ resistor forming a voltage divider, which lets the Arduino read changing light levels through A0. At first the buzzer played the same tone constantly, later I discovered through the serial monitor that A0 was reading 1023 the whole time, which meant that the resistor was not properly connected to the photoresistor. Once I fixed that, the pitch started responding to light.

What I’m proud of

The part I’m most proud of is figuring out the button wiring. This was incredibly frustrating, as I spent a long time confused about which legs of the button connect internally, which pins on the Arduino were digital versus analog, and why the signal kept reading the wrong values. I watched a YouTube tutorial to better understand how the process, it was quite challenging to be honest. https://www.youtube.com/watch?v=gj-H_agfd6U

What I can do better next time

Next time, I want to map the light values to specific musical notes rather than continuous frequencies, so it sounds more like a real scale than a smooth slide between pitches. I could also add an LED that lights up when the button is pressed for visual feedback, or use multiple photoresistors to create distinct pitch-control zones. I could also arrange the wires more neatly next time.

This is the video of me testing the sound: IMG_2491

 

Leave a Reply