Passive Buzzer Music Maker (Make Notes & Add Songs)
by JOSHIBOY61 in Circuits > Arduino
1750 Views, 11 Favorites, 0 Comments
Passive Buzzer Music Maker (Make Notes & Add Songs)
Hello everyone!
I want to show you how to make a passive buzzer sound system with LED's. This system would be able to make notes and you can also find songs you love to play on the passive buzzer sound system.
Supplies
- 21 male-to-male jumper cables
- 4 red LED's
- 4 green LEDs
- 2 yellow LEDs
- 1 passive buzzer
- 1 IR receiver and Remote
- 5 x 220 ohm current limiting resistors
- Arduino UNO R3
- Programming cable
- 1 big breadboard
Connect LEDs and Buzzer
- Connect the LEDs and buzzer in the same row on your breadboard
- Then plug the 220-ohm current limiting resistors to the left side of LEDs to the GND of the breadboard
Wire Up Both LEDs
- I connected both LEDs from both sides together thus allowing the 5 resistors to work for the 10 LEDs
- For clarification, I used jumper cables with the same colors as the LED.
Connecting the Arduino
- Use 5 jumper cables to connect the LEDs anodes to pins 2,3,4,5,6
- Then connect the buzzer GND pin to the GND of the breadboard
- Connect the positive pin of the buzzer to pin 8 of the Arduino
- Now plug the IR receiver into the breadboard and connect the signal pin to pin 9, its VCC pin to the 5V pin and its GND pin to the GND of the breadboard
Programming the System
Libraries:
The code uses two external libraries: IRremote for handling infrared remote signals and toneAC for generating tones. These libraries need to be installed in the Arduino IDE.
Constants and Variables:
The code defines some constants and variables:
- IR_RECEIVER_PIN: The pin where the IR receiver is connected.
- LED_PINS: An array of pins connected to LEDs.
- BUZZER_PIN: The pin is connected to a buzzer.
- IRrecv irrecv(IR_RECEIVER_PIN): An object to receive and decode IR signals.
- decode_results results: A variable to store the decoded IR signal.
- tones: An array of frequencies corresponding to musical tones.
- currentToneIndex: Keeps track of the currently played tone.
- lastCommandTime: Records the time of the last IR command to avoid rapid repeated commands.
- debounceDelay: A delay to prevent rapid triggering due to noise or repeated signals.
Setup Function:
The setup function initializes serial communication, sets up the IR receiver, configures LED pins as outputs, and performs an initial LED flash for visual feedback.
Loop Function:
The loop function continuously checks for incoming IR signals. If a signal is received and a sufficient debounce time has passed, it prints the hexadecimal value of the signal, plays a corresponding musical tone, and updates the last command time. Additionally, it triggers functions to flash LEDs in a sequence and in reverse.
Play Tone Function:
The playTone function maps specific IR remote hexadecimal values to corresponding musical tones. When a valid value is found, it plays the associated tone through the buzzer, briefly pauses, and then stops the tone before moving to the next one. If you want to use songs instead they can be retrieved from an Arduino-related site; some good options are Happy Birthday and the Mario Bros theme song.
Flash LED Functions:
There are three functions for flashing LEDs:
- flashLEDs: Flashes LEDs in a pattern to indicate the beginning of the code.
- flashLEDsSequence: Flashes LEDs in a sequence.
- flashLEDsReverse: Flashes LEDs in the reverse order.
Downloads
Play Notes and Add Your Favourite Songs!
Now master the notes and feel free to experiment with sounds and pitches in the code. You can optionally add songs of your choice to the code.
Thanks for following; please like and I welcome any questions : )