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:

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
1-40 of 231Next »
Score83 months ago

Don't Work for Me ! My Phone can connect, but no sound.

Any Solutions ?

ŽanK Score83 months ago

this wirks for me, but i need to run it manually everytime i power up RPi

try this, but you need to type this in everytime you turn off RPi, i am still looking for solution


pactl list sources short

(you should get)

0 alsa_output.platform-bcm2835_AUD0.0.analog-stereo.monitor module-alsa-card.c s16le 2ch 44100Hz SUSPENDED

1 bluez_source.B8_C6_8E_52_E8_CA module-bluetooth-device.c s16le 2ch 44100Hz SUSPENDED

than type

pactl list sinks short

(you should get)

0 alsa_output.platform-bcm2835_AUD0.0.analog-stereo module-alsa-card.c s16le 2ch 44100Hz SUSPENDED

type (replace your own bluez_source and alsa_output)

pactl load-module module-loopback source=bluez_source.B8_C6_8E_52_E8_CAsink=alsa_output.platform-bcm2835_AUD0.0.analog-stereo

TomC46 ŽanK7 days ago

Thanks, this worked for me, you are right, I need to run it every single time I reconnect the BT:

pi@raspberrypi ~ $ pactl list sources short

0 alsa_output.0.analog-stereo.monitor module-alsa-card.c s16le 2ch 44100Hz SUSPENDED

1 bluez_source.B8_E8_56_BA_48_2D module-bluetooth-device.c s16le 2ch 44100Hz SUSPENDED

TomC46 TomC465 days ago

I forgot this part:

pi@raspberrypi ~ $ pactl load-module module-loopback source=bluez_source.B8_E8_56_BA_48_2D sink=alsa_output.0.analog-stereo

RodolfoF Score83 months ago

I'm having the same exact problem.

Did you Ty pushing audio out the 3.5mm jack in raspi-confit?

Yes, and i See My phone into capture device, i think Pulse don't work with new versions, or the script don't work

hottroc2 months ago

Hi, this instructable is very well done and just what I wanted. However I have a problem....

I followed the instructions and my phone connects with my Pi via the Bluetooth. However the only sound I hear if I play any music is a buzzing. I have my Pi line out plugged into the Line in of my stereo amp. Is that correct? Other options would be CD, Phono or Tape.

Any idea why I just get buzzing?


Any suggestions anyone?

WilliamO9 made it!9 days ago

Excellent tutorial! Really easy to follow to completion in ~15 minutes. Works fantastic. One minor thing I will say is that the audio lags by about .5 seconds, so maybe not perfect if you're watching a video (this is probably a limitation of the pi itself) But for audio alone, it works exactly the way I hoped it would!

nreyes110 months 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?"

change class as 0x4e041C in /var/lib/bluetooth ,and it's work!
ThomasB18 nreyes16 months ago

Hi all, the same for me... I think this file is generated at boot.

When editing /etc/bluetooth/main.conf, I set the device's Class parameter by 'Class = 0x20041C' instead of 'Class 0x20041C' regarding the classic syntax for all parameters of the file.

just chmod to 444. fixes the problem.

DhoniG nreyes15 months ago

how to solve it?

i get this issue too, i'm so frustated..

GarethH516 days ago

Thank you very much for a very useful guide.

I got this up and running on my Pi 2. The only changes I made to the guide above were items 2 and 3 from gliuzzo's comment below and I skipped step 7 above, autologin. (I think gliuzzo's third tweak possibly takes care of this issue?)

Although it seems to be working nicely through the analogue output, I'd like it to work through HDMI, and I can't for the life of me work out how. I've tried commenting out the amixer line in /usr/lib/udev/bluetooth, without success. I'm assuming that the AUDIOSINK line of that file needs to be changed too, but to what? Can anyone help.

Many thanks in advance for any help.

Ah-hah. Changing the last number in the (first) amixer line from a 1 to a 2 did the trick!

There's a delay of maybe about 1.5 seconds. I was optimistically hoping to use it for audio output on Skype, so that might be just a little bit too long for it to be bearable (oh well!). Other than that, though, it seems to work a treat.

Thanks again,


JonathanV41 month ago

Great guide, i only have one problem,
when connecting with my android phone it connects without any problem and i can stream audio, but when connecting with my macbook air it connects on the macbook but not in the /var/log/bluetooth file. This has the result of not being able to stream audio from my macbook air.

JimT141 month ago

This is a great guide, Dan. I had to make some changes to how pulse connects, but I don't think I would have made it through the process without this guide, which covers all the steps to automate the bluetooth connection.
Sincere thanks - I salute you!
The symptom/problem I had was that bluetooth audio would stream for a few seconds and then the pulseaudio daemon would quit.

Just in case it helps anyone, this is how I got pulse to stream from bluetooth with the current version of Raspbian, which, as of this writing is:
Linux raspberrypi 3.18.11-v7+ #781 SMP PREEMPT Tue Apr 21 18:07:59 BST 2015 armv7l GNU/Linux

nohup pulseaudio --disallow-exit --disallow-module-loading=0 --high-priority --load="module-loopback source=bluez_source.XX_XX_XX_XX_XX_XX sink=0 " 1>>/var/log/bluetooth_dev 2>>/var/log/bluetooth_dev &

I hope this helps somebody.

RobM131 month ago

Running this on the rpi2 i had to make the changes gliuzzo did below, and also added a sleep to the bluetooth-agent script, since it needed a delay before running.

RobM13 RobM131 month ago

also, changed Master to PCM in the bluetooth script to adjust volume properly.

If you're using the crappy analog audio output, you might want to also add the following line to /boot/config.txt:


I'm actually using a USB audio output since its worlds better.


Slapshot1352 months ago

I've been stuck on the 'sudo usermod -a -G Ip pi'

whenever i put it in, i get this:

usermod: group 'Ip' does not exist

Ive tried all the suggestions in the comments so far but nothing works. Does anybody know why its not working?

I actually figured this one out, instead of 'sudo usermod -a -G Ip pi'

I used 'sudo adduser pi bluetooth'

Slapshot1352 months ago

So I finally got it working... Sort of.

The Raspberry Pi comes up, I can connect, But it still plays through my ipod and not the Raspberry pi

How do I fix this?

gliuzzo5 months ago

Hi guys! I Made it!

It works nice, but I had some problems. These:

sudo usermod –a –G lp pi doesn't found

when I copied and pasted it didn't work. terminal didn't found it! then I manually wrote it exactly same and then worked perfectly. I don't know why

output audio doesn't work

in this file: /usr/lib/udev/bluetooth :

Replace this line:


With this:


output audio after 20 seconds stopped

Edit daemon configuration:

sudo nano /etc/pulse/daemon.conf


; exit-idle-time 20


exit-idle-time -1

bluetooth devices doesn't connect

this is a proble about auto-login in tty1; I resolved this re-writing the /etc/inittab file like this, from:

#1:2345:respawn:/sbin/getty 38400 tty1
1:2345:respawn:/bin/login -f pi tty1 /dev/tty1 2>&1
2:23:respawn:/sbin/getty 38400 tty2
3:23:respawn:/sbin/getty 38400 tty3

4:23:respawn:/sbin/getty 38400 tty4

5:23:respawn:/sbin/getty 38400 tty5

6:23:respawn:/sbin/getty 38400 tty6


1:2345:respawn:/sbin/getty 38400 tty6
2:23:respawn:/sbin/getty 38400 tty2
3:23:respawn:/sbin/getty 38400 tty3
4:23:respawn:/sbin/getty 38400 tty4
5:23:respawn:/sbin/getty 38400 tty5
#6:23:respawn:/sbin/getty 38400 tty6
6:23:respawn:/bin/login -f pi tty1 /dev/tty1 2>&1

Enjoy!! Thanks @dantheman_213

Finally, this is my 5+1 Hi-Fi with bluetooth receiver :)

I'll upload a video tomorrow :)

Lars BoR gliuzzo2 months ago

goddammit i really regret not reading comments had to debug the hell out of it and came to the same solution. could have saved alot of time. but thank you for posting so i dont have to ;P

ironsand gliuzzo5 months ago

>1° sudo usermod –a –G lp pi doesn't found

Ya, I have a same error and found the cause of it.

`–` are not same with `-`!

Maybe the character are replaced by instructables's system.

wapenv3 months ago

Does anybody knows of this also works with the raspberry pi model 2B? I had it working a few times, but with a older raspbian image. I want to use the version of 5/5/2015. Thanks

GraemeY13 months ago

Worked great for me after changing the sink as other users have mentioned.

The one thing I changed to avoid having to enter pins was the following line in the bluetooth-agent

sudo hciconfig hci0 sspmode 0

GraemeY1 GraemeY13 months ago

There was also a crazy long delay (about 30 seconds) which was fixed by following https://wiki.archlinux.org/index.php/PulseAudio/Troubleshooting#Bluetooth_headset_replay_problems

mike967713 months ago

Hi, finally got this to work.

But what about Navi-Commands: next left ... next right. Is this possible too ?

RobertS233 months ago

If you're looking for a instructable for Raspberry Pi on Debian Jessie/SystemD (e.g. OSMC), maybe you'll find this one useful: http://www.instructables.com/id/Enhance-your-Raspberry-Pi-media-center-with-Blueto/

JonH74 months ago

Thanks for a nice guide and the helpful comments below to tweak it. I just got it working with latest Raspberian. I understood from @NathanH11's comments that the reason I got no sound was related to pulse and access rights. Instead of switching to system mode I set the DISPLAY environment variable for the commands that run pulse commands as pi, changing:

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


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


sudo -u pi pactl load-module module-loopback source=$bluez_dev


sudo -u pi DISPLAY=:0 pactl load-module module-loopback source=$bluez_dev

...that might be helpful for more people.

gliuzzo made it!4 months ago

5.1 hi-fi bluetooth :)

BlahBlahBlase4 months ago
I managed to fix the audio not playing problem by forcing audio out of the 3.5mm jack in raspi-config. sudo raspi-config > advanced > Audio > force 3.5mm.
This was after following gliuzzo's fixes
and running the chmod 444 that groovechampion1 suggested
sorry for all the additional replies, I drank a couple victory beers before I thought to share how I figured it out.

I also had a problem with it being too quiet, I fixed this by running "amixer cset numid=3 100%"
NathanH115 months ago

After playing with this for 2 days I just got this working on the latest. I had to make some pretty substantial changes... I'll list them out here, but I'm working from memory; they should give you enough pointers to self-solve:

1) The biggest problem is that pulseaudio will not work unless it's in system mode. Otherwise you'll always see it fail when it tries to access dbus. The problem stems from it not working in user mode unless you're running X11 and in an X session. I tried everything I could think of, but couldn't get a user daemon of pulseaudio to successfully access the system dbus. My guess is that this is the difference between a pristine minimal raspbian image and a Noobs image with all the trimmings.

The fix: run pulseaudio as a system service. To do that, you'll need to edit the /etc/default/pulseaudio config file, and the /etc/pulseaudio/ config files (plural). They should all match and declare themselves as system config; the pulseaudio page has info about the various settings and the precedence: it's a mess. You'll also need to add the bluetooth module to the puleaudio system.pa config, and there are some other modules that try to load and fail without X11, which need to be masked. You'll figure it out sequentially by tailing /var/log/syslog; the only one that seems to not be an actual problem is that the HFP endpoint in bluez isn't being set up: I chased that error but ultimately got everything working with it still there; (it will be there if you precisely follow the guide above and it's a red herring). You'll then need to go through the steps of giving user permissions to the pulse user and the pi user. Once that's done, you need to go setup dbus to allow bluez to contact pulse and vice versa. Pulse needs to be in the 'lp' group among other things.

2) The name of the pulseaudio alsa sink has changed. That's easy. You can fix with a little one-liner script to automatically pull the endpoint name when loading the loopback module, or since it's not likely to change, just 'pactl list sinks short' and hard-code it.

3) If you happen to pair the bluetooth device in the wrong order/with the wrong profile, you'll get a bunch of random config in /var/lib/bluetooth/<mac>/. Delete those files and fix the config file. Note: if you use a comment or mis-format the config file, the BT drivers will overwrite your settings. The file must be clean. If you fubar the setup, delete the whole directory and the next time the device loads it'll be clean.

Best of luck everyone!

Finally got things working with this helpful insight from NathanH11!

I ended up following this guide:


to use PulseAudio system wide and start the Bluetooth daemon. I was able to finally get sound to come out of the on-board audio and eventually through all 5.1 channels on a USB sound card (frustrating). I did however slightly tweak the script posted by sideeffekt to replace "bluez-udev" mentioned in the guide. This script is a little more "hard-coded" since I am using a USB sound card.


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


echo BSINK=0

BSOURCE=$(pactl list sources short| grep bluez_source | awk '{print $2;}')

echo BSOURCE=$(pactl list sources short| grep bluez_source | awk '{print $2;}')

pactl load-modulemodule-loopback source="$BSOURCE" sink="$BSINK"

echo pactl load-modulemodule-loopback source="$BSOURCE" sink="$BSINK"

# Turn on bluetooth discovery on disconnect

if["$ACTION"="remove" ]


handle=$(pactl load-modulemodule-loopback source=bluez_source."$mac" sink=0)

for handle in $(pactl list short modules | grep module-loopback | grep source="$BSOURCE"| cut -f 1);do

pactl unload-module"$handle"

echo pactl unload-module"$handle"


sudo hciconfig hci0 piscan


1-40 of 231Next »