Introduction: Sensor Based Motion-triggered Music Player

At my undergraduate college, we've had to create an original project that all of the students were able to choose by themselves. For my project, since I always listen to music and I always feel like it's too much of a hassle to turn on a speaker I wanted to see how I could simplify that process, so I decided to create this Motion-triggered music player.



- MDF Wooden planks (between 0,5 and 2cm)

- 6 3,5x13mm Screws

- 10 Nails


- Raspberry Pi 3 model B+ with 2.5A Power Supply

- LCD Screen

- ADC MCP3008

- Raspberry PI T-cobbler

- Light-dependent resistor

- Temperature Sensor LM35

- Breakbeam IR sensor

- Speaker

- Breadboard


- Hammer

- Screwdriver

- Ducttape

Due to limitations in the Instructables editor I have added a build of materials the whole package will cost around €95 - €100


- 22 gauge wire - Yellow

- 22 gauge wire - Red

- 22 gauge wire - Black

Step 1: Get Your Electronics Going!

So we are going to plug our mcp3008, LDR, break-beam and temperature sensor into our breadboard. if possible follow my scheme above to have an idea where to plug what in or find a great place for your components yourself!

In short: try to make sure your LDR is free of cables and is able to take in as much light as possible and that all the components are on your board!

Step 2: Normalised Database!

For our normalised database I have added a picture to give you an idea how it looks like, read on to learn what each table does!


this table contains our three sensors: LDR, Temperature and break-beam

Sensor History:

This will allow us to check when a sensor was active and what the sensor had as value when a song has been played

Songs Played:

In this table, we will see all songs that have been played what sensor history is linked to it and what song was played.


In this table, we will combine our song location, song genre and song name


This table has our Song Name and Artist in it!

Song Locations:

Contains our song location on our pi /var/www/html/...

Music Genre:

Contains our music genre the min light for it the max light for it and the same for the temperature

Step 3: Code It!

I will leave a link to my Github repo down below but feel free to check my designs and read this first!

Raspberry setup:

turn on spi with sudo rasp-config => interfacing options => SPI => enable







Add database to MySQL on raspberry then,

My python code is where I add everything into the database and make my sensors work there is not a lot that you will be able to change to make it work easier I tried to create a python script that is clear and anyone is able to use it so feel free to try it out!

My site is just what I felt worked best for my project feel free to change it up a bit and to create an original site. even better if you are able to improve my design and make it more user-friendly!

I will add as well a link to view my wireframes as images. and a zip with all my files