Soothe ragged nerves with this Arduino-based synthesized sound system.
It’s 3 a.m., and you can’t sleep. You toss and turn as the neighbor’s cat serenades a mouse. The drip in your bathroom faucet has become a steady drumbeat louder than a bazooka. Punch-drunk from exhaustion, you arrive at work only to have your ears assaulted by a deafening crescendo of office chatter.
Howling cats, leaky faucets, and workmates with voices stuck on 11 are inescapable facts of life. But you just might cope, thanks to the Smooth Moods Machine, a compact and self-contained music generator built around an Arduino. Programming in the Arduino produces nine types of relaxing sound and music effects, including wind chimes, surf, and a floating cascade of musical chords that seem to carry you into the clouds.
I’ll show you how to build your own Smooth Moods Machine and easily change the music program by pressing a button on a TV remote control. You can listen with headphones, or connect a pair of amplified speakers to fill the room with calming sound.
The basic Smooth Moods Machine is an Arduino Uno, MIDI Musical Instrument Shield from SparkFun, infrared remote control module, and a couple of wires. Construction takes about 15 minutes, and most of that is in soldering a set of 4 headers to the MIDI shield. An enhanced version uses a homemade interface board that allows you to connect the MIDI shield to most any external sound amplifier.
Let’s begin with a short description of what Smooth Moods is, and how it works. At its heart is a tiny MIDI synthesizer, in the form of a surface-mount IC. This chip is conveniently soldered to a shield, making it easy to connect the synthesizer to the Arduino. The Arduino serves as a MIDI controller, the part that literally controls the synthesizer, telling it what to do
You may already be familiar with the concept of MIDI, but here are the essentials: MIDI stands for Musical Instrument Digital Interface, a standard method of producing electronic music. Rather than recording actual sounds, MIDI songs are stored as data, akin to the paper rolls of a player piano. When reproducing music, a MIDI synthesizer mimics different instruments — a grand piano here, an electric guitar there.
Your PC or Mac has a MIDI synthesizer built into its operating system. Click on a .mid file, and the song plays through your computer’s sound circuits.
Smooth Moods works about the same way, except it uses just an Arduino Uno and the synthesizer shield. And instead of playing back a song contained in a file, Smooth Moods generates its own MIDI data on the fly. Instruments and notes are combined at random to give an ethereal quality to the music. Make that music* — with an asterisk. Smooth Moods doesn’t play tunes, though it does produce random sequences of chimes, chords, and other sounds that can be considered musical.
The Smooth Moods Machine creates over a half-dozen music-like sound effects. You select the music style using a universal infrared remote control. See the table “Smooth Moods Music Modes” for a full list of the pre-programmed music and sounds.
To change music programs just press a button on the remote control. Press button 0 (zero) to mute and unmute the sound.
All programs are automatically turned off after a 30-minute period. To play again just press a button on the remote. (You can modify the Smooth Moods sketch if you want to extend or shorten the auto-shutoff delay.)
You don’t have to understand the technical aspects of MIDI to make and use the Smooth Moods Machine, so feel free to skip this part if you’d like. Otherwise, here it is in a nutshell:
MIDI data is composed of messages, which are nothing more than a sequence of 2 or 3 bytes sent over an asynchronous serial interface. Messages specify such things as the instrument to play, the note (or notes), and their volume.
As with most MIDI synthesizers, the SparkFun MIDI Musical Instrument Shield supports the General MIDI 1 (GM1) set of melodic instruments. In documentation on MIDI, the instruments are numbered 1 to 128; when programming MIDI it’s more common to refer to instruments starting at 0. Instrument 0 in the GM1 set is an acoustic grand piano; instrument 1 is a bright acoustic piano, 2 is an electric grand piano, and so on. A second set, or bank, provides various non-melodic percussion instruments.
MIDI supports up to 16 instrument channels; you can program a different instrument on each channel. See the diagram for the basic concept. You can vary the volume for each channel, plus the volume of each separate note you play through a channel. The multi-channel feature allows you to “layer” sounds, one on top of the other. The technique is used in Smooth Moods, for example, to create unique chime effects, where multiple tubular bells strike at different volume levels. This helps the chimes sound more realistic.
MIDI makes it fairly easy to play notes. Each note is simply a number, and corresponds to the white and black keys on a piano. To play a middle C, the synthesizer is sent a message that specifies the note has a pitch of 60. To play a concert A (the A above middle C), the message specifies a pitch of 69. Because notes are just whole integers, it’s possible to easily create all types of chords just by using simple math.
For instance, a C major triad starting at middle C is the notes 60, 64, and 67. Keep in mind that in MIDI, the black keys are counted, too. So instead of thirds and fifths to specify the notes of a major chord, it’s root, root+4, and root+7.
For more details on how MIDI is programmed in Smooth Moods, check out the MIDI entry on Wikipedia, which contains extensive background on MIDI and the electronics used to create it.