Music Box Three—Infrared Control

From Microduino Wiki
Jump to: navigation, search
Language: English  • 中文


Build a music box here! You can play music files in the TF card and change songs & volume with a remote controller or a Joystick.

MusicBox Remote.jpg


The principle is to detect if there is matched infrared remote control signal and play music according to different infrared signal. At the same time, it can detect and judge the Joystick's movement in the X-Y direction by reading the analog value. It'll choose the control mode according to the stay time.

MusicBox Remote controller-sch.jpg


Module Number Function
mCookie-CoreUSB 1 Core board
mCookie-Hub 1 Sensor pin board
mCookie-Audio 1 Audio module
mCookie-Amplifier 1 Amplifier module
mCookie-OLED 1 OLED display
mCookie-BM 1 Battery management
Microduino-Joystick 1 Joystick sensor
Microduino-IR Receiver 1 Infrared receiver
  • Other Equipment:
    • Two loudspeakers
    • One battery
    • One TF card
    • One infrared remote controller
MusicBox Remote-module.jpg


  • Setup 1:Connect the CoreUSB to the computer via a USB cable and open Arduino IDE.
CoreUSB Ble pc.jpg
  • Setup 2:Click Files > Examples > mCookie > _302_MusicBox_Remote and then load the program.
MusicBox Remote ino.jpg
  • Setup 3:Select the right board and COM port for program download. When it pops up "Done Uploading" notice, it means the program has been written into the CoreUSB module.
MusicBox Remote ino-ok.jpg

Software Debugging

  • Infrared Control
if (irrecv.decode(&results)) {
    //Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value

    if (results.value == 0xFFA857)
      music_status = !music_status;	//Play or pause 
      if (music_status == true)	//Play 
        Serial.println("play");   //Serial outputs "PLAY"  
        audio_play();              //Audio starts to work.  
      else	//Pause  
        Serial.println("pause");   //Serial outputs "PAUSE"  
        audio_pause();              //Audio pauses. 
    else if (results.value == 0xFF906F)//Next song  
      music_num++;	//Music number +
      if (music_num > music_num_MAX)	//Limit the number of songs if it is larger than 30.   
        music_num = 1; //Music number returns to 1.  
      music_status = true;
    else if (results.value == 0xFFE01F)//Last song  
      music_num--;	//Music number reduces one.   
      if (music_num < 1)	// Limit the song number if it is less than one.
        music_num = music_num_MAX;   //Maximum music number (Here is nine.)
      music_status = true;
      audio_choose(music_num);       //Audio chooses music number. 

      audio_play();                  //Audio play 
    else if (results.value == 0xFF02FD)//Volume+ 
      music_vol++;                 //Volume+ 1
      if (music_vol > 30) music_vol = 1; //If the volume is more than 30, then it returns to 3.   
      music_status = true;
    else if (results.value == 0xFF9867)//Volume-  
      music_vol--;                   // Volume-1    
      if (music_vol < 1) music_vol = 30; // If the volume is less than 1, then it returns to 30.
      music_status = true;
    results.value = 0;
  • Detect the joystick value
int uiStep()         //Change songs  
  if (analogRead(A0) < 100)  //Y-up
    delay(50);       //50ms delay 
    if (analogRead(A0) < 100)      //
      return 1;      //Return to 1  
  if (analogRead(A1) < 100)    //
    delay(50);       //50ms delay   
    if (analogRead(A1) < 100)  //X-Right
      return 2;      //Return to 2  
  if (analogRead(A1) > 900)    //X-Left
    delay(50);       //50ms delay  
    if (analogRead(A1) > 900)  //
      return 3;      //Return to 3
  return 0;
  • OLED display interface, which is available to be changed by users.
 //Main interface, which can be defined freely by users.  
void draw()

  u8g.setPrintPos(4, 16);
  u8g.print(music_status ? "play" : "pause");

  u8g.setPrintPos(4, 16 * 2);
  u8g.setPrintPos(4, 16 * 3);
  u8g.setPrintPos(4, 16 * 4);

Hardware Buildup

  • Setup 1:Use the wire to connect the OLED to the IIC interface of the Hub, then install the Joystick sensor to A0, A1 and the IR receiver sensor to D6.
MusicBox Remote hub.jpg
  • Setup 2:Insert the TF card into the slot of AudioShield.
MusicBox Joystick TF.jpg
  • Setup 3:Stack the Audio and AudioShield to the PC, and you can save MP3 files into the TF card. (Here we can save 9 to the most.)
MusicBox Joystick song.jpg
  • Setup4:Connect the two loudspeakers to the Amplifier.
MusicBox Joystick song speak.JPG
  • Setup5:Make sure you stack Audio, AudioShield and Amplifier together.
MusicBox Joystick 3 speaker.JPG
  • Setup6:Connect the activated battery box with the BM module.
CoreUSB Ble steup2.jpg
  • Setup7:Stack all modules together without fixed order.(Except for Audio, AudioShield and Amplifier should be connected with each other). Congratulations! You just finished the circuit buildup!
MusicBox Remote controller steup ok.JPG

How to operate

You can push the corresponding button of the remote controller to change songs or volume.

MusicBox Remote ir receiver.JPG

You can also control the music box with the Joystick, as follows:

MusicBox Joystick cc caozuo.JPG

Also you can choose DUO-V to be stacked with OLED so as to reduce the stacking height.


To play, pause or change songs with an infrared remote controller of Joystick to control. Here you can also build a beautiful shell for your project with LEGO since mCookie can be easily stacked with LEGO boards.

MusicBox Remote okay.JPG