OUTPUT DEVICES
Controlling sound and music with a microcontroller and passive buzzer
Group Assignment: Power Measurement
For our group assignment, we measured the power consumption of various output devices. You can see the complete group work on the group assignment page.

Measurement Setup
Using a multimeter to measure current draw of different output devices including LEDs, buzzers, and motors.
- Measured idle current consumption
- Recorded peak current during operation
- Calculated power consumption at different voltages

Power Comparison
Comparing power requirements of different output devices helps in selecting appropriate power supplies and designing efficient circuits.
- LEDs: ~20mA each
- Passive buzzer: ~30mA
- Small DC motor: ~100-200mA
- Servo motor: ~50-300mA depending on load
Through this group assignment, I learned how to properly measure power consumption of output devices and the importance of selecting components that match the power capabilities of my microcontroller board. Understanding current requirements helps prevent damage to components and ensures reliable operation.
I also gained appreciation for power efficiency in embedded designs, especially for battery-powered applications where every milliamp matters.
Individual Assignment: Musical Buzzer
For this week's individual assignment, I added a passive buzzer as an output device to a microcontroller board I designed and programmed it to play music.
This week in Fabacademy, I established communication between an Attiny45 (with a PCB designed and made during week 11) and a Xiao RP2040 (whose board was manufactured in the electronics production week). Through UART, I transferred data from an ultrasonic sensor processed by the Attiny45 to the Xiao RP2040, allowing the received values to display on the Arduino serial monitor.
Communication Protocols
Networking protocols like I2C (Inter-Integrated Circuit) and UART (Universal Asynchronous Receiver-Transmitter) are key to facilitating communication between microcontrollers and peripheral devices in embedded systems.
Protocol | Description | Advantages | Use Cases |
---|---|---|---|
I2C | Two-wire interface (SDA, SCL) supporting multiple devices | Simple wiring, multi-device support, built-in addressing | Sensor networks, EEPROMs, small displays |
UART | Asynchronous serial communication (TX, RX) | Simple point-to-point, flexible baud rates, long-distance | GPS modules, Bluetooth, console output |
SPI | High-speed synchronous serial (SCK, MOSI, MISO, CS) | Very fast, full-duplex, simple hardware | Displays, flash memory, ADCs |
CAN | Robust differential serial bus | Error handling, long-distance, multi-node | Automotive, industrial systems |
For my project, I chose UART because:
- Simple point-to-point communication was sufficient
- Both microcontrollers supported it natively
- Easy to debug with serial monitor
- Flexible baud rate selection
Music Programming with Arduino
To create music with the passive buzzer, I needed to understand musical notes, their frequencies, and timing.

Musical Notes
The natural scale and its semitones, with corresponding frequencies for different octaves.
I found helpful examples at dragaosemchama.com which helped me understand how to program music with Arduino.

Note Frequencies
The frequencies of musical notes in different octaves. Higher octaves have higher frequencies.
This table was essential for programming the correct pitches for my buzzer.
Code Implementation
The code uses several key concepts:
- SPEED_FACTOR: Controls playback speed (0.5 = 50% faster)
- playNote: Function that plays a note or silence for a specified duration
- tone(): Generates square wave at specified frequency on buzzer pin
- delay(): Pauses execution for note duration adjusted by SPEED_FACTOR
- Arrays: melody[] stores note frequencies, rhythm[] stores durations
Embedded Code
Final Result: Rick Astley - Never Gonna Give You Up
The passive buzzer playing my programmed song
During this project, I faced several challenges:
- Note Timing: Initially, the rhythm was off. I fixed this by carefully adjusting the duration constants and using the SPEED_FACTOR.
- Sound Quality: The buzzer produced harsh tones. I improved this by adding small delays between notes and adjusting volume.
- Memory Limits: The Attiny45 has limited memory. I optimized by using PROGMEM for storing the melody arrays.
- UART Communication: Had synchronization issues. Fixed by implementing proper handshaking and error checking.
Files and Resources
File Type | Description | Download |
---|---|---|
Arduino Code | Complete source code for the musical buzzer | Download |
Board Design | CAD files for the microcontroller board | Download |
Enclosure | Design for buzzer enclosure | Download |
Useful Resources
Final Reflections
- How to generate sound with a passive buzzer
- Musical note frequencies and timing
- UART communication between microcontrollers
- Power considerations for output devices
- Optimizing code for limited memory
- Getting the rhythm timing perfect
- Managing limited memory on Attiny45
- Debugging UART communication issues
- Making the buzzer sound musical
- Power management for battery operation
Integrated networks and communications are fundamental components of the vast ecosystem of interconnected devices that shape the modern technological landscape. These networks facilitate seamless interaction among various embedded systems, ranging from simple microcontrollers to complex industrial machines.
The expansion of integrated communications has also led to the incorporation of more sophisticated technologies, such as wireless networking capabilities and Internet connectivity. This integration enhances the functionality of embedded systems, allowing them not only to perform localized tasks but also to participate in larger networks for data sharing and remote management.
Looking ahead, the future of integrated networks and communications appears poised for significant growth, driven by advances in hardware miniaturization and software development. As these technologies evolve, they will enable more complex and reliable systems capable of autonomous operation and real-time data processing.