Project description:
This project involves using LEDs, buttons, a potentiometer, and a buzzer to create a fun and interactive experience. Below is a summary of how it works and what was learned.
Key Components:
- Breadboard and Arduino UNO: These are the main platforms where the components are set up.
- LEDs: Light up when a button is pressed to show visual feedback.
- Buttons: Each one is linked to a specific LED. Pressing a button lights up the LED and makes a sound.
- Potentiometer: Adjusts the sound’s pitch from the buzzer.
- Buzzer: Produces sounds that change tone based on button presses and the potentiometer setting.
- Resistors: Uses both 330-ohm and 10k ohm resistors to control the current.
Instrument:
https://youtube.com/shorts/6Bm-7NDI3RM?si=Vu55mtSy6QuivNm8
Code:
const int redLED = 6; const int greenLED = 5; const int yellowLED = 7; const int redButton = 12; const int greenButton = 11; const int yellowButton = 13; const int potPin = A2; const int buzzerPin = 3; void setup() { pinMode(redLED, OUTPUT); pinMode(greenLED, OUTPUT); pinMode(yellowLED, OUTPUT); pinMode(redButton, INPUT_PULLUP); pinMode(greenButton, INPUT_PULLUP); pinMode(yellowButton, INPUT_PULLUP); // Initialize Serial for debugging Serial.begin(9600); } void loop() { // Read potentiometer value int potValue = analogRead(potPin); // Map potentiometer value to a frequency range (e.g., 100 Hz to 2000 Hz) int frequency = map(potValue, 0, 1023, 100, 2000); // Check each button and activate the corresponding LED and buzzer if (digitalRead(redButton) == LOW) { digitalWrite(redLED, HIGH); tone(buzzerPin, frequency); // Play buzzer at mapped frequency delay(100); // delay } else { digitalWrite(redLED, LOW); } if (digitalRead(greenButton) == LOW) { digitalWrite(greenLED, HIGH); tone(buzzerPin, frequency + 100); // Slightly higher pitch for green button delay(100); // Debounce delay } else { digitalWrite(greenLED, LOW); } if (digitalRead(yellowButton) == LOW) { digitalWrite(yellowLED, HIGH); tone(buzzerPin, frequency + 200); // Even higher pitch for yellow button delay(100); // Debounce delay } else { digitalWrite(yellowLED, LOW); } delay(10); }
Reflections:
Watching the LEDs light up and hearing the buzzer change pitch was very rewarding. It’s fascinating to see how basic parts and some coding can create a captivating interactive experience. Adjusting the buzzer’s pitch with the potentiometer was particularly enjoyable, as it required fine-tuning to get pleasant sounds and smooth transitions between pitches.
Challenges:
- Debouncing: Making sure the buttons only register a single press at a time was challenging. The project uses simple delays now, but could benefit from more advanced debouncing methods.
- Sound Complexity: Currently, the buzzer only creates basic tones. Using sound libraries like Mozzi might allow for more complex sounds.
Improvements:
- Light Patterns: Could add flashing or fading lights for more visual appeal.
- Multiple Tones/Melodies: Using libraries to generate more detailed sounds.
- Interactive Games: Creating games based on pressing buttons and keeping time.
- LCD Display: Adding a screen to display instructions or scores.