A poliphonic chiptune-like music player for the Arduino Uno!
- Pokemon Red, Blue and Yellow Trainer battle music
- Super Mario Bros
- Sweet Child of Mine by Jean Henrique, using Arduitunes and an electric arc speaker. Pretty cool.
- Clone/download the project
- Load the arduitunes.ino file to your board. I personally use PlatformIO that allows me to develop in my current favorite IDE. Important: You must have already installed the Arduino IDE v1.5.8 or newer.
- Set up your circuit. See my proposed setup, but please, read the Warning section before building it.
- Load the program to your board
- Listen! Play with the tempo if you feel like it
Here I propose a quick and dirty circuit that does the job of safely mixing the outputs. I added some more convenience components such as a volume knob.
This sketch's parts are:
- An Arduino UNO board
- Two potentiometers (tempo, volume)
- Two LED diodes (tempo, sound indicator)
- 7 300Ω resistors. 5 for the passive mixer, 2 for the LEDs.
- 1 1kΩ resistor
- 1 10kΩ resistor
- 1 audio mono jack
Presets are described as a set of constant strings, each one representing an individual voice. If you succeeded on loading and playing the program (sketch) you should've heard the Pokemon red/blue/yellow battle theme song.
The song data is contained on the code inside the following commented tags:
/**** PRESET MELODIES ****/
/** Preset 1 **/
const char voice1_melody[] PROGMEM = {" ... "};
...
const char voiceN_melody[] PROGMEM = {" ... "};
...
/**** END PRESET MELODIES ****/
To change the song, just comment out the current song voices and uncomment another set.
Please that only one song at a time can be active.
Included tunes are:
- Super Mario Brothers overworld theme
- Pokemon red/blue/yellow battle theme
- Tiny bit of Attack on titan's first opening song
- Tiny bit of Fullmetal Alchemist's first opening song
Songs are declared as RTTTL-like strings for each voice. I created an ugly but functional webapp which is a somehow easy way to create tunes. I actually used it to create most of the preset tunes.
When done, click Generate, copy and paste the resulting text to the sketch, and load it to your board. Remember to define only one tune at a time when loading the code.
The web app's source code is available in this repo too, if you feel like you want to make it better.
Arduino boards output voltages that are commonly logic 3.3V or 5V. This is TOO MUCH VOLTAGE for typical audio applications, so your output circuit should handle this to avoid blowing up your speakers, headphones, eardrums, windows... You're just a google search-away of knowing how to avoid this. With my proposed circuit though, you should be safe.
In the proposed circuit, the more voices are singing at the same time, the higher the total peak to peak voltage at the mixed output. If you need it, evaluate implementing a compressor circuit before the actual audio output.
I cannot and won't be responsible for any damage you cause to your arduino, audio devices, yourself or someone else. If you don't know what you're doing I strongly advice you do your research first.
- True polyphonic harmony
- Mostly accurate note frequencies (equal temperament)
- Note range from G2 to D#8
- Repetitions support ||: :||
- Adjustable tempo
- Only a few simple passive components required (plus the arduino)
- Support for triplets (and more complex beats)
- More instruments (other than square waves)
- MIDI support
- OOP paradigm
- Decent webapp development
- Online tune preview
- PCB design to plug and play
- ADSR envelope support
Everything that oscillates at a relatively constant rate is potentially a musical note: A metal rod when you hit it, a tight string when you strum it, a hollow tube when you blow on it, and even a digital output pin when you toggle it.
As you may know, every known musical note has a defined frequency in the very common A 440 equal temperament tuning standard. If you connect a digital pin to something that can produce sound when you toggle it from 0 to 1 in a controlled fashion, then you can reproduce precise notes. The real challenge though, comes when you want to produce various notes at the same time, on a device that is physically constructed to do just one thing at a time: to execute one instruction at a time.
The approach followed in this project is inspired on this article from Jeremy Blum's blog. If you get this, then you already understand the complicated part of Arduitunes.
It was my first Arduino project. When I first saw an arduino blink an LED, I immediately fell in love with the platform, and I, as a music lover, could not get out of my head the idea of making this thing produce some sound.
So, I ended up developing this, which ended up involving some research on the actual Atmega chip guts, that was both scary and thrilling. The sincere joy this process brought to my soul was a kind surprise for me, I didn't know I liked this kind of stuff so much.
Arduitunes is what taught me the level of satisfaction that messing around with electronics could provide, which was a previously unknown world to me.
Merge requests, comments, suggestions and feedback in general will always be appreciated!