Introduction: Bluetooth Speakers Using Raspberry Pi

Picture of Bluetooth Speakers Using Raspberry Pi

hi guys long time since i wrote a tutorial, this tutorial tells you how you can use any old speaker lying around your house into a wireless bluetooth speaker, this can also be an cheap bluetooth audio device receiver for your car. This is not my original work, but modified(added a few steps/changed a few) tutorial from http://kmonkey711.blogspot.com who has also taken help from Colin CW, i am reproducing this tutorial because this is the only tutorial that worked for me and i don't want it to disappear from the World Wide Web when i really need it. thanks Kmonkey for this awesome tutorial. Another way to have an wireless speaker is using AIRPLAY here

Step 1: What You Need?

1 Raspberry pi (i am running Occidentalis_v02.img from adafruit)
1 speaker
1 Male-to-male 3.5 mm audio jack
1 bluetooth dongle ( check here for list of devices that work ) do check using the command hcitool scan
1 ethernet connection for pi/ wifi (how to connect a wifi dongle to Raspberry pi) (all u need to do is edit "/etc/network/interfaces" file)

Step 2: Installing the Softwares...

you need to install a couples of things before you can get started :-)

sudo apt-get update

sudo apt-get install bluez pulseaudio-module-bluetooth python-gobject python-gobject-2 bluetooth blueman

sudo usermod -a -G lp pi

sudo nano /etc/bluetooth/audio.conf

add the following after [general] in nano 

Enable=Source,Sink,Media,Socket

CTRL+X to close nano, Y to save the file

sudo nano /etc/pulse/daemon.conf

add the following line under ;resample-method = speex-float-3

resample-method = trivial

run the following command to reboot the PI

sudo reboot

if you have a monitor connected to your PI you can skip this next step 

Step 3: Installing the VNC Server

if you have a monitor connected to your PI you can skip this step, if you use SSH like me the following steps will install a VNC server on the PI, so that you can go into the LXD desktop.

apt-get install tightvncserver

Setup vnc password by the following command

tightvncserver

reboot the pi

sudo reboot

run the following command to create a desktop you can connect to.

vncserver :0 -geometry 1920x1080 -depth 24 


Step 4: Connect to PI Dektop

Picture of Connect to PI Dektop

(for VNC users)
once the PI is restarted and VNC server running you need to pair your device.

connect to the VNCserver using VNC viewer that can be download from here

c
onnect the vnc server with <<you PI's IP address>>:0  eg: 192.168.2.8:0

enter your password


(if you have a monitor hooked up start from here)

now you should be able to see your desktop, on the bottom right corner near the time display you should be able to see a bluetooth icon, right-click on it and select devices. you should now see an empty list if nothing has been added.

click on the search button to find new devices.

new devices should show up in the table below.

right-click on the device and click on pair to pair the devices

enter a pin and pair them

once paired right click on the paired device and mark them as "trust" this ll make this device trusted.once the device is in the trusted list a golden star will be visible on the device.

now you can close your vnc server ( not needed if you have your monitor hooked up) and run vncserver -kill :0 on the SSH


Step 5: Connect the Bluetooth to Alsa Audio

run the following comands as user "pi" not sudo

amixer cset numid=3 1

find out the name of your source and and sink using the following comands

pactl list sources short

pactl list sink short

and run the following command

pactl load-module module-loopback source="name of your source" sink="name of your sink"

my command looks like this...

pactl load-module module-loopback source=bluez_source.50_EA_D6_DE_D9_39 sink=alsa_output.platform-bcm2835_AUD0.0.analog-stereo



Step 6: Play Your Song...

Picture of Play Your Song...

now connect you phone/ipod to the Bluetooth device and start playing songs... do hookup your speakers using the 3.5 mm jack..like duh...

note:
if your volume is too less run the following commands

amixer set Master 100%

pacmd set-sink-volume 0 65537

Comments

MichaelA91 (author)2016-04-15

In the file audio.conf its blank so I hope I am right about adding the line

sudo nano /etc/bluetooth/audio.conf add the following after [general] in nano

Enable=Source,Sink,Media,Socket

No file named
daemon.conf in the /etc/pulse/

so I cant add to a file that isn't there.

Mohamed-KhadarJ (author)2015-12-17

Asc

hello i have a problem when i install bluez and bluetooth i cant find the audio.conf file so please can any one help i am willing to complete this project as soon as i get answer

thankx

BobiC (author)2015-04-30

I did all of the steps everything is ok (i share the music the PI is receiving the music) but when i put ''pactl list sinks short'' there is nothing there :( so i can't listen to my music

Can someone tell me why i cant see nothing after ''pactl list sinks short'' ? ? ?

BobiC (author)2015-04-30

Giancarlo Zanuz made it! (author)2015-03-27

Thanks, it worked fine. To connect your device using SSH:

install bluez-tools, a usefull package to use with bluetooth:

$ sudo apt-get install bluez-tools

Scan devices with:

$ hcitool scan

and take note the mac andress, something like XX:XX:XX:XX:XX:XX

Connect with your phone:

$ bt-device -c XX:XX:XX:XX:XX:XX

Choose a 4 number PIN, like 0000

Your phone will ask you to put this same PIN, do it.

Set your device to Trusted:

$ bt-device --set XX:XX:XX:XX:XX:XX Trusted 1

That's it, now you can continue with step 5.

PS: there's a little typo in step 5, in

$ pactl list sink short

it's really

$ pactl list sinks short

That's it, you can continue with step 5

LuceyA (author)2014-12-04

Bluetooth speakers are fine but I would suggest its better to look for other alternatives before landing up on something. e.g. airplay or wifi speakers check out the differences between the two of them


http://audioindustryupdates.weebly.com/blog/which-one-to-choose-airplay-or-bluetooth-wireless-speakers
Nelice (author)2014-07-24

A very useful DIY tutorial. Most especially when you have all of these parts hanging around your house.

dmüller10 (author)2013-06-02

I just added a USB-soundcard to the Pi.

with some changes in the sudo nano /etc/modprobe.d/alsa-base.conf and amixer cset numid=1 0 I can play songs which are at the pi, but bluetooth streaming doesn't work anymore.

What should I change, that the bluetooth streaming will work again?

thank you :)

dantheman_213 (author)2013-05-12

Hey guys! I used the work here to build a much better version of a portable A2DP bluetooth receiver then what's provided here. Check out my guide!

https://www.instructables.com/id/Turn-your-Raspberry-Pi-into-a-Portable-Bluetooth-A/

critak (author)2013-02-17

After my smartphone is connected to the Pi i ALWAYS have to enter
pactl load-module module-loopback source=bluez_source.10_10_FF_2B_2B_2E sink=alsaput.platform-bcm2835_AUD0.0.analog-stereo

Is there a way to automate that ? And let it also work after a reboot ?!?

sajingeo (author)critak2013-02-17

you could write a python script that would search for your device an connect it, i was trying to write one... i have attached the link to the code on git hub, if you could mod it ... u have to add

su -c "python /home/pi/Desktop/bluez/script.py" pi

in you /etc/rc.local file and..
comment /etc/inittab(sudo nano /etc/inittab)

#1:2345:respawn:/sbin/getty 115200 tty1
like this

#1:2345:respawn:/sbin/getty 115200 tty1
and add this below
1:2345:respawn:/bin/login -f pi tty1 /dev/tty1 2>&1

this would automatically startup bluetooth, search for your device for 3 seconds, if found it would link it to the ALSA audio else it would exit, u have to modify the code to work with your phone/device bluetooth MAC address. I am still working on the code, feel free to use the idea and make it work better.

https://github.com/sajingeo/bluez

About This Instructable

183,204views

157favorites

License:

Bio: DIY, electronics...and loves getting creative...
More by sajingeo:Amazon Echo starts your carReal World MinecraftBluetooth Speakers using Raspberry Pi
Add instructable to: