Passive Buzzer Music Maker (Make Notes & Add Songs)

by JOSHIBOY61 in Circuits > Arduino

1641 Views, 10 Favorites, 0 Comments

Passive Buzzer Music Maker (Make Notes & Add Songs)

IMG_20231116_130036_526[1].jpg
ezgif.com-gif-maker.gif

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

IMG_20231112_220826_113.jpg
  1. 21 male-to-male jumper cables
  2. 4 red LED's
  3. 4 green LEDs
  4. 2 yellow LEDs
  5. 1 passive buzzer
  6. 1 IR receiver and Remote
  7. 5 x 220 ohm current limiting resistors
  8. Arduino UNO R3
  9. Programming cable
  10. 1 big breadboard

Connect LEDs and Buzzer

IMG_20231113_111647_105.jpg
IMG_20231113_111736_297.jpg
IMG_20231113_170555_144.jpg
  1. Connect the LEDs and buzzer in the same row on your breadboard
  2. Then plug the 220-ohm current limiting resistors to the left side of LEDs to the GND of the breadboard

Wire Up Both LEDs

IMG_20231113_171058_086.jpg
IMG_20231113_171124_379.jpg
IMG_20231113_172810_597.jpg
  1. I connected both LEDs from both sides together thus allowing the 5 resistors to work for the 10 LEDs
  2. For clarification, I used jumper cables with the same colors as the LED.

Connecting the Arduino

IMG_20231113_172105_346.jpg
IMG_20231113_173307_033.jpg
IMG_20231113_174257_152.jpg
IMG_20231113_174439_471.jpg
IMG_20231113_174618_139.jpg
IMG_20231113_174635_644.jpg
IMG_20231113_175323_921.jpg
IMG_20231113_175241_462.jpg
IMG_20231113_175417_021.jpg
IMG_20231113_175541_396.jpg
  1. Use 5 jumper cables to connect the LEDs anodes to pins 2,3,4,5,6
  2. Then connect the buzzer GND pin to the GND of the breadboard
  3. Connect the positive pin of the buzzer to pin 8 of the Arduino
  4. 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

IMG_20231113_180210_795.jpg
IMG_20231113_180227_245.jpg
Screenshot (22).png
Screenshot (7).png
Screenshot (23).png
Screenshot (27).png
IMG_20231113_181347_769.jpg
IMG_20231113_181343_097.jpg

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.

Play Notes and Add Your Favourite Songs!

GridArt_20231116_131147620[1].jpg

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 : )