Control MP3 Player with Wheel Touch Sensor
Table of Contents
Project Overview
In this project, we will build a Capacitive touch controller composed of a Wheel Touch Sensor and a Keyboard Touch, for our MP3 player module. We will be able to adjust the player’s volume using the Wheel Touch Sensor and select different music files using the Keyboard Touch.
Difficulty Level
Zio Padawan
Helpful Resources
For this project, we assume you have already configured Zuino M Uno to interface with Arduino IDE. If you haven't done so, we have a separate post on our development board guides. Check them out below:
Schematics
Setup & Configuration
You need the following modules and components to build this project.
- Zuino M Uno Development Board
- Zio Qwiic Capacitive Touch sensor AT42QT2120 &
- Zio Qwiic 0.91” OLED display
- Zio Qwiic Mp3 player module
- Qwiic cable
- Micro USB cable
Step 1 Daisy chain all the modules together
There is no particular order to connect the modules together. Because it uses qwiic connector system, connecting the modules in any order is possible. The above image is for example purposes only.
Note: The Capacitive Touch Sensor should be set up with the Keyboard Touch and Wheel Touch module connected together with a ribbon cable.
Step 2 Install required libraries
You need the following libraries to run the project code in your Arduino IDE:
- Adafruit GFX Library
- Adafruit SSD1306 Library
- Zio Qwiic Capacitive Touch Sensor Library
- Zio Qwiic MP3 Library
Step 3 Download code
Download the project code and upload it to your board.
Code
Open Arduino IDE Plug your Uno to a computer.
Download and Flash the code below to your Uno using the Arduino IDE.
Alternatively, you can download the full source code of the project from our Github page.
Code Explanation
The sketch code comes with two files. Wheel_touch_sensor.ino and Wheel_touch_control_mp3.ino. The file names are pretty much self-explanatory where the first file controls the keyboard touch and wheel touch sensors and the latter the MP3 player module.
In the code, we specified that keys number 3 to number 11 will play track according to the MP3 track number (that is the order that the file is saved in the SD card).
<Wheel_touch_sensor.ino> file
//display which key is pressed or not, 1 = pressed and 0 = not pressed
for(uint8_t i=3;i<12;i++) //from key 3 to key 12
{
Serial.print("Key");
Serial.print(i);
Serial.print(": " );
Serial.println(qtouch.isKeyPressed(i));
if(qtouch.isKeyPressed(i)==1){ //if a key is pressed, play the song corresponding to the key number
mp3ChangeVolume(volume);
mp3PlayTrack(i-2);
displaymag();
delay(1000);
}
}
Each key of the keyboard touch represents one of the songs inside the memory card, the first track will be key3, the second track the key4, and so on.
<Wheel_touch_control_mp3.ino> file
void mp3PlayTrack(byte trackNumber)
{
mp3Command(COMMAND_PLAY_TRACK, trackNumber); //Play track
}
For the volume control, the Wheel touch sensor will read the value of the part where it is touched by the user, and wait 100 ms before reading the value again (to confirm after this delay where does the user has moved his/her finger).
It will try to compare between 2 values (First and second) to detect Up or Down.
When first reading < second reading the wheel will detect this movement (clockwise) as UP. The opposite will happen (in anticlockwise movement) where the first reading > second reading.
<Wheel_touch_sensor.ino> file
digitalWrite(13,HIGH);
touchWheel.update(); //sliding on the wheel
uint8_t P=touchWheel.getSliderPosition(); //for getting the position of the finger on the wheel
Serial.println("TOUCHING...");
Serial.println("P");
Serial.println(P);
delay(100);
touchWheel.update();
uint8_t P2=touchWheel.getSliderPosition();
Serial.println("TOUCHING...");
Serial.println("P2");
Serial.println(P2);
if (P2>P){ //if we slide our finger to the clock side, volume up
volume++;
mp3ChangeVolume(volume);
displaymag();
}
else if (P2<P){ //if we side in the other side, volume down
volume--;
mp3ChangeVolume(volume);
displaymag();
}
delay(100);
}
digitalWrite(13,LOW);
Demo
How it works
As mentioned earlier, the keyboard touch controls the music file program of the MP3 player module. These music files are located on the external memory stored in the SD card. For this project demo, we stored 7 music files and each key is assigned to a music file from the MP3 player module.
The wheel touch sensor adjusts the volume of the MP3 player module. Sliding your finger clockwise will increase the volume of the MP3 player while sliding it anti-clockwise decreases the volume.
Got questions or suggestions? Or just want to greet us? Drop us a comment below!