This simple hack turns your Raspberry Pi into a powerful FM transmitter! It has enough range to cover your home, DIY drive-in movie, silent disco, a high school ball game, or even a bike parade (depending on the stragglers).

PiFM software not only boldly enhances the capability of your Pi, but does so with nothing more than a single length of wire. This hack starts with the absolute minimum you need to run a Raspberry Pi — an SD card, a power source, and the board itself — and adds one piece of wire. It’s the coolest Pi device we’ve ever seen with so few materials.

PiFM was originally created by Oliver Mattos and Oskar Weigl, and revised by Ryan Grassel. We’d like to thank the whole PiFM community for inspiration. MAKE’s contribution to the project, the PirateRadio.py script, now enables playback without using the command line, and handles all the most common music file formats automatically. It was written by MAKE Labs engineering intern Wynter Woods. You can find the source code here.

radio

NOTE: The Raspberry Pi’s broadcast frequency can range between 1Mhz and 250Mhz, which may interfere with government bands. We advise that you limit your transmissions to the standard FM band of 87.5MHz–107.9MHz (see Step 3) and always choose a frequency that’s not already in use, to avoid interference with licensed broadcasters.

What will the next generation of Make: look like? We’re inviting you to shape the future by investing in Make:. By becoming an investor, you help decide what’s next. The future of Make: is in your hands. Learn More.

Project Steps

Make the antenna.

Technically, all you need for an antenna is a piece of wire. For an optimal antenna, you could attach a 75cm wire to pin 4, with a 75cm power cable pointed in the other direction. (That would effectively make a half-wave dipole antenna at 100MHz, near the middle of the FM band.) We just used 40cm of 12 AWG solid wire, since things started tipping over when the wire got longer.

Cut and strip a female jumper wire. Solder it to one end of your antenna, and insulate with heat-shrink tubing.

Dab hot glue around the joint for support, and stick it on pin 4 of the GPIO pins of your Raspberry Pi. The glue makes the antenna more rigid so it stands up better.

NOTE: If you have the Raspberry Pi Starter Kit and you’re in a hurry, you can just use a male jumper wire plugged into the Cobbler breakout board! (Both are included in the kit.) It will work, but the range will be roughly half of what you’d get with 40cm of 12 AWG solid copper.

Flash the SD card and add music.

To save you time configuring everything, MAKE Labs made a disk image. Download it here. (Advanced users who just want the source can find the link in the intro.)

The original PiFM code proved the concept with impressive results. The MAKE image takes the work out of partitioning the card into system and data partitions. It also auto-mounts the data partition. It uses a fraction of the CPU of the original code and enables playback from MP3, FLAC, and more. And it runs the PirateRadio.py script on startup, so your music starts broadcasting immediately once the transmitter boots up. Ultimately, this will save you a lot of time. But you can’t just drag the files to your SD card; it must be flashed to work.

Flash the image to your SD card. If you’re not familiar with the process, it’s easy. Good tutorials can be found here. You can use Win32DiskImager on Windows, or the Command Line Tools (1) instructions if you’re on OSX. I’ll assume Linux users have moved on already.

For OSX and Linux users, simply open up the PirateRadio partition and get started. Windows users, follow our instructions for connecting to your Pi via SSH using WinSCP.

To add music, simply add your artist or album folders to the root of the “Pirate Radio” partition of the SD card. Your music files can be nested within these folders, so there’s no need to dump all your music into one mess on the main directory.

Edit the config file.

You can set the frequency you want to broadcast on in the pirateradio.config file. Open it up in a text editor. You should see something like:

[pirateradio]

frequency = 88.9

shuffle = True

repeat_all = True

Set frequency to the station you want to broadcast on. Useable FM frequencies are typically from 87.5MHz to 108.0MHz. (108.2 was the highest our test radio could reach, but that’s in an aircraft band that you should never interfere with.)

Set shuffle to True to shuffle files, or to False to play files alphabetically.

Set repeat_all to True if you want to loop forever through your playlist.

Start it up!

Tune your FM radio to your frequency of choice and plug in the Raspberry Pi. It will take about 15 seconds to warm up. Once it does, you should hear your music loud and clear.

How the PiFM software works.

From the PiFM wiki:

“It uses the hardware on the Raspberry Pi that is actually meant to generate spread-spectrum clock signals on the GPIO pins to output FM radio energy. This means that all you need to do to turn the Raspberry Pi into a (ridiculously powerful) FM transmitter is to plug in a wire as the antenna (as little as 20cm will do) into GPIO pin 4 and run the code.”

Frequency modulation “is done by adjusting the frequency using the fractional divider.” For example, for a target broadcast frequency of 100MHz, the signal is fluctuated between 100.025Mhz and 99.975Mhz, which makes the audio signal.

The Python code defaults to 87.9 FM with shuffle and repeat turned off. It scans the SD card for music files and builds a playlist based on the options in the config file. It then passes each file along to a decoder based on the filetype. Each file is then re-encoded into a mono format the PiFM radio can handle. This lets you play more than just WAV files: use your MP3, FLAC, M4A, AAC, or WMA files too.

Going further.

Tuck everything in the acrylic case that comes with your Raspberry Pi Starter Kit and you’re good to go. Or, if you want something cooler or more subversive, try building an awesome housing of your own. MAKE Labs manager Sam Freeman drew up this little number, a cool radio tower; download it at thingiverse.com/makelabs.

Add RadioShack’s handy USB battery pack so you can carry your station wherever you need to take over the airwaves. (It fits inside the radio tower, too.)

NOTE: If you have trouble with range, double-check which pin your antenna is plugged into. At MAKE Labs we spent a few hours puzzled by our antenna’s performance, only to discover it was one pin over!

TIP: For a cleaner FM signal, and to reduce any accidental broadcasts outside the FM band, build a simple bandpass filter for your Pirate Radio using just a few components, at makezine.com/go/pirate-bandpass.