Open Source Swiping-card Music Player

From Microduino Wiki
Jump to: navigation, search


  • Project:Microduino open source code card music player
  • Objective:To read songs in SD card to play, and change the music by swiping card.
  • Difficulty:Medium
  • Time-consuming:2 hours
  • Maker:
  • Introduction:

PORTABLE SPEAKER is always about speaker that is based on speaker which can support or read memory processors such as SD and TF in the market, and add the function that change song by swiping card. Compared with traditional computer speaker, the unique decoding function of the swiping-card speaker makes it more favored by consumers, and just because of this, it is named as the king decoding audio empire.

Bill of Material

  • Microduino Equipments
Module Number Function
Microduino-Core+ 1 Core card
Microduino-USBTTL 1 Programs dowenload
Microduino-Audio(with shield) 1 Decode and store music files
Microduino-Amplifier 1 Attack release
Microduino-OLED 1 Display
Microduino-Cube-S1 1 Extended board OLED interface
  • Other Equipments
Module number Function
OLED connecting line 1 Connection
Micro-USB cable 1 Programs download and power supply
Horn 1 Audio play
MicroSD card(optional) 1 Store the music file
Nylon screw&nut 1 Fixation
Wooden case 1 The appearance and fixation

Principle of the Experiment

Microduino-Audio board can decode and store music files. Connect Microduino-Audio&shield and the horn to realize music thumbwheel and mass storage. Connecting Microduino-Cube-S1 and Microduino-OLED can visually see volume and tracks on the OLED in tooltip way. Then jointing Microduino-USBTTL, Microduino-Core+ and other modules disorderly can realize the card speaker function. The shell of the speaker adopts wooden case, or you can also DIY your own exclusive shell.

  • Main Sensor



The code of the swiping-card music player:[The code of the PORTABLE SPEAKER] Github:[Github地址]

Commissioning Process

Stack Microduino-Core+ and Microduino-USBTTL together. Upload completed programs to Microduino-Core+ through Microduino-USBTTL with USB cable. Note: Please upload programs before stacking all modules together.

Open the Arduino IDEprogramming software, click [FILE]->[Open], and choose Microduino_Audio_ble\ Microduino_Audio_ble.ino after opening PORTABLE SPEARKER document. Click"√", and program. Click [tool], and choose the right board + processor + port. Click"→", and upload.

  • Store music through Flash(The capacity is very small).

Connect the Audio module to the computer. If successfully identified, CD driver will appear in “MY COMPUTER”, and open the CD driver. Note:If not identified successfully, please check whether the cable and the module are stuck tightly. If it can’t be identified after you have checked them stuck tightly, you shoule try another USB interface. When they are connected successfully, there will show a CD driver named as Microduino-Audio, then you should do as the following steps:


After opening the driver, you should choose to open MusicDownload.exe as the administrator.(Note:win10system user need to right-click to open MusicDownload.exe and select properties, and set up to run Windows 7 compatibility.)


After opening, choose“Audio load”


Click “Browse” and select all the songs, then click “Open”(Songs are in Case1-4.mp3). Note:Music files in Flash cannot surpass 4M, so there is only Music Num on the screen:Num1-4 have songs, but Num5-9 are the last songs. If you want to increase the songs, you can use the first method to store music into the MicroSD card.


After open, click on the return to “Download updates”, and click “Update”. It will update for a long time, please be patient.


When the “Check successfully” appear, you have copy music successfully. Note:Close the window after checked successfully. Don’t click update, or you’ll need to update again.

  • Use TF cad to store music.(The capacity is change with the size of TF card.)

Connect Audio&Shield module to the compute trough USB cable, and at this point it will identify CD drive and a removable disk. You should double-click on the removable disk.


Click the right mouse button to create a new folder, and name it as 01 (If more are needed, you can continue to name 02, 03. The rest can be done in the same manner.)


Then store the music in the folder 01.



As shown in the picture, please click to view a larger image and do as the corresponding steps to assemble.

  • Step1: Firstly fixA1 and OLED screen with screws and nuts, then insert the sensor cable into the interface on the back of the OLED.
  • Step2: Insert D1 and C2 into the interface in B1 respectively.
  • Step3: Embed audio into position as shown in the picture, then assemble A1 and B1 together with D3.
  • Step4: Embed audio into position as shown in the picture, then assemble A1 and B1together with D3 and D2.
  • Step5: Combine C1, A1 and B1, and overlay Core,USBTTL,Audio&Shield,Amplifier, and Audio together, then insert them in the baseboard, then fix with D4.
  • Step6: Insert the sensor line and the audio line to the corresponding position of the module, and then use the USB line to connect with the USBTTL module.

Now this music box has been completed.

Swiping Card to Use

Use a black Mark's pen to draw black and white stripes on different edges on a blank sheet of paper.


Then swipe the stripes from the swipe card position to play music. Different stripe number plays different music.

Matters Needing Attention

1. In the event of:The volume can only be increased and can’t be reduced, the number of the song can only be increased and can’t be reduced, or on the contrary. Cause:The threshold setting is not reasonable in uiStep().

Thumbwheel Action A6measuresd voltage(V) Corresponding Code(Voltage/5*1023) Threshold setting
Default 3.3 675.18 >600
Downward 0 0 0~50
Toward the left 1.6 327.36 150~400
Towards the right 2.6 531.96 450~600

Change the threshold setting in uiSetup

Program Description

Part of the main program

boolean vokey(boolean _vokey)
  key=analogRead(PIN_key)<paper_val_MIN;	//When the trigger

  case 0:
    if(!key && key_cache)		//After the press release
      key_cache=key;		//The cache for judgment
      return true;
      key_cache=key;		//The cache for judgment
      return false;
  case 1:
    if(key && !key_cache)		//After the press release
      key_cache=key;		//The cache for judgement
      return true;
      key_cache=key;		//The cache for judgment
      return false;

void loop() 
  if(vokey(0))		//When the trigger
    colorWipe(strip.Color(255, 255, 0), 10);
    paper_num++;	//Count
    // Serial.print("+");

    paper_sta=true;	//Read mode 


  if(millis()-time1>1000 && paper_num!=0)	//Trigger, and idle for more than one second it will end.
     AUDIO.choose(paper_num);	//Play songs scanned.
    paper_num=0;		//Return to zero, and wait for next scan.

    paper_sta=false;	//End of the read mode

  if(!paper_sta)		//Not the read mode, LED to breathe.


    colorWipe(strip.Color(LED_vol, 0, 0), 10);		//Breathing lamp displays brightness.


// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);;