Turn your Raspberry Pi into a Wireless Portable Bluetooth Audio System A2DP

Picture of Turn your Raspberry Pi into a Wireless Portable Bluetooth Audio System A2DP
Howdy folks! I had the idea of turning my Raspberry Pi into something like the Beats By Dre portable audio system found here:,default,pd.html

It’s a cool product, don’t get me wrong, but I’m not really down to pay $400+ tax for some fancy looking speakers (which don't even give you rechargeable batteries, by the way). So I decided to set off to replicate the functionality without the hefty price tag.

OBJECTIVE: To create a Raspberry Pi that automatically boots into the command line and becomes discoverable via Bluetooth. Any Bluetooth-enabled device with the A2DP (Advanced Audio Distribution Profile) support will be able to push audio to the Pi through its Analog (default) or HDMI speaker output. When a Bluetooth device connects, the PI routes the connection through to Pulse audio and Bluetooth discoverability is turned off. The audio should play seamlessly from here. You can then disconnect your device (likely a smartphone) and the PI will become discoverable again via Bluetooth and another device is free to connect. The default pass key will be 0000 but most devices input this automatically so it should be hassle free!

NOTE: I did find that a lot of other people in the Linux community have attempted to do the same thing to their PI but not as successfully as I have! My setup allows the device to run headless (without a monitor) from boot and any Bluetooth device can connect and disconnect without an issue. I’ve seen a lot of other people with tutorials that make you login via command line first or login to the desktop and setup the Bluetooth connection manually. LAME! The goal of this is to be as similar to a *product* as possible. :) enjoy!

NOTE: This tutorial assumes you have a fair amount of Linux/command-line knowledge. I won’t be explaining basic commands or ideology so if this is above your head find a friend!

What is the Raspberry PI?
The Raspberry Pi is a credit-card sized computer that plugs into your TV and a keyboard. It’s a capable little PC which can be used for many of the things that your desktop PC does, like spreadsheets, word-processing and games. It also plays high-definition video. --Raspberry PI website

You can learn more about the PI and how to get one, here:

• Raspberry Pi
• Bluetooth v4.0+ micro USB dongle
• 4GB SD Card

Requirements for [portable audio]
• Battery-powered speaker(s)
• Battery pack for Raspberry Pi
• Enclosure to keep everything in
Remove these adsRemove these ads by Signing Up
1-40 of 157Next »
nreyes17 days ago

I'm having the same issue as Philrlewis

"Every time I try to set my class as 0x20041C in /var/lib/bluetooth/ it saves, but on reboot the class has reverted back to 0x4e041c. Any ideas how to stop this?"

DomR19 days ago

I have an odd problem, I've managed to get it to work, it will connect and play a song for about 10 seconds and then there will be no sound, the song will continue to play on my phone and it is still connected via bluetooth but no sound will come out!

To start it working again, I either have to restart the Pi or just restart bluetooth (sudo service bluetooth force-reload) and it will do the same thing.

Any ideas?

Great instructable!!

I've followed the instructions closely, used the old kernel, and even followed some of the comment suggestions.
However, I'm getting "Connection Unsuccessful - Make sure bluetooth is on and in range"
Looks like the bluetooth blue light comes on intermittently on the Pi.

Any thoughts would be greatly appreciated!

Never got this working but here's a working Rasbpi-Bluetooth tutorial instead:

To follow up, I've tried these two bluetooth models off Amazon, both confirmed working with Raspberry Pi in the Amazon reviews. I don't think they're faulty here. (Low energy bluetooth) (Regular bluetooth)

I've also tried all the applicable comment recommendations (Diff script, diff kernel, etc.)

Running this didn't return anything.

tail -f /var/log/bluetooth_dev

RPCALIVE1 month ago

sudo apt-get upgrade should be sudo apt-get update

lukeg016 months ago

hmmm..... seems to work, got a device with a headset sign in the list.... now just ONE terrible problem.... i can't find the PIN code.... 0000 and 1234 did not help


lukeg01 lukeg016 months ago

fixed it using bluez agent, now... no audio not even for 20 sec, maybe worth noting, i'm using "Xbian" instead of raspbian, meaning everything with alas needs
needs the "sudo" command


DusanKo lukeg011 month ago


I hope i did not make two posts:)

Can You please give step by step instuctions how You managed the PIN pairing with bluez?

thank You lukeg01

wapenv2 months ago

After the 20 seconds fix it worked for me! But I'm searching for a command that stops playing... Because I also want to play internet radio...Someone a idea?

tbailey962 months ago

Thanks for this, I tried a few other methods before this one and couldn't make them work, this works, but the volume of the output from the 3.5mm jack is very low, as a result I need my amp turned up really high. I tried to fix this by increasing the master volume in the Bluetooth script to 200%, and that didn't have any affect, so has anyone got any ideas on how to make the pi kick out more volume? :)

Thanks In Advance,


sigilium2 months ago

Thanks for this, worked like a charm. Tomorrow morning my Raspi starts a new life in my car :)

I get quite nasty background noise from the analog output. Hope it's not so bad in car!

PeppoF2 months ago


I followed these steps.. I'm able to pair my Nexus 4 with the USB Bluetooth dongle (CSL v4.0 from amazon), but no sound is going out from speakers. I can see the device loaded correctly with pactl module in the bluetooth_dev log.

Now I have this version of Wheezy:

Linux raspberrypi 3.12.18+ #673 PREEMPT Thu Apr 24 18:34:24 BST 2014 armv6l GNU/Linux

Another thing I don't know if can cause problems, is the class of bluetooth. By default mine is 0x4e041c and I changed it to 0x20041c as suggested, but in the

/var/lib/bluetooth/><ADDRESS>/config file, the value changes back to 0x4e041c

(probably after a reboot or restart of bluetooth service).

Any suggestions? There could be compatibility problems with the dongle at this point, also if I can pair the device?


PeppoF PeppoF2 months ago

At last I made it.. I have changed two things, don't know which one (or both/none?) has worked.

First I put the class 0x4e041c on every configuration file and then I noticed that listing sink properties with

pactl list sinks

the "Mute" property was set to "Yes".. so I switched to "No" using this command:

pactl set-sink-mute alsa_output.platform-bcm2835_AUD0.0.analog-stereo 0

Anyway, after a reboot, it worked.

Now I have an issue with bluetooth pair... If I restart the bluetooth service, no device is able to pair again, until I reboot again the pi.

HaraldE2 months ago

At last I got this running on my Raspberry Pi model A, I got it working with Wheezy distro 2014-06-20. I did the apt-get update, apt-get upgrade and also updated the RPi firmware using the "sudo BRANCH=next dpi-update" command.

One error I believe I did was putting an ; in front of the resample-method = trivial line in /etc/pulse/daemon.conf , not sure about this though.

I struggeled a lot getting audio to play through the RPi, when I finally heard something it only lasted for about 20 seconds. I googled and found a fix at mrverralls blog:

add the following line at the end of /etc/pulse/client.conf :

extra-arguments = --exit-idle-time=-1 --log-target=syslog

Thank you for posting this instructable - I'm looking forward to install this setup in my 2004 Skoda Octavia :)

HaraldE HaraldE2 months ago

oh forgot url to mrverralls 20 sec timeout fix.
Thanks mrverrall

dantheman_213 (author) 1 year ago
Hmm I tested this extensively on the iPhone 4 and iPhone 5. Encountered 0 problems after countless connects/ disconnects. If you setup everything correctly, reboot your pi, and forget the device in your iPhone. Then wait to be seen again and connect. Should be okay! Remember to give it a second before disconnecting to reconnect.

hello, can you confirm me that your iphone is reconnection automaticaly without any intervention from your side? cand you please provide me the modifications for this to happen? i have managet to get the connection and sound, but no auto-reconnect after reboot. thanks.

Hi Dan, great job. I got everything working for Android, and I also tried with an old Samnsung phone with Windows mobile 5. The only problem is that iPhone is not connecting, it does not even show the Raspberry in the devices while discovering bluetooth. What could be wrong? I checked everyting many times and all looks fine. Thanks for your help.

PhilippeS12 months ago


I had the "20 seconds timeout issue". This page helped me out :

You just need to disable timeouts by adding a line in '/etc/pulse/client.conf'

extra-arguments = --exit-idle-time=-1 --log-target=syslog

citaine4 months ago


I followed the tutorial and worked well at first :D

then the sound stop and the only way to get the sound back is to use this command that I found on an other forum :

pactl load-module module-loopback source=1 sink=0

then the sound come back for 10 or 20 more sec and then stop.

If i use my command again, It will work for an other secs.

Could you help me with it ?



matty.kay citaine2 months ago

citaine, I was wondering if you ever figured out why this was happening. I am having the same issue.
I have output from my syslog pasted here:

Everything is up-to-date on this system:

kernel: Linux raspberrypi 3.12.22+ #691 PREEMPT Wed Jun 18 <snip>

bluez: 4.99-2
bluez-tools: 0.1.38+git662e-3
pulseaudio-module-bluetooth: 2.0-6.1
python-gobject: 3.2.2-2
python-gobject-2: 2.28.6-10

Hempy902 months ago

I had the problem that my phone would connect just fine, but no music coming through at all. I went through all steps in the manual below in addition to the steps of this tutorial and now it's working fine.
Using Raspberry Wheezy 20-06-2014 version in combination with an HTC One X (Android 4.2.2)

shirsch3 months ago

All worked seemingly well until i tried to pair my andoird tablet. It paired but would not play audio through the speaker, there also was no option to use as audio output as ther usually is with A2DP speakers. Any help would be much appreciated!

cyber73 months ago

Farley easy with older WHEEZY release!

I added the LCD repositories, anyone knows if there is a way to get the song-detail displayed? (What details can you get from pulseaudio?)


(aka Aubrey Kloppers:

Snorey26 months ago

Good Guide! i am having an issue though. I can pair my device to the pi, but have no option to connect once paired. Once paired i get a message saying: "Confirm passkey is ###### to pair to [my pis name]."

The 6 digit number is different each time (not sequential looks randomly generated).

Anyone seen this or any ideas?


Snorey2 Snorey26 months ago

now its working, not sure what i changed but just click ok and its connecting after pairing now.

Snorey2, I'm having the same issue. Did you do anything in particular to resolve it or did it just fix itself?

davidcom Snorey26 months ago

Hi Snorey2. Thanks for giving us an update. There have been quite a few comments that the instructions no longer work because of changes to the kernal, etc. Can you let us know if you made any changes to the instructions to get yours to work?

My raspberry pi arrives in a couple days and any feedback on how to do this successfully would be greatly appreciated!

fdragone4 months ago

hi all works perfectly, what about the siri audio? is possible to run the siri audio via bluetooth? emulating like the parrot bluetooth for cars?

thank you

steckums5 months ago

Any idea if it is possible to automatically pair to the last device (or one of x?) on boot? I'm using this for car audio, and would like my phone to automatically connect when it after it boots up.

bob_binz steckums5 months ago

A bit of a hack, and I'm sure there's better ways (I'm no scripter) but this "seems" to do the trick. I say seems because I haven't tested it with many devices.

In the bluetooth script, where it says:

mac=$(cat "$dev/name" | sed 's/:/_/g')

Add this, underneath:
cat "$dev/name" > /etc/btdevs

This will create a file containing the device ID when a device connects. Then, in /etc/rc.local, add this at the end (before exit 0):

if [ -f /etc/btdevs ]; then
btdev=`head -n 1 /etc/btdevs`
if [ "$btdev" ]; then
echo "connecting to device " "$btdev"
rfcomm release /dev/rfcomm0 > /dev/null&
rfcomm connect hci0 $btdev 3 > /dev/null&

The rfcomm release seems to be needed to allow a subsequent connection. Hopefully, when you reboot, it should connect to your device. It may be worth testing the rfcomm commands from the command line first though, to make sure it connects to your device.

jcaisse bob_binz5 months ago

Gave it a try on my Pi/Nexus 5 setup and no change. it all starts up but I still have to initiate the connection from my phone. I've searched high and low for a way to do this... seems to be dead-ends everywhere.

TEHumbert9 months ago

in the log file I'm not seeing the out of:

echo "Setting bluez_source to: $bluez_dev" >> /var/log/bluetooth_dev

I'm wondering what the command CONFIRM = 'sudo -u pi pactl list short | grep $bluez_dev#' does? what's up with the weird quotes around it? they're like half apostrophes...

Those "back tics" (`), on a US keyboard are left of the 1, under the ~. These tell the shell to execute what is inside and the result of that is stuffed into CONFIRM.

squirrelsnuts5 months ago

Great post! I am playing with this on Fedora (I know, I'll have to do some tweaking) and I didn't have the /etc/bluetooth directory, nor any of the files. Can you post the entire files as you have them?

jcaisse7 months ago

FWIW I bought a USB soundcard to get better sound (I'm installing this into a car to have a headless sound system powered by my phone) and then spent 2 nights trying to figure out why it would only play from the headphone jack... in the above scrips you'll see a line "AUDIOSINK="alsa_output.platform-bcm2835_AUD0.0.analog-stereo"" This forces it to the headphone jack. To output to your USB soundcard, run "pacmd list-sinks |grep name:" and insert: "AUDIOSINK="name-of-your-device"" Hope this helps someone else too...

TexyUK jcaisse5 months ago

Thankyou jcaisse - you solution worked for me with a pcm2704 based usb sound card. My usr/lib/udev/bluetooth files now looks like this :


echo "Executing bluetooth script...|$ACTION|" >> /var/log/bluetooth_dev

echo "Executing bluetooth script...|$ACTION|"

ACTION=$(expr "$ACTION" : "\([a-zA-Z]\+\).*")

if [ "$ACTION" = "add" ]


for dev in $(find /sys/devices/virtual/input/ -name input*)


if [ -f "$dev/name" ]


mac=$(cat "$dev/name" | sed 's/:/_/g')


sleep 1

CONFIRM=`sudo -u pi pactl list short | grep $bluez_dev`

if [ ! -z "$CONFIRM" ]


echo "Setting bluez_source to: $bluez_dev" >> /var/log/bluetooth_dev

echo pactl load-module module-loopback source=$bluez_dev sink=alsa_output.usb-Burr-Brown_from_TI_USB_Audio_DAC-00-DAC.analog-stereo rate=44100 adju$

sudo -u pi pactl load-module module-loopback source=$bluez_dev sink=alsa_output.usb-Burr-Brown_from_TI_USB_Audio_DAC-00-DAC.analog-stereo rate=4410$






Hi jcaisse, I am trying to make it work with usb speakers, I changed the AUDIOSINK name but still is not working. What else do you recommend doing?

kirichof5 months ago

Got the following error when updating rc.d!:

$ sudo update-rc.d bluetooth-agent defaults

update-rc.d: using dependency based boot sequencing

insserv: Service pulseaudio has to be enabled to start service bluetooth-agent

insserv: exiting now!

update-rc.d: error: insserv rejected the script header

1-40 of 157Next »