Project tutorial
Arduino MP3 Nodding Toy

Arduino MP3 Nodding Toy © GPL3+

Stuffed toy with MP3 module, speaker, servo and piezoelectric sensor that nods to music.

  • 2,011 views
  • 0 comments
  • 7 respects

Components and supplies

Apps and online services

About this project

Summary

In this project I wanna show you how to build simple stuffed animal toy capable to play MP3 files. I also added the possibility of nodding the toy's head, just to make it cooler. :)

You can also use this tutorial as example for connecting DFPlayer Mini to Arduino, and build your own projects like alarm clock, MP3 speaker, etc.

Idea

Idea is very simple. I press stuffed toy hand, and it plays MP3 file from MicroSD card. While playing, toy is nodding it's head.

To respond to the pressure of my hand, I inserted a piezoelectric plate in toy's hand.

For nodding, I put servo with holder inside of the toy.

Hand pressure detection

To respond to the pressure of my hand, I inserted a piezoelectric plate in toy's hand.

To make the signal clearer, a 1M resistor should be added between the piezoelectric wires.

Nodding head

In order for the toy to nod its head, it was necessary to insert a holder, which would hold the servo in place. Without this, the servo would move in place. I used plastic bottle for this.

Calibrate servo based on your project setup.

void nodd()
{
   servo1.write(SERVO_NODD);
   delay(300);
   servo1.write(SERVO_INITIAL);
}

MP3

  • MicroSD formatting

Format the SD card with the FAT or FAT32 file system.

  • Connections

Using the Arduino to control the DFPlayer Mini requires seven connections between the DFPlayer and the Arduino.

Arduino TX (D5)  <--------> DFPlayer RX (with 1K resistor)
Arduino RX (D4)  <--------> DFPlayer TX
Arduino 5V     
Speaker wire 1   <--------> SPK_1 pin of DFPlayer
Speaker wire 2   <--------> SPK_2 pin of DFPlayer
Digital pin (D2) <--------> BUSY pin of DFPlayer
  • Library

I tried with multiple libraries, but they didn't work with my MicroSD card. I found this library and it works perfectly.

You can download library here, from RobotsForFun website.

Start mp3 module and set volume in setup().

 // Start MP3 module
 mp3.begin();  
 mp3.setVolume(VOLUME_INITIAL); 

Play file:

mp3.playMP3Folder(1); // Play track 1 in the mp3 folder

Stop songs:

mp3.stopAll();

Use hardward to detect if playing using the DFPlayer Busy pin

mp3.playing(BUSYPIN)

You can find code in Code section. Everything is explained in comments.

  • Add files to module

Create two special folders using the names mp3 and advert. 99 more folders can be added using names 01 to 99.

In order for the module to play the file, it is necessary to rename it in a certain format. MP3 files in mp3 and advert folders must starts with 4 digits ( 0001, 0002, 0003...), and then optionally a long filename after.

In other custom folders (01-99), MP3 filename must start with 3 digits (001, 002, 003..), and then optionally a long filename after. You can have up to 255 files inside these folders.

Finished project

Video demonstration

Possible extension of the project

You can add more piezoelectric plates for playing multiple songs, or more servos for moving head in different directions or for limbs movement.

Code

ArduinoMP3Toy.inoArduino
#include "DFPlayer.h"
#include <Servo.h>

// DFPlayer 
#define DFPserial_RX 5  // DFP RX pin 2 connect to Arduino TX pin 5
#define DFPserial_TX 4  // DFP TX pin 3 connect to Arduino RX pin 4
#define BUSYPIN 2
#define VOLUME_INITIAL 20
// Servo 
#define SERVO_PIN 6
#define SERVO_INITIAL 70
#define SERVO_NODD 55

//Piezoelectric
#define PIEZO_PIN A0
#define THRESHOLD 70

Servo servo1;
DFPlayer mp3;
bool playing = false;

void setup() {
  Serial.begin(115200);
  
  servo1.attach(SERVO_PIN);
  
  // Set initial position of servo
  servo1.write(SERVO_INITIAL);


  // Start MP3 module
  mp3.begin();  
  mp3.getPlayerStatus();
  mp3.setVolume(VOLUME_INITIAL);
}

void loop() {

  //Read piezoelectric
  int val= analogRead(PIEZO_PIN);
  delay(100);

  // Check that the piezo is pressed
  if (val >= THRESHOLD)
  {
    // If it's not playing and piezo is pressed, then start the song.
    if(!playing)
    {
        mp3.playMP3Folder(1);       // Play track 1 in the mp3 folder
    } 
    else               
    {
       // If it's playing and piezo is pressed, then stop the song.
        mp3.stopAll();
        
        // Set servo to initial position
        servo1.write(SERVO_INITIAL);
    }
  }

  // Use hardward to detect if playing using the DFPlayer Busy pin connected to pin 2 on the Arduino 
  if (mp3.playing(BUSYPIN)) { 

    //Start nodding
    nodd();
    
    if (!playing) {
      playing = true;
    }
    
  } 
  else 
  {
    if (playing) 
    {
      playing = false;
    }
  }
  delay(10);
}

void nodd()
{
    servo1.write(SERVO_NODD);
    delay(300);
    servo1.write(SERVO_INITIAL);
}

Schematics

ArduinoMP3ToyFritzing
arduinomp3toyfritzing_pUlNDLefz7.fzz
ArduinoMP3ToyFritzing image
Arduinomp3toyfritzing bb 2hoql9kul3

Comments

Similar projects you might like

Arduino Mp3 player Catalex

Project tutorial by javier muñoz sáez

  • 44,203 views
  • 11 comments
  • 36 respects

Arduino Retro Style MP3 Player!

Project tutorial by Neutrino

  • 17,123 views
  • 0 comments
  • 25 respects

Interactive Toddler Music Box Toy

Project tutorial by Christopher Monreal and Nick Udell

  • 2,975 views
  • 1 comment
  • 2 respects

Toddler's Drum Kit Toy - PCL Project 1 - Group 3

Project tutorial by Isaac Wolf and Sarah Worthington

  • 2,487 views
  • 0 comments
  • 5 respects

Arduino - Web-Based MP3 Player

Project tutorial by khanhhs

  • 17,281 views
  • 6 comments
  • 38 respects

LazerDazer: Arduino Laser Cat Toy

Project tutorial by Team RobotGeek Projects Team

  • 12,158 views
  • 1 comment
  • 26 respects
Add projectSign up / Login