For projects involving audio output, you’ll often need an amplifier, adding cost to the project. As this build by Łukasz Podkalicki shows, however, you can create a simple class D amplifier based on an ATtiny13 microcontroller to generate PWM frequencies for sound reproduction.
The component list in this device is very simple, consisting of the ATtiny13, two resistors, and two capacitors, along with the speaker that it powers. Audio is fed into an input pin across one of the capacitors, which is converted to a digital signal and fed to the speaker. Podkalicki notes that the Attiny13’s 9.6 MHz clock only allows for a 37.5kHZ PWM rate, however, for his experimental sampling rate of around 10KHz, it performs quite well.
Podkalicki shares that it took him a few hours to figure it out, but since he’s done most of the hard work for this breadboard amp, it could be a fast and inexpensive solution for your next project.
Code for the project can be found on GitHub, while further explanation and a demo of how it works is seen/heard in the video above. Obviously how good it sounds to you will depend on your speakers and how it was recorded, but it’s certainly decent enough for many audio hacking applications.