Introduction: Musical Robot for Kids / Robot Musical Pour Enfants (bilingue)

About: French Graduate Engineer, love electronics, software and 3D printing

Build this cute musical robot, it's easy ! I made a very girly version of it for the 5 years birthday of my grand-daughter, she loves it !! It's quite easy to use, very intuitive and suitable for kids. They will be able to choose to listen any kind of music and songs you will have stored in it. No internet connection, it's safe. And battery will last for hours.

I believe this tutorial is very accessible to all electronics DIYers, you will find step by step explanations to build and customize it as you want. Sometimes, for in-depth explanations about elements I got from other people, I'll give you the link to their blogs. Required skills include a bit of electronics (say mostly soldering), a bit of software and 3D printing. In case you have difficulties, I'll be happy to help.

This tutorial is written both in English and French.

Time to start !

You need to gather up a few elements:

Construisez facilement ce petit robot musical ! J'ai réalisé et offert le modèle présenté ici à ma petite fille de 5 ans, elle l'adore !! Il est facile à utiliser, très intuitif et adapté aux enfants. Ils peuvent choisir d'écouter la musique ou les chansons que vous avez sélectionnées pour eux et stockées dans le robot. Il n'y a pas besoin de connection internet. Et la batterie dure des heures.

Le tuto est très accessible à tous les bricoleurs, vous y trouverez toutes les explications, pas à pas et pourrez personnaliser le robot à votre goût. Parfois, pour avoir plus de détails sur des éléments que j'ai récupérés d'autres bricoleurs, je vous donnerai les liens vers leurs tutos. Vous avez simplement besoin de savoir souder, il y a un peu de logiciel et de l'impression 3D.

Supplies

Step 1: Understanding the Electronics (part 1) / Comprendre L'électronique (1ère Partie)

The hardware architecture is based on the ESP32 micro-controller.

I often use a WEMOS LOLIN32 (ESP32) since I like the very low power consumption when in sleep mode, wifi and bluetooth inside, the lipo battery charger, ... Ironically in this case, I use none of these features, but I keep a stock of them at home, so I used one of them. Nothing really complex here, the LOLIN32 will run the application and interface with the different elements: 2 rotary encoders, the power control, a small OLED screen, an MP3 reader.

The MP3 reader is a very cheap DFPlayer Mini integrating a micro SD card driver on which you can store and play back MP3 files. The ESP32 sends basic commands (play, stop, ...) to the DFPlayer and receives status through a serial interface. The "Busy output" pin is also used to monitor the current DFPlayer status: working or not working. A speaker output is available for connecting a 3W maximum speaker or a headset. I will explain in the next step how they can be connected through an audio jack.

An 1.3" OLED screen is connected through the I2C bus. The 128 x 64 pixels screen is used to display a picture representing the current MP3 folder and level of remaining battery.

2 rotary encoders: 1 for the audio volume, 1 for changing the MP3 folder (turn) and start the next song (push).

The Power Control part (details in the next step) is used to manage the on/off process. A long (1 second) push starts the system, a second long push will stop it. If there is no interaction with the robot during 5 minutes and no song played back, the system will automatically shut off.


L'architecture matérielle est basée sur un micro-contrôleur ESP32.

J'utilise souvent des WEMOS LOLIN32 (ESP32) qui ont plein de qualités: très basse consommation en mode sleep, wifi et bluetooth, contrôleur de charge Lipo... En fait, je n'ai rien utilisé de tout ça pour ce projet mais bon, j'ai un stock à écouler... Le montage n'est pas compliqué, le LOLIN32 exécute un petit programme simple qui gère les interactions avec les différents éléments: les 2 encodeurs rotatifs, le contrôle de l'alimentation, un petit écran OLED et le lecteur MP3.

Le lecteur MP3 est le DFPlayer Mini, vraiment pas cher, qui intègre un lecteur de carte micro-SD qui stockera les fichiers MP3. L'ESP32 envoie des commandes simples (play, stop, ...) au DFPlayer et reçoit un statut au travers d'une interface série. La broche "Busy output" est utilisée pour connaitre l'état du DFPlayer (occupé, disponible). On peut connecter un haut-parleur de 3W maximum ou un casque. J'explique comment les connecter dans la section suivante.

Un écran OLED 1.3" est connecté sur le bus I2C. L'écran de 128 x 64 pixels affiche un pictogramme représentant le dossier MP3 en cours de lecture et le pourcentage restant de batterie.

Il y a aussi 2 encodeurs rotatifs: 1 pour le volume, l'autre pour sélectionner le dossier MP3 (en le tournant) and démarrer la lecture du morceau suivant (en appuyant).

Le contrôle de l'alimentation (Power Control) gère l'allumage et l'extinction du système. Une pression prolongée (1 s) sur le bouton on/off démarre le système, une deuxième pression prolongée l'arrête. Le robot s'arrête tout seul au bout de 5 minutes si on ne touche à aucun bouton et si aucune musique n'est en cours de lecture.

Step 2: Understanding the Electronics (part 2) / Comprendre L'électronique (2ème Partie)

I used EasyEDA to draw the schematics. I strongly recommend this tool: it is easy to use and reference a huge bank of components.

POWER CONTROL

You can now see the details of the Power Control part, based on the MOSFET transistor NDP6020P. When the switch is pushed down (power on), the transistor 2N3904 triggers the MOSFET, allowing current to flow from the battery (via the TP4056) and booting the ESP32. One of the first things done by the ESP32 is to activate the POWER_CONTROL signal (pin 12) to latch the MOSFET. The button can be released, the ESP32 remains powered. A second push on the switch (for power off) is detected by the ESP32 through the SWITCH_MONITOR signal (pin 13). The ESP32 then deactivates the POWER_CONTROL signal to unlatch the MOSFET and cut the current. More explanations can be found here.

Note that the current comes from a 2500 mAh Lipo battery associated with a TP4056 power charger to safely charge the battery. Connection of TP4056:

  • micro-USB: used to charge the battery
  • IN- and IN+: not used
  • B- and B+: connect the Lipo battery
  • OUT- and OUT+: connection to the board

The battery level is monitored by the ESP32.

La partie Power control est détaillée sur le schéma joint, elle est basée sur le transistor MOSFET NDP6020P. Quand l'interrupteur est pressé (allumage), le transistor 2N3904 active le MOSFET qui met sous tension l'ESP32 et déclenche le boot. Une des premières tâches de l'ESP32 est d'activer le signal POWER_CONTROL (pin 12) pour verrouiller le MOSFET. Le bouton peut être relâché, l'ESP32 reste sous tension. Une deuxième pression sur le bouton (arrêt) est détectée par l'ESP32 qui surveille le signal SWITCH_MONITOR (pin 13). L'ESP32 désactive alors le signal POWER_CONTROL pour déverrouiller le MOSFET et couper l'alimentation. Vous trouverez plus d'infos ici.

A noter que le courant est fourni par une batterie Lipo de 2500mAh associée avec le contrôleur de charge TP4056. La connection du TP4056 se fait de la manière suivante:

  • micro-USB: pour charger la batterie
  • IN- and IN+: non utilisé
  • B- and B+: vers la batterie
  • OUT- and OUT+: vers la carte principale.

HEADSET CONNECTION BOARD

This is a clever cabling of the stereo jack (5 pins) to enable the connection from the HP-/HP+ output of the DFPlayer Mini:

  • to the mono speaker at full power when no headset is inserted
  • to the stereo headset (audio remains mono) with a reduced power when the jack is inserted. This is particularly important to prevent any ear damages of your beloved kids.

Le câblage du jack stereo est particulièrement astucieux car il permet la connection de la sortie HP-/HP+ du DFPlayer Mini:

  • à pleine puissance vers le haut-parleur interne lorsque le casque n'est pas branché
  • à puissance réduite (en mono) lorsque le casque est branché. C'est un point de sécurité pour préserver les oreilles des enfants.

Step 3: Building the Electronics / Assembler Les Composants

The main board (PCB) will include the ESP32, the DFPlayer mini and the Power Control part components. Connection with other elements are done through soldered colored wires (dupont like) and JST connectors on the other end to connect to the PCB.

I used EasyEDA to capture the schematic and generate the PCB through automatic routing. The result is excellent and I ordered it to JLCPCB. Actually it cost me 2$ for 5 PCBs, plus the delivery !

You will find here the Gerber zip file containing the description of the PCB (type of file not allowed to upload on this site) and allowing you to order it. You don't need to install EasyEDA except if you want to modify the board.

Soldering elements on the PCB is quite straightforward, I strongly recommend to use a support for the ESP32.

The headset connection board is just a small piece of veroboard to solder the jack, the resistor and the wires to the PCB.

La carte principale (PCB) supporte l'ESP32, le DFPlayer Mini et les composants pour contrôler l'énergie. La connection avec les autres éléments se fait avec des fils de couleur (type dupont) sertis sur des connecteurs JST.

J'ai utilisé EasyEDA pour saisir le schéma et générer le circuit imprimé par routage automatique. Le résultat est excellent et j'ai commandé sa réalisation à JLCPCB. il m'en a coûté 2$ pour 5 circuits imprimés, plus la livraison !

Vous trouverez ici le fichier Gerber qui contient la description du circuit (ce type de fichier n'est pas autorisé sur le site) qui vous permettra de le commander. Vous n'avez pas à installer EasyEDA sauf si vous voulez modifier le circuit.

Souder ensuite les composants ne pose pas de problème particulier, je recommande d'utiliser un support pour l'ESP32.

Le circuit de connection au casque est simplement fait à partir d'une petite carte veroboard sur lequel on soude le jack, la résistance et les fils vers la carte.

Step 4: Add Music / Ajouter La Musique

There are some constraints on the MP3 files you can store on the SD card. If you want to learn more about this, please visit the DFPlayer wiki.

Mine is formatted FAT32 and I organized the files as follows:

  • 6 folders at the root, numbered from 01 to 06, corresponding to the 6 audio themes:
    • folder 01: songs for kids
    • folder 02: tales
    • folder 03: Disney songs
    • folder 04: Christmas songs
    • folder 05: other songs for kids
    • folder 06: classical music
    • folder 07: other songs for kids
  • Each folder contains MP3 files with names starting with 4 digit numbers + free text: e.g. 001_song1, 002_song2, ... It's important to do it this way, otherwise the files won't be recognized by the reader. Only the first 4 characters are taken into account.
  • 1 additional folder, at the root, numbered 99 corresponding to additional messages: e.g. Welcome message, Low Battery, ...

Only one additional message is currently implemented: the Welcome message after the boot. You can record it yourself or simply ignore it. I does not make sense to share mine since it is customized with the name of my grand-daughter, but it's really easy to record something with the Audacity application and robotize your voice. Save the file as 001.mp3.

Due to copyright, I cannot supply the MP3 files: you need to put your own ones. If you decide to change the folders themes, or add new folders, you will have to change the code (explained in the next section).

Il y a certaines contraintes à respecter pour stocker les fichiers MP3 sur la carte SD. Pour en savoir plus, visitez le wiki DFPlayer.

La mienne est au format FAT32 et j'ai organisé les fichiers de la façon suivante:

  • 6 dossiers créés à la racine, numérotés (nommés) de 01 à 06, correspondant aux 6 thèmes audio suivants:
    • dossier 01: chansons pour les enfants
    • dossier 02: contes
    • dossier 03: chansons de Disney
    • dossier 04: chansons de Noël
    • dossier 05: d'autres chansons pour les enfants
    • dossier 06: musique classique
    • dossier 07: chansons des United Kids
  • Chaque dossier contient des fichiers MP3 dont les noms sont composés par 4 digits suivis d'un texte libre. Par exemple 001_chanson1, 002_chanson2, etc... Il est important de respecter cette règle sinon les fichiers ne seront pas reconnus par le lecteur MP3. En fait, seuls les 4 premiers caractères comptent.
  • 1 dossier supplémentaire créé à la racine, nommé 99, et qui contient les messages de service: par exemple un message de bienvenue, alerte batterie faible, ec...

Un seul message est réellement pris en compte dans le code: c'est celui du message de bienvenue lorsque le robot démarre. Vous pouvez l'enregistrer vous même ou simplement ne pas mettre de fichier. Je ne vous propose pas le mien car je l'ai personnalisé pour ma petite-fille, mais il très facile d'enregistrer le vôtre avec l'application Audacity et robotiser votre voix. Sauvegardez le fichier avec le nom 001.mp3.

Quant aux chansons, je ne peux pas non plus vous les mettre en téléchargement à cause des droits d'auteurs: vous devez utiliser les vôtres. Si vous décidez de changer les thèmes des dossiers ou en ajouter de nouveaux, vous devrez changer le code (c'est expliqué dans la section suivante).

Step 5: Set Up the Software / Préparer Le Logiciel

I used the Arduino IDE to develop the software in C language. You will find here explanations to set up the IDE for the Lolin32 microcontroller. I also used SmartGit for configuration management (a good practice !).

J'ai utilisé l'atelier Arduino pour développer en langage C. Vous trouverez ici l'explications pour configurer l'environnement pour le micro-contrôleur Lolin32. J'ai également utilisé SmartGit pour la gestion de configuration (une bonne pratique !).

There is nothing complex in the code, it is a very linear programmation as we usually find in this case. However I tried to structure the code a little bit and split the few lines in modules:

  • Blinky2.ino: is the main module with the classic setup() and loop() functions
  • Blinky2.h: a few parameters here. Change NUMBER_OF_FOLDERS if you add/remove MP3 folders.

Rien de complexe dans le code, c'est une programmation très linéaire comme souvent dans ces cas-là. Malgré tout, j'ai essayé de structurer un peu le code en créant des modules:

  • Blinky2.ino: module principal avec les fonctions classiques setup() et loop()
  • Blinky2.h: quelques paramètres. Modifier NUMBER_OF_FOLDERS si vous ajoutez ou retirez des dossiers MP3.
// Number of folders of songs

const int NUMBER_OF_FOLDERS = 7;
  • ButtonFolder.h, ButtonFolder.ino, ButtonVolume.h, ButtonVolume.ino: asynchronous management of the rotary encoders.
  • Mp3.ino, Mp3.h: management of commands to the DFPlayer Mini. you need to install the DFRobotDFPlayerMini library.
  • Power.ino, Power.h: management of power on and off, management of battery
  • Display.ino: management of the OLED display thanks to the U8g2lib library that you will have to install as well in your environment.
  • Display.h: mostly includes the definition of the images representing each folder. If you want to modify the images, change the folders, this is explained in the next section.
  • ButtonFolder.h, ButtonFolder.ino, ButtonVolume.h, ButtonVolume.ino: gestion asynchrone des encodeurs rotatifs
  • Mp3.ino, Mp3.h: gestion des commandes vers le DFPlayer Mini. Vous devrez installer la bibliothèque DFRobotDFPlayerMini.
  • Power.ino, Power.h: gestion du contrôle d'alimentation, gestion de la batterie
  • Display.ino: gestion de l'écran OLED grâce la librairie graphique U8g2lib que vous devrez également installer dans votre environnement.
  • Display.h: contient la déclaration des images représentant les différents dossiers. Si vous voulez modifier les images, changer les dossiers, vous trouverez les explications dans le paragraphe suivant.

Step 6: Prepare the Display / Préparer L'Interface

If you decide to change the folders themes, or add new folders, you will have also to change the small image associated to them. This section explains how you can transform an image to C code, taking the theme "classic" as an example.

Si donc vous décidez de changer les thèmes des dossiers, ou d'en ajouter de nouveaux, vous devrez changer l'image associée. Je vais vous expliquer comment transformer une image en code C, en prenant l'exemple du thème "classique".


  • First, I recommend to install GIMP on your computer
  • Run GIMP and load your image file. Any image can do it but keep in mind that the final display will only be 128 x 64 pixels, so it has to be pretty simple, like an icon.
  • Follow this detailed tutorial from section 5. To better fit the screen, I set the image height to 64 pixels.
  • You should now have a file with .xbm extension containing the C source code: classic.xbm with a structure like this:
  • D'abord, je vous recommande d'installer GIMP sur votre ordi
  • Lancer GIMP and ouvrez votre image. N'importe quelle image peut convenir mais gardez bien à l'esprit que l'affichage final se fera sur 128 x 64 pixels, donc elle doit être assez simple, comme une icône.
  • Suivez ce tutoriel détaillé à partir de la section 5. Pour adapter correctement l'image à l'écran, j'ai pris systématiquement une hauteur de 64 pixels.
  • Vous devriez finalement récupérer un fichier avec l'extension .xbm qui contient le code C: classic.xbm avec la structure suivante:
#define classic_width 64
#define classic_height 64
static unsigned char classic_bits[] = {
   0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0xe0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,
   0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ....

   ...., 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00 };

  • Copy and paste this code into the Display.h file.
  • Add (from line 378) the following declaration:
  • Copier/coller le code dans le fichier Display.h
  • Ajouter (à partir de la ligne 378) la déclaration suivante:
IMAGE classic = {classic_width, classic_height, classic_bits};
  • Finally, update the structure (end of the file):
  • Finalement, mettez à jour la structure (en fin de fichier):
IMAGE images[NUMBER_OF_FOLDERS]= {comptine, loup, mickey, pere_noel,comptine2, classic, kidsunited};

You can now compile the final source code and download the binary to the ESP32.

Vous mettez maintenant compiler votre source and télécharger le binaire dans l'ESP32.

Step 7: Print the Box / Imprimer Le Coffret

The box has been designed using Fusion 360, an excellent modeling tool. Now, time to 3D print the box: please download all the attached files corresponding to the box, the ears, the back panel and other internal elements. I used my Prusa Mk3s+ printer and PrusaSlicer with standard parameters: PLA filament, 0.15mm Quality, Supports everywhere. For the filament color, I chose a very nice silk pink, very girly (gift for my grand-daughter).

Glue the ears on both sides of the box. Spray two layers of varnish with a satin finish on the box and the back panel as well. Wait for 24 hours.

Le coffret a été conçu avec Fusion 360, un super outil de modélisation. Téléchargez les fichiers joints correspondants au coffret, aux oreilles, au panneau arrière et à d'autres pièces internes. J'ai utiliser mon imprimante Prusa Mk3s+ et PrusaSlicer avec les paramètres standards: filament PLA, qualité 0.15mm, supports partout. J'ai choisi un très beau filament brillant de couleur rose, c'était un cadeau pour ma petite fille.

Coller les oreilles des 2 côtés du coffret. Passez 2 couches de vernis satiné sur le coffret et le panneau arrière. Attendez 24h.

Step 8: Final Assembly / Assemblage Final

Start by inserting and fixing the OLED screen in the screen holder with M2 self-tapping screws. Close with the screen protection also fixed with M2 screws. Make sure the wires and connector go through.

For the speaker, you can first insert some protective fabric, then insert the speaker. Close with the speaker protection and fix it with M2 screws. Make sure the cables are not trapped inside.

Then fix the 2 rotary switches and add the buttons.

Insert and screw the ON/OFF button on top of the box.

Fix the main PCB with 4 M2 self-tapping screws on the side supports. Do not forget the micro-SD card.

Insert carefully the TP4056 board inside the charger holder, the micro-USB connector is fragile. You may have to reduce a bit the length of the board by cutting the 2 small bumps close to the OUT-/+ pads. Originally, I planned to have a protection lid on top of it (as it is shown on the photo) but I realized it would prevent from closing the back panel: wrong idea, do not add anything on top of the TP4056. It will not move anyway.

Insert the Lipo battery into its holder on the back panel and close the protection with M2 screws.

Insert the audio jack and its small board (headset connection board), and screw it.

Plug all the connectors.

You just have to fix the panel again with M2 screws.

And congratulations, you're done !!

Commencez par insérer l'écran OLED dans son habitacle et fixez avec 2 vis M2 auto-perceuses. Fermez l'habitacle avec le petit panneau de protection et fixez également avec 2 vis M2. Laissez passer la nappe de fil.

Avant de placer le haut-parleur, positionnez une pièce de tissu pour le protéger de l'extérieur. Fermez l'habitacle et fixez avec 2 vis M2. Laissez passer les 2 fils du haut-parleur.

Puis vissez les 2 encodeurs rotatifs et ajoutez les boutons.

Insérez et vissez le bouton ON/OFF sur le dessus du coffret.

Fixez le circuit imprimé avec 4 vis M2 auto-perceuses sur les supports latéraux. N'oubliez pas d'insérer la carte micro-SD d'abord.

Insérer avec beaucoup de protection la petite carte TP4056 dans son habitacle. Attention, le connecteur micro-USB est fragile et peut s'arracher facilement. Pour gagner de la place en longueur, il vaut mieux couper les 2 petites excroissances en regard des sorties OUT-/+. Je pensais ajouter par-dessus un petit panneau de protection (comme sur la photo) mais ça gène la fermeture du panneau arrière. Donc n'en mettez pas, c'était une mauvaise idée. La carte ne bougera pas de toute façon.

Insérez la batterie Lipo dans son habitacle du panneau arrière et vissez le petit panneau de protection avec des vis M2.

Insérez le jack audio avec sa petit carte et vissez le.

Branchez tous les connecteurs.

Et fixez le panneau arrière avec des vis M2 auto-perceuses.

Félicitations, c'est terminé !!

Step 9: Enjoy the Music / Bonne Écoute

A simple press on the top on/off button will wake it up. The default MP3 folder (01) is selected and its image is displayed on the screen. Turning the folder button will change the MP3 folder. Pushing the button will start randomly a song within the folder. Pushing it again will start another one. The other button will change the audio volume. That's it, I cannot make it more simple.

Hope you'll make happy kids !!

Une simple pression sur le bouton du haut réveille le robot. Le dossier MP3 par défaut (01) est sélectionné et son pictogramme s'affiche sur l'écran. Tournez le bouton dossier pour changer de thème. Appuyez sur le même bouton lancera l'écoute d'une chanson aléatoire dans le dossier. Appuyez encore, une autre chanson démarrera. L'autre bouton permet de régler le volume. C'est tout, on ne peut pas faire plus simple.

J'espère que vous ferez des heureux !!

Step 10: Possible Improvements / Améliorations Possibles

A few thoughts about possible improvements:

  • External reinforcement of the screen with a transparent protection would be good. As it is built it's easy to push the screen inside and break the screw holders.
  • Same remark for the speaker: you need to glue the protective fabric inside.
  • Replace the USB charger with an induction charger, it's safer for the kids.

et voilà, see you soon !!

J'ai pensé à quelques améliorations possibles:

  • le renforcement de l'écran avec une protection transparente serait pas mal. Tel quel, il est facile d'enfoncer l'écran vers l'intérieur et de casser ses fixations
  • Même remarque pour le haut-parleur: il faudrait coller le tissu à l'intérieur pour l'empêcher de bouger
  • Remplacer le chargeur USB par un chargeur à induction, ce serait plus adapté pour des enfants.

et voilà, à bientôt !!

Anything Goes Contest

First Prize in the
Anything Goes Contest