Home automation is an area many are interested in. There are several home automation solutions available in market but we have a habbit of doing it ourselves. In this tutorial we shall see how we could make Raspberry Pi start a music player when we enter the room. To make this possible we need to make the Pi interact with the environment using sensors and control the music player.
Raspberry Pi is an ARM-based computer that is widely used in DIY and engineering projects. It is a single board computer that has its processing, memory and I/O units integrated in a single circuit board. If you are unfamiliar with Raspberry Pi you may go through the tutorial below first and then come back.
IR Break Beam Sensor
IR break beam sensor is an infrared sensor that detects the entry of a person into a room when he breaks a beam of infrared rays emitted by its transmitter. The transmitter and the receiver are to be placed facing each other at the desired location. When powered on the transmitter emits a beam of IR rays which is received by the receiver. As soon as someone enters the room the beam is broken and the entry is detected.
The project requires the following materials :-
- Raspberry Pi
- IR Break Beam Sensor
- 10 kΩ, 1 kΩ resistors
- Speakers with standard headphone jack
- PCB Board and Connectors
Steps to create a motion triggered music player using RPi
Step 1 : – Testing music player
To play an audio file we need a music player. If you have successfully installed Raspbian as given in the tutorial you need not install any new software. Raspbian includes a package called omxplayer by default which is a command line music player built specifically for Raspberry Pi. If you are using a different distro install omxplayer or find a similar package from its repository.
To start testing connect your speakers to the audio jack and load a music file to your Pi’s SD card. Open terminal and change the directory to the one containing the music file.
Command :- cd /path/of/folder
Now, invoke omxplayer to play the file.
Command :- omxplayer filename.extension
Step 2 :- Interfacing the break beam sensor
You need to interface the break beam sensor to the Raspberry Pi to detect your entry into the room. For this purpose we shall make use of the GPIO pins of the Pi. It is a good practice to test the circuit on breadboard and then build it on the PCB. The circuit diagram is given below. In the circuit diagram you can see that VCC and GND pins of IR transmitter and receiver are connected to the respective pins of the Raspberry Pi. If you are new into building circuits make sure you do not make any mistakes here. Connecting them wrongly can damage your devices. The third pin of the receiver is the output pin connected to a GPIO pin of Raspberry Pi.
For more detail: Motion triggered music player using Raspberry Pi