“Imitate musical instruments and make music with an Arduino and only few external components!
Most of you already know the tone() function from the Arduino Library. But this simply spits out a square wave and so it sounds rather boring.
But with a simple trick we can generate any waveform with an Arduino and a small circuitry, and with this even imitate musical instruments!
In this project, I use the Timer/Counter 2 of the ATmega328 MCU to generate a PWM signal. After low-pass filtering with some resistors and capacitors, we get either a sine, sawtooth or rectangle wave with programmable frequency and duty cycle. By modulating with an ADSR envelope, it is even possible to imitate any musical instrument and play a small tune! Watch the video for a detailed explanation and see how it works and how to use.
Although I use an Arduino Nano in the video, the project will also run with an Arduino UNO, because both UNO and Nano have the same pinout and MCU.”