Skip to Main Content
How I Hijacked FM Radio Using a Raspberry Pi ZeroBack to Top

How I Hijacked FM Radio Using a Raspberry Pi Zero

By shadowe1ite
3 minutes
Hot

Introduction

This guide shows how to set up PiFmAdv on a Raspberry Pi and broadcast FM radio using GPIO.

FM broadcasting may be illegal or regulated in your country. This demonstration is for educational and experimental purposes only. Keep transmission power low, range short, and avoid interfering with licensed stations. You are responsible for complying with local laws and regulations.

Requirements

Setup PiFmAdv

First, install Raspberry Pi OS on your Pi. This guide skips OS installation—there are plenty of guides available.

Access your Raspberry Pi terminal. Here, SSH is used.

Install dependencies

sudo apt update -y && sudo apt install git libsndfile1-dev libsoxr-dev -y

Build PiFmAdv

git clone https://github.com/Miegl/PiFmAdv.git
cd PiFmAdv/src
make clean
make

Install locally

Rename and copy the binary to a local bin directory for easy access:

mkdir -p ~/.local/bin
cp pi_fm_adv ~/.local/bin/pifm

Add it to your PATH (based on your shell):

export PATH="$PATH:$HOME/.local/bin"

Reload your shell or source the file.

Antenna Setup

Connect a jumper wire to GPIO4 on the Raspberry Pi. This wire acts as the FM antenna.

GPIO4 on Raspberry Pi Zero 2 W

Raspberry Pi Zero W GPIO Pinout

Use the pin diagram above to identify the correct pin.

Broadcasting radio signals

using an audio file

sudo pifm -f 103.2 --ps "DawnFM" --rt "SongName" -a "$HOME/Music/song.wav"

Using a microphone

  1. Connect your microphone (USB dongle or USB mic).
  2. Find the microphone device ID:
arecord -l

You’ll see something like:

card 1: USB [USB Audio], device 0: USB Audio [USB Audio]

That means:

card = 1
device = 0

So the mic ID becomes:

plughw:1,0

Test the mic (important):

arecord -D plughw:1,0 -f S16_LE -r 22050 test.wav
aplay test.wav

If you hear your voice, the mic is set correctly.

  1. Broadcast live audio:
arecord -d 0 -c 1 -f S16_LE -r 22050 -t wav -D plughw:1,0 - | sudo pifm -f 103.2 --ps "DawnFM" --rt "Live Broadcast" -a -

Replace plughw:1,0 with your mic’s actual card and device numbers.


Broadcasting MPD Music over FM

This part is for when your music is playing on another computer and you want the Raspberry Pi to rebroadcast it over FM.

MPD runs on your main machine, exposes an audio stream over HTTP, and the Pi simply listens to that stream and transmits it using PiFmAdv.

MPD configuration

Add this block to your mpd.conf:

music_directory "~/Music"
auto_update "yes"
bind_to_address "any"
port "6600"
restore_paused "yes"

audio_output {
    type "httpd"
    name "Radio Stream"
    encoder "flac"
    port "5555"
    bind_to_address "0.0.0.0"
    always_on "yes"
    mixer_type "software"
    tags "yes"
    format "44100:16:2"
}

This tells MPD to:

Restart MPD after editing:

systemctl --user restart mpd

Streaming MPD into PiFmAdv

Now use your favorite music mpd client to play music here i am using euphonica

On the Raspberry Pi, connect to the MPD stream and broadcast it:

ffmpeg -re \
  -reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 2 \
  -i http://192.168.1.75:5555 \
  -ac 2 -ar 44100 -f wav - \
| sudo pifm -f 103.2 --ps "DawnFM" --rt "Stereo Stream" -a -

What’s happening here, in plain terms:

As long as MPD is playing, your radio is live.