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 197Next »
gliuzzo3 days 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 :)

>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.

ehsmaes4 days ago

I am close to giving up (and I am not new to headless linux). Too much time spent. I have sort-of got it to work a couple of times but there is always something not working and in trying to fix it I loose my way and I am forced to start from a fresh memory card again.

I can get it to pair but the phone immediately disconnects and any consecutive attempts immediately disconnect. I think there is an incompatility between device classes. I get Class: 0x42041c from "bt-adapter -i".

Anyway, @danteman_213, based on all the comments I would say it is safe to say your instructable could use an update. Everybody seems to have a different opinion on what the magic solution is and it is not easy to piece it all together.

In the meanwhile - does anyone out there have a dropbox with a working SD-card-image? Please!

So I've done everything in the directions and my phone connects to the PI no problem but no audio streams. It shows that it is connected and connects right away with no problem besides the audio not playing. Anyone know what it could be? Could really use some help! Thanks!!!

tuxfamily16 days ago
nreyes15 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?"

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 nreyes119 days ago

how to solve it?

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

NathanH1121 days 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 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!

Cut my thought short. This is with the latest default raspbian image (not NOOBS) and with a full sudo apt-get update && sudo apt-get upgrade before starting.

can you please explain it in detail ?

JonF222 days ago

hello, I followed your tutorial and didn't seem to receive any errors and while I can pair both Android and my mac to the rpi, no audio plays- suggestions?

terryo11 month ago

I have not read through all of the comments, but does anyone have this outputting through hifiberry? Are there any modifications for this?

Thumb up for this. I also have a hifiberry and bluetooth installed.

How to change the output to the hifiberry soundcard ?

solved it. streaming from phone to hifiberry is possible





this was the right, after reading the sink source with command pactl list

gliuzzo28 days ago

It doesn't work with Bluetooth V 2?

DomR5 months 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?

I have this exact same issue, I just set it up. I've looked at the running processes to see if just maybe bluetooth or pulse or maybe it died? Nope, i see them running the entire time (mine plays between 15 and 20 seconds then dies)

Ah yeah, other people have found what i found below in the comments. It's because pulseaudio is going to idle after 20 seconds. So there is a bit of code posted below to prevent that.

Just in case anyone else gets stuck at the "PulseAudio Drops After 20 seconds", here's how I resolved it:

Edit daemon configuration:

sudo nano /etc/pulse/daemon.conf


; exit-idle-time 20


exit-idle-time -1

dtb062 months ago

Hi, it is working fine with sideeffekt's script. I'm using it in my car to play music with a Lumia 735, but I also use an USB sound card instead of the raspberry integrated port, which has also an input jack.

I was wondering : do you think it is possible to change the device class to be recognized as a music+voice device and use it with a microphone plugged in order to answer calls or use voice guidance or to send SMS with voice recognition ? Do I need someting else like an activation button ?

Thanks to everybody for their input (and sorry for my Englidh, I'm French).

cybrg dtb061 month ago


I also want to use a raspberry PI for my car. I have tried to rebuild several BT car kits but IMO the raspberry pi could solve my "problems" best.

So, also I want to know if you think, that it is possible to use a raspberry pi to use a microphone in my car.


RobertS231 month ago

The problems I had were solely to be blamed on Raspbmc distro I was trying to get this to work on. Setting this up on Raspian (on Pi 2) was a breeze :)


MateuszK32 months ago

Hi, everything works like a charm.

But I have a problem with pairing. I'm connecting my tablet(android), laptop(win7), phone(android) to Pi, but everything works As long as I connect for the first time. When devices are paired, and i reconnect to the PI then the script /usr/lib/udev/bluetooth doesn't start.

I checked syslog if there is an event for "ADD" when connecting my paired device to Pi but there is no such event going from KERNEL - so the line:

KERNEL=="input[0-9]*", RUN+=/usr/lib/udev/bluetooth from /etc/udev/rules.d/99-input.rules doesn't get triggered.

For the first time (connecting not-paired) the line in syslog which triggers script is:


Jan 26 19:00:39 raspberrypi kernel: [ 856.520658] input: XX:XX:XX:XX:XX:XX as /devices/virtual/input/input0

then i can see output in


Mon Jan 26 19:00:39 UTC 2015 : Executing bluetooth script...|add|
Mon Jan 26 19:00:41 UTC 2015 : Setting bluez_source to: bluez_source.XX_XX_XX_XX_XX_XX
pactl load-module module-loopback source=bluez_source.XX_XX_XX_XX_XX_XX sink=alsa_output.platform-bcm2835_AUD0.0.analog-stereo rate=44100 adjust_time=0

For the second time (paired)


Jan 26 19:01:05 raspberrypi bluetoothd[2008]: Discover: Connection timed out (110)

and nothing happens.

But i can ping the phone from PI (l2ping) so the connection is established?

To be honest constantly unpairing the devices is painful ;)

how can i improve this? i looked for the answers about 110 error but what I found is not relevant in my opinion.

any help?

guaycuru2 months ago

After a firmware upgrade (rpi-update) I stopped getting audio after connecting.
After some digging around, I found that I had to make this change on /usr/lib/udev/bluetooth :

Replace this line:


With this:


Hope this helps someone else!

guaycuru guaycuru2 months ago

Forgot to mention: great tutorial, thank you very much!

RobertS232 months ago

I can connect and my device is playing to Pi, but I have no sound.

When I check this I get:

$ pactl list sources short
Assertion 'l' failed at pulsecore/flist.c:168, function pa_flist_pop(). Aborting.
Ollilie2 months ago

Its working great but i have a question. Whats about the sound if i get a call?

The voice comes out of the phone and for me its interesting to hear it out of the 3,5mm jack of the Pi because it will be mountet in my car and i like to talk free hands. Have anyone an idea?

regrats from Germany

please excuse my English

Robert__S2 months ago

The bluetooth script at (what should be) /lib/udev/bluetooth executes when a USB dongle is inserted or removed - which is not the desired action. I suggest adding the following near the top of the script - so that the script only executes if a bluetooth device links with the Raspberry Pi:

DEVTYPE=$(expr "$DEVTYPE" : "\([a-zA-Z]\+\).*")
[ "$DEVTYPE" != "link" ] && { echo "DEVTYPE is $DEVTYPE - exiting" | logger; exit; }

One small issue I am having is that I have lost a lot of bass to what I would normally have (streaming from Spotify to BT as compared to having headphones in). Do you know if this is something I can address or is this just the nature of Bluetooth or the Pi?

This worked great! The only issue I had was the volume being very low. I found a link which mentions running this command

pacmd set-sink-volume 0 65537

Cool stuff :) On to an FM transmitter now!

ThrRokstar3 months ago
How would you get this to work with the model b+?
sobodash3 months ago

Made this and it's working great except for one problem. I have a Macbook Pro that recognizes the Pi as an audio devices, connects fine and switches to Bluetooth audio.

However, the Mac's audio does not appear to actually be streaming to the Pi. There is simply no sound at all. I tried toggling back and forth between the internal speakers and the Bluetooth Pi, but there was no real change.

Anyone have an ideas about what might be going on? I'm running Yosemite if it's relevant.

Oktavius sobodash3 months ago

Hi, i have the same problem. Pairing with Iphone works very well. Connecting and pairing with my Macbook works but I can´t hear any music I play. Is there a solution to overcome this problem?

AndreaB33 months ago

Hi, many thanks for this tutorial.
I tried it on raspian wheezy 9/9/2014 (fresh install) and I'm stuck. My phone (android 4.2.2) shows the Pi as paired and connected to media audio, but I can't actually ear any output.
I looked around the internet and to try the connection I run

sudo l2ping <address>
but the raspberry said

Cannot connect: invalid exchange
I read all the comments here and didn't find a possible workaround.

Did someone manage to get this work with a recente realese of wheezy?

schmo901 year ago
after weeks of madness and no succes i got it finally working but with a complette different start script because the even kernel event did not work for me.

at first i decommended in the
sudo nano /etc/bluetooth/audio.conf

after that i made a script

sudo nano /

to get my bluetooth device mac adress

while [ 1 -lt 10 ]; do
  source=$(pactl list short sources |  grep -o "bluez.source.\(.*\)module" | sed 's/'\module'/''/g' |  sed 's/[ \t]*$//')
    if [ "$source" ]; then
      if [ $running -eq 1 ]; then
        sudo -u pi pactl load-module module-loopback source=$source sink=alsa_output.platform-bcm2835_AUD0.0.analog-stereo
     sudo hciconfig hci0 piscan
  sleep 5


sudo nano /etc/init.d/EnableBTMusic

#! /bin/sh
# /etc/init.d/blah

# Alles, was in jedem Fall ausgeführt werden soll, steht am Anfang
touch /var/lock/somefile.lock

# Bestimmte Funktionen werden per switch-case Anweisung geregelt
case "$1" in
    echo "Starte Beispielprogramm "
  sudo -u pi sh / &
    echo "Stoppe Beispielprogramm"
    # ./ --stop
    echo "Usage: /etc/init.d/ {start|stop}"
    exit 1

exit 0

 sudo chmod 755 /etc/init.d/EnableBTMusic
sudo update-rc.d EnableBTMusic defaults

with this changes i can hear music on my raspberry :-)
i hope i could help someone with that infos...
AndreaB3 schmo903 months ago

Hi, thanks for posting this.
I have the same issue you had, so, my phone says the devices are paired but no sound is actualli reaching the 3.5 mm jack.
I'm trying to get it to work using a 9/9/2014 wheezy, but I read in the comments that many people suggest to use a older kernel. Did your script work with a recent realese of raspian? I so I'll give it a try.

rpotee schmo901 year ago
For some reason, I need to ssh into my RPi to get this solution to work. Any work arounds? I have all of the configuration detailed for this project, plus your solution.
derekkg rpotee1 year ago
Me too! If I have Ethernet plugged into my pi, it works. If I don't, I can't connect. Did you ever figure out what the problem was?
1-40 of 197Next »