In this project, we will use potentiometer to control the volume of  music player. As raspberry pi can not accept analog signal from potentiometer , we need to use ADC module to convert analog signal to digital signal before sending it to Raspberry Pi.

A/D converter pin graph:

raspberry_pi_mcp3008pin

MCP3008 datasheet:https://osoyoo.com/driver/MCP3008_datasheet.pdf

MCP3204 /MCP3208 datasheet:https://osoyoo.com/wp-content/uploads/2016/10/MCP3208_datasheet.pdf

Wiring diagram(MCP3208 or MCP3008):

pi_volume_knob_bb

Wiring diagram(MCP3204)

pi_volume_knob_bb

potentiometer pin graph:

diasnweiqi

Software installation:

1)Install python on Raspberry Pi by running following terminal commands:

sudo apt-get update
sudo apt-get install python-dev

update&python-dev

2) Install RPi.GPIO module by running following commands:

sudo apt-get install python-setuptools
sudo easy_install rpi.gpio

setup&&gpio

3)Install ALSA sound utilities and MP3 player by running following commands:

sudo apt-get install alsa-utils
sudo apt-get install mpg321

mpg321

4) Download python code for this project:

wget http://osoyoo.com/driver/raspi-adc-pot.py

chmod  777  raspi-adc-pot.py

chmod777

run the project:

1) Upload sound module:

sudo modprobe snd-bcm2835
sudo amixer cset numid=3 1

snddd

2)Download sample MP3 music files

wget http://osoyoo.com/driver/long_time_no_see.mp3

mpg321   long_time_no_see.mp3

longtimenosee___

3)Open another terminal window and run following command:

sudo  python   raspi-adc-pot.py

runn

connect your earphone to Raspberry Pi, change volume by adjusting potentiometer and enjoy your music.

DSC_6793