Introduction: Raspberry Pi - PiFMPlay - FM-Broadcasting Simplified

Picture of Raspberry Pi - PiFMPlay - FM-Broadcasting Simplified

Here's the hassle free way to make your raspberry pi play your music files over FM-radio!

Skip to the next step if you are in a hurry ;)

For a couple of days I have been messing around with PiFM, and I absolutely love having my own radio station.
So far I've gotten about 50m range outside, not much, but certainly enough to broadcast at and around home. It is possible to improve the range drastically by adding filters and signal amplifiers , but broadcasting with that kind of range is illegal without a license -.-

Yup, pifm is awesome!!! But its a little impractical to use, you have to convert every different format and its troublesome to write the long one-liners over and over. It's just not practical to use if you're outside controlling it from your phone via ssh.

I wanted it to be as easy to use as the programs aplay and play, so I made PiFMPlay :D

PiFMPlay is here to make it easier to control your PiFM-radio broadcast.

I DIDN'T make PiFM! Kudos and thanks to icrobotics :D

I DID make the PiFMPlay script, and it's on github. Feel free to fork it from there:

Now, lets get to it!

Step 1: Tl;dr (Too Long Didn't Read)

Picture of Tl;dr (Too Long Didn't Read)

This is the quickest way to set up pifmplay.

Open a terminal on your Raspberry Pi.
Download pifmplay:


Unzip it:

Move the 'pifmplay' folder to /home/pi:

mv PiFMPlay-master/pifmplay ~/pifmplay

Go into the pifmplay folder:

cd ~/pifmplay

Then add execution permissions:

sudo chmod +x pifm pifmplay

Download & Install media converters:

sudo apt-get install ffmpeg sox libsox-fmt-all

Now edit you users bash config file:

nano ~/.bashrc

and type this at the bottom of the file:

export PATH=$PATH:~/pifmplay

restart the pi:

sudo reboot

Attach a 30cm wire to to GPIO4 (That's Pin-7)
Turn your FM-radio to frequency "91.3"

Start FM-Broadcast with:

pifmplay ~/pifmplay/starwars.wav 91.3

If you cannot hear anything on the radio, try adjusting your antenna

Step 2: Ingredients:

Picture of Ingredients:

What you will need:
- A raspberry pi up and running with internet
- a way to type commands into you pi :P (ssh or a screen and a keyboard)
- a 30cm wire to use as antenna (any antenna/wire will do)
- a brain

Software(download links comes later in the instructable):
- pifm and pifmplay
- sox
- ffmpeg
- sound/music files

Step 3: Add Antenna to GPIO4

Picture of Add Antenna to GPIO4

This one is easy:

- Connect your antenna (the 30 cm wire) to GPIO4 on your raspberry pi.

And that's all you have to with the hardware.

Step 4: Install Sound Converters

Picture of Install Sound Converters

PiFMPlay uses sox and ffmpeg to automatically convert audio files and play them with pifm.

So to use it we need to install sox and ffmpeg. Type this into a terminal on your pi:

sudo apt-get install ffmpeg sox libsox-fmt-all

Step 5: Install PiFMPlay

Picture of Install PiFMPlay

Do this in a terminal on your pi:
go to your home directory:
cd ~/

download pifmplay from github

To unzip:

Move pifmplay to where you want it, e.g:
mv PiFMPlay-master/pifmplay /home/pi/pifmplay

remove empty folder:
rm -r PiFMPlay-master

Now go into the pifmplay folder, e.g:
cd /home/pi/pifmplay

change permissions so we can run it as a program:
sudo chmod +x pifm
sudo chmod +x pifmplay

Step 6: Change Default Frequency

change the default frequency in the pifmplay script.

cd ~/pifmplay
nano pifmplay

find this line, it should be at the top somewhere..
and change 91.3 to your preffered frequency

Step 7: PiFMPlay Is Ready for Your Orders, Now Play Some Music

Picture of PiFMPlay Is Ready for Your Orders, Now Play Some Music

Go into the pifmplay folder via a terminal, and type:
sudo sh pifmplay .
(this plays some music on the default frequency. Default is 91.3 if you didn't change it )

Now try:
sudo sh pifmplay "/path/to/folder/or/sound.file" 91.3
(change 91.3 to your desired broadcast frequency.)

sudo sh $HOME/pifmplay/pifmplay "/home/pi/music/Daft Punk" 91.3
sudo sh /home/pi/pifmplay/pifmplay "/home/pi/music/Daft Punk/Daft Punk - Technologic.mp3" 91.3

Step 8: How to Use Pifmplay

Basically you just send what you want to play as the first parameter to the script, and the frequency to broadcast on as the second.
But read on, because there is more:

to play a file:
sudo sh $HOME/pifmplay/pifmplay "Name of - song.mp3"
to play a song on another frequency:
sudo sh $HOME/pifmplay/pifmplay "Name of - song.m4a" 91.3

To play a folder:
cd /into/the/folder/you/want/top/play
sudo sh $HOME/pifmplay/pifmplay .
or just
sudo sh $HOME/pifmplay/pifmplay "/path/to/music/folder" 91.3

to pause the broadcast:
sudo sh $HOME/pifmplay/pifmplay pause
to resume:
sudo sh $HOME/pifmplay/pifmplay resume
to stop:
sudo sh $HOME/pifmplay/pifmplay stop
to play the next file in the folder:
sudo sh $HOME/pifmplay/pifmplay next

If you want to run pifmplay in the background, type:
sudo sh pifmplay $HOME/pifmplay/pifmplay "/path/to/folder/or/file" &>/dev/null &

Now you are done installing pifmplay and you can enjoy using your fm-radio transmitter ;)

However; there's still some more ingredients you might want to add to your pie to make it even more awesome ;)

Step 9: (Optional)Now That PiFMPlay Is Up, Add More Music

To play music from a usb hdd or flashstick do this:

First things first:
Preheat the oven to 50°c, fold in a usb-drive into your pie, put the pie in the oven, let it cook for 50µs.
(DON'T PUT YOUR PI IT IN THE OVEN!!!! Just insert a usb drive into your pi)

Now you must find your usb media, so type in:

ls -l /dev/disk/by-uuid

That gives you a list of storage devices connected to the pi.
It should look like this:

pi@pi ~ $ ls -l /dev/disk/by-uuid
total 0
lrwxrwxrwx 1 root root 15 Jan 1 1970 676B-0317 -> ../../mmcblk0p5
lrwxrwxrwx 1 root root 10 Jan 1 1970 1B23-1234 -> ../../sda1
lrwxrwxrwx 1 root root 10 Jan 1 1970 B321-4321 -> ../../sda2
lrwxrwxrwx 1 root root 15 Jan 1 1970 A1B2-3C4D -> ../../mmcblk0p1
/\ /\
this is the disk uuid & this is the drivename. remember these, we will use them later

Your usb media drive should be called something like /dev/sda1 or /dev/sdb1, where the number at the end is the partition number.
sda is the first drive while sdb is the second, the third and fourth drive would be sdc and sdd respectively
However, its NOT /dev/mmcblk0px, that is the sdcard your OS runs from.

Now, make up a name for your drive.
To mount your media, type:

sudo mkdir /media/yourmadeupname
sudo mount -t vfat /dev/harddrivename /media/yourmadeupname

(if your drive is not formatted as FAT16 or 32, you have to change "vfat" to something else)

To make it mount it automatically at boot, we need to edit /etc/fstab
make a backup of /etc/fstab with:

sudo cp /etc/fstab/ /etc/fstab.backup

edit /etc/fstab with:

nano /etc/fstab

Remember your uuid and your made up drivename?
Add this line the the end of the file:

UUID=youruuid /media/yourmadeupname vfat rw,defaults 0 0

Replace "youruuid" with your drives actual uuid, and "yourmadeupname" with the name you made up :P

If you didn't understand my instructions, or something was unclear check out:
or google it ;)

Step 10: (optional) Add Pifmplay to Your $PATH

If you want to type even less to play your music, you must add the pifmplay folder to your $PATH
This can be done in so many ways, and i'm not sure if this is the correct way. But it works :P

on your pie, type this:
nano ~/.bashrc

now type this into the bottom of the file
export PATH=$PATH:~/pifmplay


now you should be able to type
sudo pifmplay "file/or/folder/to/play"
from anywhere, Yey! ¦-D


BurakT3 (author)2017-10-05

Hi, is there a way to stop then replay broadcast with outside trigger by wired 5v signal over pins?

uvvp (author)2017-01-05

is there any way to reveive fm using pi

ShuhanM1 (author)2016-08-15

does not work :(

ShuhanM1 (author)2016-07-27

sudo apt-get install ffmpeg sox libsox-fmt-all

says "E: Package 'ffmpeg' has no installation candidate" :(

NathanG57 (author)2016-04-15

Hi, would this work on the pi 3?

vedranius (author)2016-04-05

Any way to use PiFm with MusicBox? Thanks!

akröll (author)2016-03-31

Is there a way to play music from spotify?

roberthjhan (author)2016-02-07

I try to get ffmpeg but terminal returns:

"Package ffmpeg is not available, but is referred to by another package.This may mean that the package is missing, has been obsoleted, or is only available from another source

E: Package 'ffmpeg' has no installation candidate"

gouravgarg007 (author)2015-03-01

not working for raspberry pie 2 unable to hear anything

Mickey_Boy (author)gouravgarg0072015-03-03
you have to change some address in the pifm code so it works with the pi2, since it's a different processor ;) You might also want to check if icrobotics have updated pifm to work with the new pi2.

JohnC67 (author)Mickey_Boy2015-06-17

Do you have a backup of it?Topic got deleted...

Mickey_Boy (author)JohnC672016-01-29

nope sorry. if you find a fix, tell me and I'll add it to the repo on github :)

Mark Collins (author)2015-08-29

+Mickey_Boy Are you sure we need a brain for this project ???

Mickey_Boy (author)Mark Collins2016-01-29

Apparently :P

theshubhamk made it! (author)2015-09-13

how to repeat songs in folder??

Mickey_Boy (author)theshubhamk2016-01-29

feature added by a collaborator on github just now, redownload from github and you will get the new feature.

sdidwania (author)2015-05-28

can we use PI audio in to broadcast at a frequency. not play some stored files.

Mickey_Boy (author)sdidwania2016-01-29

Read the instructable... pifmplay plays mp3s wavs and all sorts of other sound files.

Yes, you can set it to actually get audio from an audio device, and route it to the transmission. The official page of this project explains how.

CoderDog (author)2016-01-26

I precisely did what you said in the first step, yet there is an error message saying: /home/pi/pifmplay/pifmplay: 94: /home/pi/pifmplay/pifmplay: ffmpeg not found exiting. Please respond and answer. Seems great though!

Mickey_Boy (author)CoderDog2016-01-29

ffmpeg not found means you do not have ffmpeg installed...

TheRealDutchOwner (author)2015-10-21

My transmitter starts transmitting a beeping sound when left on too long with no sound going to it. The USB soundcard keeps blinking when it does this while the LED stays static when it is functioning. What could be the problem? Does arecord reset the USB card at some point messing up the script? This is very frustrating as I am planning to make this a stationary transmitter.

PrinceZordar (author)2015-02-15

Just started playing with a Raspberry Pi 2. Can't seem to get PiFM to work. It doesn't give an error, it just sits there until I cancel it. I don't get any output to a nearby radio. I've checked a lot of sites, including, but most of the comments are people arguing over the legality of it all.

Mickey_Boy (author)PrinceZordar2015-03-03

smarticles101 (author)Mickey_Boy2015-10-09

That topic no longer exists, could you post the solution?

PrinceZordar (author)Mickey_Boy2015-03-08

Awesome, thanks, that's exactly what I was looking for.

in my case its got started but i am unable to hear anything whats your status??

It's broadcasting, but not the wav file I send to it. I'm seeing people say that it's a trivial change, but apparently the questionable legality is preventing them from sharing. Too bad, I thought the point was to learn, not to be shielded from knowledge.

brycef1 (author)2015-09-24

theshubhamk (author)2015-09-13

how to repeat songs i folder??

MohdS2 (author)2015-03-20

I am getting some strange problem ,When ever i try to play a song it play for a second and then it starts beep and keeps on beeping.....

I have tried everything changed power supply , changed antenna and reboot my pi several times .

Can you please help me?i need to do this as a school project sir :(.....

marwadi (author)2015-03-20

Failed to fetch 404 Not Found

marwadi (author)2015-03-20

Failed to fetch 404 Not Found

how to sloved this error

BasC1 (author)2015-03-15

Is it possible to put a text on the display of your radio? For example I play a song, and you can see on the radio which song it is.

Mickey_Boy (author)BasC12015-03-16

Both sox and ffmpeg should display the song in the terminal on program execution.

derekiswise (author)2014-11-02

also,(i am not good with coding) as a recommendation in the future i would add a shuffle command so people can restart their stations and hear different music than before, Thank you so muchfor your work on this. i loved pifm before but now it is sooooo much easier to use!

Mickey_Boy (author)derekiswise2015-01-06

That's a good idea. But right now I'm busy playing with other things. Feel free to add features to pifmplay on

AndrewH7 (author)2014-12-08

Hi, thanks for the instructable. Do you know if there is a way to change the frequency of the transmission while the song is playing? I.e. Without having to stop it and then replay it? Thanks!

Mickey_Boy (author)AndrewH72015-01-06

Not atm. Feel free to add features on ;)

luis.romeroquiroz (author)2014-12-07

hi, i would want to know, how i can use the function playstream with Spotify?

I guess something like this: could work. But I have no plans on expanding pifmplay, I'm busy playing with other things ;)

aks3 (author)2014-10-06

sudo mount -t vfat /dev/harddrivename


which one is that?

Mickey_Boy (author)aks32014-11-10

that depends, unplug you hdd and open a terminal.

'cd /dev/'


you should now see a list of devices and their respective names.
usb hdd and memory sticks comes up as sda, sdb, sdc, sdd and so on

plug in the hdd

then look for the new drivename if you only have one drive connected, it should be /dev/sda, drive partitions appear as /dev/sda1 /dev/sda2

if your drive is called /dev/sda, and it is formatted with fat32, then write
sudo mount -t vfat /dev/sda

if your drive is not fat32, change 'vfat' to correct format.

derekiswise (author)2014-11-02

one quick question, Will pifm play look into the folders in a folder and play the music in their. I currently have it so all the music files (more than 7 hours worth) are in one folder, but my brothers/ mom have different music preferences and i want to be able to have it play all music if i choose the parent folder, but have the music in the specific folder for the person in my family. Does all this make any sense? sorry if it is a bit comfusing

HansakaP (author)2014-08-11

mp3 songs playing slower than it suppose to be

scottinnh (author)HansakaP2014-09-03

Try using (or borrowing) one of those $5 USB Sound Card thingys.

Basically the sound-out on the Pi is very bad... pops and clicks if the Pi is doing anything else. (The new Pi B+ model has improved power filtering which helps with this issue, but an external USB sound device will give best results).

Chee2 (author)2014-08-13

can here music just a blank noise

PLZ help??

ps. this works as a jammer

Chee2 (author)Chee22014-08-13

plus it saing not found exiting

jlynggaard (author)2014-06-19

On mySD card is fresh installation of Pifm, installed using the steps mentioned in this guide:

When i type commands (everything apart from the basics: halt, reboot, cd, pwd, ls...) the Rasbpberry PI doesn't do what it's told to... That effectively leaves me stuck on the first step in this tutorial!

Example of the type of messages i receive:
I typed:
apt-get install ffmpeg
-bash: sudo: command not found

Since I am trying to install PiFMPlay, any answer helping me further along doing so would be much appreciated!


Mickey_Boy (author)jlynggaard2014-06-19

Hmm, sounds like you made a mistake somewhere when installing PiRateRadio. Probably a fault in a config file that keeps your pi from booting properly, thats why it cant find the sudo program.
If i were you I would re-flash the sd-card, and start from a fresh raspbian install -_-

About This Instructable




Bio: Not much to say. I'm a student, learning about computers, and I like to tinker with electronics, 3D-Designing, prototyping and machining
More by Mickey_Boy:Raspberry Pi - PiFMPlay - FM-Broadcasting SimplifiedRaspberry pi - simple 2x2x2 led cube
Add instructable to: