Introduction: Raspberry Pi Radio Transmitter

Picture of Raspberry Pi Radio Transmitter

The Raspberry Pi is a very useful computer that can be used for many different things. The people over at Imperial College Robotics Society have a new way to use your favorite treat. They designed a program that turns the Pi into an FM radio transmitter. This instructable will show you how to make your own Pifm transmitter, installing and using the program.

Some Updates (03/11/15):

There is a new program up that I wrote where you only need the filename (NOT THE PATH). It will install everything for you, all you have to do is type in the frequency and the filename to be played (WAV or MP3, stereo or mono).

ICRS has released another version on PiFM a while back, it allows you to play stereo sounds (mp3 files) over the radio now. You can go to this link here to check out the new information (the new code is included in my program listed above.)

More Updates (08/06/15):

The member, AndrewG29, has given me a link to GitHub that supports the Raspberry Pi 2! Through the traditional method, this doesn't work on the RPi2.

Step 1: Having the Necessary Parts

Picture of Having the Necessary Parts

Obviously this will not work unless you have the right parts to start your Pifm radio. I will list the basic things that you need to start up your Raspberry Pi that most of you already have, but I will put it there for the people that don't.  In the second paragraph are things that you may not have that you need.

1. Raspberry Pi
2. 5 volt 1 amp (between 750 milliamps and 2 amps is what I have tried) USB power supply
3. Micro USB cable
4. At least 2 GB SD card with Raspbian on it
5. A display or ssh 

Now past the basics, you will need these items as well for it to work.

1. Ethernet cable or a wifi dongle (See step two if you don't have this)
2. Some sort of antenna
You can just use your finger but it will not work as well, you can use a Pi Cobbler with some wire sticking out of the pin like I did, it works fine, the projected range is about 10 meters, but I found it to go much longer than that.

Step 2: Downloading the Packages

Picture of Downloading the Packages

Now that we have everything we need, we can get to installing the software, it is a very simple process.  Keep in mind that this will not work if you are not connected to the internet (see below**).  You only need the internet to download the software, you can use this afterwards without internet.

** If you have an Ethernet cable you can ignore this paragraph.  If you don't have an Ethernet cable but you still want to do this you can download the files onto your computer and put it on a flash drive and upload it to the "pi/home" directory.

Now in your Pi terminal type in this exactly, pay attention to capitalization!

(Capitalized 'P' in 'Pifm.tar.gz')

(If you did it right when you type 'ls' you should see other files along with one named, 'Pifm.tar.gz')

     tar -xvf Pifm.tar.gz
(Again, capitalized 'P' in 'Pifm.tar.gz')

That's it!  All of the code is done, now on to the next step to learn how to actually play music over any station you want.

Step 3: Using the Software

Picture of Using the Software

Finally we are to the end of our journey, but all of this hard work pays off when you can impress your friends with your awesome new 'hacking' abilities!

There are a few commands that are used to control the pi I will list them below and break them up and tell you what they mean step by step.

Before we get into the code, you need to know what pin it broadcast's out of so you can attach your antenna to it.  GPIO pin 4 is what is being used, unfortunately you can't change the pin number because it have specific specifications embedded into it, so if you have something else running out of GPIO pin 4, you will have to change it or take it out for this to work.

     sudo ./pifm sound.wav 100.1

          sudo - This gives you administrator power (like on windows the admin)

          ./pifm - The ./ is used to run a program, the program you want to run is what you put after it (pifm)

          sound.wav - Here is the music you want to be played over the radio, you can change it to any** .wav file
          100.1 - This is the station that you want your music to be played on, you can change this to anything between 87.1 and 108.1

To exit your song press, 'control' + 'c'

If you have a microphone you can plug it into the USB port and broadcast your voice over the radio station here is what you will type in:

     arecord -fS16_LE -r 22050 -Dplughw:1,0 - | sudo ./pifm - 100.1 22050
(pay attention to capitalization)

To do this of course you have to have a USB microphone, I have an old Wii Karaoke microphone that works just fine.  You can just pick one up off Amazon to, I just found a Guitar Hero one for about $15 here.

Step 4: Adding Other Songs

Picture of Adding Other Songs

So you probably don't just want one song on your Raspberry Pi. To put the songs that you want onto it you have to have the correct format. It has to be a .wav file and if you have a .mp3 file or .mp4 or whatever, you need to convert it. You can use this online one here. It also has to be in 16 bit : 22050 Hz : mono. If it is not like that it will sound really slow and weird or really fast and weird.

UPDATE: There is now a way to use .mp3 files in your raspberry pi, here is a Google Doc for more information.

To import your song just use an FTP server like Fillzilla, you can find a pretty good tutorial on it here. Make sure you import it to the home/pi directory (it is on it by default) to avoid extra work. As far as the code just replace the 'sound.wav' with the name of your song.

EX. sudo ./pifm livin_on_a_prayer.wav 100.1

If your song has spaces in it you may notice that it doesn't work, it will give you an error, to fix this put the name of the song in quotes.

EX. sudo ./pifm "living on a prayer.wav" 100.1

Make sure that you are capitalizing what you are suppose to
Be sure to spell everything right
You can see all of the songs that you downloaded by typing 'ls' in the command line
Any other questions, don't be afraid to leave a comment!


RandyB44 (author)2016-03-17

for those who have pi2 model b follow this persons vid on youtube. Works for me

Cody Heiser (author)RandyB442016-03-18

Thanks for sharing this video! I'll have to try it out sometime!

MMKaresz (author)Cody Heiser2016-09-12

Just a question: I would like to use it in the car, because I have only built-in radio and cd player. I have a pi zero, can this run on it?

PrashantK83 (author)Cody Heiser2016-07-24

can we use same code on rasberry pi 3 modal b.i reached on step 3rd but i have not recive any sonund on my handset so plese help me in code.

dleite (author)2014-07-08

You do not want to be using this as a long term, stationary FM
transmitter. If any of your signals interfere with air traffic control,
emergency services (police, ambulance), etc they will come looking for
your signal and ultimately you. Looking at a spectrum analyzer with a
frequency of 88.7MHz there are harmonics all across the VHF band.
Centering on 121.5MHZ, your aviation band emergency frequency, there are
harmonics and intermod products all through aviation VHF band
(118-136MHz,) and VHF navaids (108-117MHz). If you use this you will
splash onto these frequencies. If nobody complains, nobody will come
looking for the signal. If this does interfere with aircraft, I
guarantee you someone, (FAA in US, Industry Canada in CA) will come by
with a DF and find you and you can be charged. Use with caution.

windsr (author)dleite2014-09-01

Quite true, it generates a square wave and splatters all over the VHF and UHF bands. A frequency counter puts this at the specified freq above (100.1). Using a SDR with an antenna very close to the RPi I was able to see harmonics when the radio was active but not sending a wav file every 466Khz, granted, not a very accurate method but somewhat effective. While the radio was transmitting a Wav file I heard strong audio at 100.1, ~150, ~200, ~300(very strong), ~400(very strong), , ~600, ~700, ~900 and ~1.1Ghz. You can find some videos showing an actual spectrum analyzer how dirty this is as a FM radio.

The attached image shows some of the air band through the SDR while the Pi is not sending a wav audio. Also another image while transmitting at 100.1 showing it at 600Mhz

The output power is very low so it shouldn't be an issue, I can barely hear the radio 40ft away, just be aware of what @dleite says above.

stoobers (author)windsr2015-03-26


Your comment is kind of a big deal.

Any idea how to filter this to get rid of the harmonics?

Can you do an instructable on how you found these spikes? I am not familiar with software defined radio (other than in theory) and would be a great way to detect dirty transmissions from homemade equipment.

windsr (author)stoobers2015-03-26

Not sure we'd be able to get rid of the harmonics since they are being generated by the Pi. Maybe at the output (antenna) we could add a band pass filter before the signal gets to a tunned antenna so the range for the harmonics is limitted.

I might be able to do an instructable for this but I'll need to start from scratch since I keep configuring my Pi for different projects. SDR is easy to get started with using cheap dongles; you can find them anywhere from $10 - $25.

Adafruit has instructions on building a scanner using a Pi, don't know what it would look like but it's on my to-do list.

stoobers (author)windsr2015-07-06


What I am asking about, is what steps were taken to view the harmonics, and if you could make an instructable for this? (call this the "windsr method"). If I were designing a band pass filter, I would want to use this "windsr method" to make sure my filter works and I am not letting splatter escape and cause trouble.

3of5 (author)dleite2014-10-27

haven't tested that yet, I live in a place where there should be no interference. I would like to hook this up to an rf amp and then a filter to deplete the interference. just using the raspberry pi and a length of wire shouldn't get you and farther than your house depending on where in the house the antenna is, and how long it is. I guess if I do cause harmful interference to aviation and others like that, it should be within my ham license limit. I would rather have my license stripped of me and have to re-take the test rather than be fined a couple hundred thousand dollars.

james132 (author)3of52015-03-13

Still going to want to be careful. Interference in a non ham band such as the aviation bands have nothing to do with your ham license. Also, if you are in the US, if you have your license revoked it is much more difficult than just retesting to get it back. There is legal red tape and a very good possibility of not getting it back

Cody Heiser (author)dleite2014-07-08

Of course, this is just an example of how it could be done and people need to use it in complience with the FAA.

Squidyman (author)Cody Heiser2014-08-02

lol why worry? This puts out such a tiny amount of power a receiver will not pick it up less than 50 feet away. No DF is sensitive enough to pick up such a tiny signal. Heck even a large electric motor puts out more noise than this!

Cody Heiser (author)2015-03-11

There is a new program up that I wrote where you only need the filename (NOT THE PATH). It will install everything for you, all you have to do is type in the frequency and the filename to be played (WAV or MP3, stereo or mono).

james132 (author)Cody Heiser2015-03-13

Glad to hear you are still working on this project! That is an excellent improvement

Cody Heiser (author)james1322015-03-14

Thanks! I am working on a PiStation v3 now that would show recommended results. So if you typed in the song name wrong, instead of having to restart the program and type in the song name again it would say, did you mean 'this' song instead? But it is still in the development process!

RichardM457 (author)2017-12-28

The lesson here is that any electronic equipment that operates at high frequencies can become a radio, especially when you don't want it to be. it's called EMI Electromagnetic Interference. The trick is keeping your PC, switching power supply, TV, RPi from becoming a radio when you don't want it to be by proper cabling, filtering and shielding. I'm not sure about the details - I suppose there is some PWM going on. It would be interesting to find an actual FM SoC and mate it to the RPi to get a air-wave friendly transmitter.

bpd362 (author)2017-05-16

Would this work on a pi zero?

AndytheAdventurer (author)2016-10-11

I made this and it works great! But, the only concern I have is it possible to have almost like a playlist run? Or can you only play one track at a time.

RareșN2 (author)2016-08-13

This is so awesome!!! I'm planning to use an existing audio stream (from the internet, over HTTP) and pass it throught to FM.

PrashantK83 (author)2016-07-14

Hello sir,

i have completed 3rd step and i write code for sound wave but howto convert song into rasberry pi 3 please help me

PrashantK83 (author)2016-07-14

Hello sir,

i have completed 3rd step and i write code for sound wave but howto convert song into rasberry pi 3 please help me

Gustav_Clausen1 (author)2016-03-27

will this work on raspberry pi 3 b?

i tried but it didnt work

what about you ??

PawełP25 (author)2016-05-18

Hello, who knows how it looks like on raspberry pi 3? Its working? I did this but its not working - any ideas?

i tried but it didnt work

what about you ??

GeorgeP85 (author)2016-03-04

Nice. I am a licensed amateur radio operator. The comments listed here demonstrate why building an FM transmitter is not trivial :( I wish it were. It makes VHF/UHF experimentation difficult.

GeorgeP85 (author)GeorgeP852016-03-04

I want some distance like my local area for CW weak signal transmission for nets and beacon and such. Again, not trivial :(

SubramanianN (author)2015-08-05
i dont know why .....but the whole thing till downloading works but broadcasting has a problem i believe .......the things is that i have raspberry pi 2 not the 1st version the gpio pins and other stuff isnt going on well.

and also the ^cexiting command is not coming once i give the the command before that ( sudo ./pifm sound.wav 100.1)

can someone please help me out ......

mudassar butt (author)2015-03-22

please tell me maximum area covered by this project..?? reply plz.

It really depends on your location and how much interference there is. If I had to pick a number I would say about 10 meters (32 feet) in open air, and about 5 meters between floors/walls. Also making a bigger antenna would make the signal better. Be sure you aren't near an airport or something similar! You are only legally allowed to transmit 200 feet (61 meters) in the US, not to sure about the UK however.

any method to increase the area..?? antenna specification or software changes for larger coverage..??

You could try a different type of antenna (folded dipole or something similar). Use this formula to find out how long to make the wire (to maximize your distance covered); L = 93.75/f where 'L' is the length of wire to use and 'f' is the frequency, so if the frequency was 95.5, then enter L = 93.75/95.5. The number that comes out is how many meters the antenna should be, convert it to whatever unit you like to use after that. When scaling the wire up and down, do it in fourths and halves (for downscaling) and doubles, triples, quadruples, etc. (for upscaling). Make your antenna in the shape of a 'T' as well (folded dipole is what it's called).

EttoreP (author)Cody Heiser2015-11-17

ok for the dipole, but how can I connect a dipole antenna to a single pin (gpio 4)?

Cody Heiser (author)EttoreP2015-11-17

I am not 100% sure, but what I would try is connecting one to ground and one to GPIO 4. Again I'm not positive, but that's what I would try.

JacobBr (author)2015-10-03

Hi, I was wondering where the antenna should be connected to the Rpi. (What Pin #) Right now I am playing the sound and have all the code working, but the radio 5 feet away won't pick it up. I finally realized it is because there is no antenna connected. Thank you!

taifur (author)2015-09-18

Nice and useful task

undertakerbro (author)2015-08-03

Hi, if anyone can please answer if the following is possible. Can we get the audio output of the pi to play on the FM modulation? I mean any sound that comes out of the Pi to be transmitted on the FM pin. I want to have VLC working on the PI and I want it's output to go to the FM modulation. Is there any way to do this? (software solution would be best).

I'm not quite sure I know what you mean, you want to transmit sound from a VLC player to the Raspberry Pi?

VLC player is running on RPI. I want to transmit the sound produced by vlc on FM..the easiest way is to hook RPI audio out to an external FM modulator.

The end goal is to have a headless RPI that I control songs from my phone and it transmits over FM.

Is there anything like: sudo ./pifm rpi_audio_output 100.1 ?

PS: I tried to do it like in the tutorial with sound.wav. It does not work I cant find it on my randio....I used a 30cm ribboncable as the antena and nothing...tried with a long cable...still nothing...I have a RPI2 model B

AndrewG29 (author)undertakerbro2015-08-05

PiFm isn't currently compatible with the Pi2 as far as I can tell. I got this working great tonight though:

Subeer MuuseL (author)AndrewG292015-08-23

I have raspberry Pi 2, and i couldn't figure out how to work on your way so please any tutorial will be much appreciated

Cody Heiser (author)AndrewG292015-08-05

Ah yes I missed that part about the Pi2. So that program is working on the Pi2?

AndrewG29 (author)Cody Heiser2015-08-06

Yep, literally got it set up yesterday, works a charm.

Cody Heiser (author)AndrewG292015-08-06

Awesome, I will put it at the top and credit you. Thanks for sharing this!

Oh okay I see what you mean. I haven't tried this but here are some of my recommendations, get a USB cable and use it to somehow (sorry I would have to look into how to do that) connect your Raspberry Pi to your computer/phone(headphone jack) or other interface device, then control it using the microphone command (it should be in one of the steps). Another option would be to search online for someway to trasnfer sound over LAN to the RPI. Haven't looked into either. I would be interested if you find anything on this subject!

dewintermaarten (author)2015-03-25

Will it work with the Raspberry Pi2B?

One person reported it having issues on the Pi2. Technically it should work, but you might have to take a look at the pins and test each pin (it might not be 4 on the Pi2 like it is on the regular one) But I would just play around with it. If you have anymore questions feel free to ask me! Thanks, Cody.

Hey Cody,

Thanks for your reply. I will test this in a couple of weeks and I'll let you know! Thanks for this article, very informative and well written.

Greetings from Belgium!

About This Instructable




Bio: Love to see what makes things tick! email me at:
More by Cody Heiser:Raspberry Pi Radio TransmitterVNC Server Set upForwarding IP Ports to Your Computer
Add instructable to: