{"id":189808,"date":"2026-02-12T14:30:06","date_gmt":"2026-02-12T14:30:06","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=189808"},"modified":"2026-02-12T15:25:37","modified_gmt":"2026-02-12T15:25:37","slug":"esp32-yx5300-yx6300-mp3-player-arduino","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/esp32-yx5300-yx6300-mp3-player-arduino\/","title":{"rendered":"ESP32 with YX5300\/YX6300 MP3 Player (Arduino IDE)"},"content":{"rendered":"\n<p>This is a guide on how to interface the YX5300 \/ YX6300 Serial MP3 Music Player Module with the ESP32 programmed with Arduino IDE. You&#8217;ll learn how to wire the MP3 player to the ESP32 and play sounds and music tracks from<em>.mp3\/.wav<\/em> files that are stored in a MicroSD card. As a project example, we&#8217;ll also show you how to build an MP3 audio player with button controls and a volume knob.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/ESP32-Guide-YX5300-YX6300-MP3-Player-Arduino-IDE.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 Guide YX5300 YX6300 MP3 Player Arduino IDE\" class=\"wp-image-189806\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/ESP32-Guide-YX5300-YX6300-MP3-Player-Arduino-IDE.jpg?w=1920&amp;quality=100&amp;strip=all&amp;ssl=1 1920w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/ESP32-Guide-YX5300-YX6300-MP3-Player-Arduino-IDE.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/ESP32-Guide-YX5300-YX6300-MP3-Player-Arduino-IDE.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/ESP32-Guide-YX5300-YX6300-MP3-Player-Arduino-IDE.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/ESP32-Guide-YX5300-YX6300-MP3-Player-Arduino-IDE.jpg?resize=1536%2C864&amp;quality=100&amp;strip=all&amp;ssl=1 1536w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n<p><strong>Table of Contents<\/strong><\/p>\n\n\n\n<p>In this tutorial, we&#8217;ll cover the following topics:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"#intro-YX5300\" title=\"\">Introducing the YX5300 \/ YX6300 Serial MP3 Music Player Module<\/a><\/li>\n\n\n\n<li><a href=\"#YX5300-wiring\" title=\"\">Wiring the YX5300 \/ YX6300 Serial MP3 Music Player to the ESP32<\/a><\/li>\n\n\n\n<li><a href=\"#microsd-card\" title=\"\">Preparing the MicroSD Card<\/a><\/li>\n\n\n\n<li><a href=\"#headphones-speakers\" title=\"\">Connecting Headphones or Speakers to the YX5300 Module<\/a><\/li>\n\n\n\n<li><a href=\"#YX5300-library\" title=\"\">Installing the YX5300 for ESP32 Library (YX6300 compatible)<\/a><\/li>\n\n\n\n<li><a href=\"#play-sound\" title=\"\">Testing the YX5300 \/ YX6300 MP3 Player (Play Sound)<\/a><\/li>\n\n\n\n<li><a href=\"#troubleshooting\" title=\"\">Troubleshooting the YX5300 \/ YX6300 MP3 Player Module<\/a><\/li>\n\n\n\n<li><a href=\"#mp3-audio-player\" title=\"\">PROJECT: YX5300 \/ YX6300 MP3 Player with Button Controls and Volume Knob<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"intro-YX5300\">Introducing the YX5300 \/ YX6300 Serial MP3 Music Player Module<\/h2>\n\n\n\n<p>The <a href=\"https:\/\/makeradvisor.com\/tools\/yx5300-yx6300-serial-mp3-music-player-module\/\" target=\"_blank\" rel=\"noopener\" title=\"\">YX5300 \/ YX6300<\/a> is a low-cost Serial (UART) MP3 music player module that can be interfaced with microcontrollers (such as the ESP32, ESP8266, or Arduino) to play <em>.mp3<\/em> or <em>.wav<\/em> files stored on a MicroSD card by sending serial commands.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"423\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/YX5300-YX6300-MP3-Player-Serial-Module-Front-Pinout-Headphone-Jack.JPG.jpg?resize=750%2C423&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"YX5300 YX6300 MP3 Player Serial Module Front Pinout Headphone Jack\" class=\"wp-image-189805\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/YX5300-YX6300-MP3-Player-Serial-Module-Front-Pinout-Headphone-Jack.JPG.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/YX5300-YX6300-MP3-Player-Serial-Module-Front-Pinout-Headphone-Jack.JPG.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\">Where to Buy?<\/h3>\n\n\n\n<p>You can check our Maker Advisor Tools page to compare the YX5300 \/ YX6300 module price in different stores:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><a href=\"https:\/\/makeradvisor.com\/tools\/yx5300-yx6300-serial-mp3-music-player-module\/\" target=\"_blank\" rel=\"noopener\" title=\"\">YX5300 \/ YX6300 Serial MP3 Music Player Module<\/a><\/strong><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"YX5300-wiring\">Wiring the YX5300 \/ YX6300 Serial MP3 Music Player to the ESP32<\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"417\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/YX5300-YX6300-MP3-Player-Serial-Module-Front-Pinout-Highlight.jpg?resize=750%2C417&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"YX5300 YX6300 MP3 Player Serial Module Front Pinout Highlight\" class=\"wp-image-189814\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/YX5300-YX6300-MP3-Player-Serial-Module-Front-Pinout-Highlight.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/YX5300-YX6300-MP3-Player-Serial-Module-Front-Pinout-Highlight.jpg?resize=300%2C167&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>Wiring the MP3 player to the ESP32 is quite simple, as it only requires two serial pins: <strong>RX<\/strong> and <strong>TX<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>YX5300 \/ YX6300<\/strong><\/td><td><strong>ESP32<\/strong><\/td><\/tr><tr><td>TX<\/td><td><span class=\"rnthl rntclgreen\">GPIO 16<\/span> (UART 2 RX)<\/td><\/tr><tr><td>RX<\/td><td><span class=\"rnthl rntclblue\">GPIO 17<\/span> (UART 2 TX)<\/td><\/tr><tr><td>VCC<\/td><td><span class=\"rnthl rntcred\">VIN<\/span> (5V)<\/td><\/tr><tr><td>GND<\/td><td><span class=\"rnthl rntcblack\">GND<\/span><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>According to the product specifications in the manual, the VCC works with voltages between 3.2V-5.2V. According to our testing, it works most reliably when connected to 5V (VIN).<\/p>\n\n\n\n<p>* you can use any other RX\/TX GPIOs. Check the ESP32 Pinout Guide:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-pinout-reference-gpios\/\">ESP32 Pinout Reference: Which GPIO pins should you use?<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-s3-devkitc-pinout-guide\/\">ESP32-S3 DevKitC Pinout Reference Guide: GPIOs Explained<\/a><\/li>\n<\/ul>\n\n\n\n<p class=\"rntbox rntclgreen\">You may also like: <a href=\"https:\/\/randomnerdtutorials.com\/esp32-uart-communication-serial-arduino\/\">ESP32 UART Communication (Serial): Set Pins, Interfaces, Send and Receive Data (Arduino IDE)<\/a>.<\/p>\n\n\n\n<p>We&#8217;ll connect the RX pin to <span class=\"rnthl rntclblue\">GPIO 17<\/span>, and the TX pin to <span class=\"rnthl rntclgreen\">GPIO 16<\/span>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"475\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/ESP32-YX5300-YX6300-MP3-Player-Play-Sounds-Wiring-Circuit.png?resize=900%2C475&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 YX5300 YX6300 MP3 Player Play Sounds Wiring Circuit\" class=\"wp-image-189796\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/ESP32-YX5300-YX6300-MP3-Player-Play-Sounds-Wiring-Circuit.png?w=900&amp;quality=100&amp;strip=all&amp;ssl=1 900w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/ESP32-YX5300-YX6300-MP3-Player-Play-Sounds-Wiring-Circuit.png?resize=300%2C158&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/ESP32-YX5300-YX6300-MP3-Player-Play-Sounds-Wiring-Circuit.png?resize=768%2C405&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 900px) 100vw, 900px\" \/><\/figure><\/div>\n\n\n<p class=\"rntbox rntclgray\"><strong>Important:<\/strong> in all projects that use serial commands, you need to connect the pins TX-RX and the RX-TX. However, if the code is not running properly (not sending\/receiving serial commands), you might need to swap the wiring and connect RX-RX and TX-TX. One of our Serial MP3 players came with the wrong labels on the module, and the only way it worked was connected with TX-TX and RX-RX.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"microsd-card\">Preparing the MicroSD Card<\/h2>\n\n\n\n<p>The YX5300 MP3 player has a microSD card slot where you can insert a <a href=\"https:\/\/makeradvisor.com\/tools\/microsd-card-raspberry-pi-16gb-class-10\/\" target=\"_blank\" rel=\"noopener\" title=\"\">microSD card<\/a> to store your <em>.mp3 or .wav<\/em> files. Here are the main specifications that the module supports.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>YX5300<\/strong><\/td><td><strong>Value<\/strong><\/td><\/tr><tr><td>Supported MicroSD Cards<\/td><td>MicroSD &lt;= 32GB<\/td><\/tr><tr><td>Card Format<\/td><td>FAT16 \/ FAT32<\/td><\/tr><tr><td>Track Formats<\/td><td>.mp3 \/ .wav<\/td><\/tr><tr><td>Frequencies<\/td><td>8-48 kHz<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Before proceeding with the tutorial, make sure you&nbsp;<strong>format your microSD card as FAT32<\/strong>. Follow the next instructions to format your microSD card or use a software tool like&nbsp;<a href=\"https:\/\/www.sdcard.org\/downloads\/formatter\/\" target=\"_blank\" rel=\"noreferrer noopener\">SD Card Formater<\/a>&nbsp;(compatible with Windows and Mac OS).<\/p>\n\n\n\n<p><strong>1.<\/strong>&nbsp;Insert the microSD card into your computer. Go to&nbsp;<strong>My Computer<\/strong>&nbsp;and right-click on the SD card. Select&nbsp;<strong>Format&nbsp;<\/strong>as shown in the figure below.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"431\" height=\"573\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/format-SD-card-1.png?resize=431%2C573&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"format microSD card\" class=\"wp-image-61731\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/format-SD-card-1.png?w=431&amp;quality=100&amp;strip=all&amp;ssl=1 431w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/format-SD-card-1.png?resize=226%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 226w\" sizes=\"(max-width: 431px) 100vw, 431px\" \/><\/figure><\/div>\n\n\n<p><strong>2.&nbsp;<\/strong>A new window pops up. Select&nbsp;<strong>FAT32<\/strong>, press&nbsp;<strong>Start<\/strong>&nbsp;to initialize the formatting process and follow the onscreen instructions.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"254\" height=\"463\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/format-SD-card-2.png?resize=254%2C463&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"format microsd card fat32 windows\" class=\"wp-image-61732\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/format-SD-card-2.png?w=254&amp;quality=100&amp;strip=all&amp;ssl=1 254w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/05\/format-SD-card-2.png?resize=165%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 165w\" sizes=\"(max-width: 254px) 100vw, 254px\" \/><\/figure><\/div>\n\n\n<p><strong>3.<\/strong> In order to play music tracks, you must have folders and your files named correctly, so the MP3 module can access them. Here&#8217;s an example of the folder and filename structure:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>01\/\n001xxx.mp3\n002xxx.mp3\n003xxx.mp3\n02\/\n004xxx.mp3\n005xxx.mp3\n03\/\n006xxx.mp3\n007xxx.mp3\n008xxx.mp3<\/code><\/pre>\n\n\n\n<p>Your folders must have 2-digits and each tracks needs to start with 3-digit. Each track name must be unique. Note: there is a maximum of 99 folders with 255 songs in each folder.<\/p>\n\n\n\n<p>Example, start by creating 2 folders in your microSD card (name your folders: <em>01 <\/em>and <em>02<\/em>):<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"717\" height=\"336\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/YX5300-YX6300-MP3-Player-Serial-Module-Folder-Structure.png?resize=717%2C336&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"YX5300 YX6300 MP3 Player Serial Module Folder Structure\" class=\"wp-image-189804\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/YX5300-YX6300-MP3-Player-Serial-Module-Folder-Structure.png?w=717&amp;quality=100&amp;strip=all&amp;ssl=1 717w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/YX5300-YX6300-MP3-Player-Serial-Module-Folder-Structure.png?resize=300%2C141&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 717px) 100vw, 717px\" \/><\/figure><\/div>\n\n\n<p><strong>4.<\/strong> Copy <em>.mp3<\/em> or <em>.wav<\/em> files, starting with <em>001<\/em>, <em>002<\/em>, and <em>003<\/em>. The file names must be sequencial and start with 3-digits.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"731\" height=\"336\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/YX5300-YX6300-MP3-Player-Serial-Module-Folder-and-Filenames.png?resize=731%2C336&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"YX5300 YX6300 MP3 Player Serial Module Folder and Filenames\" class=\"wp-image-189958\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/YX5300-YX6300-MP3-Player-Serial-Module-Folder-and-Filenames.png?w=731&amp;quality=100&amp;strip=all&amp;ssl=1 731w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/YX5300-YX6300-MP3-Player-Serial-Module-Folder-and-Filenames.png?resize=300%2C138&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 731px) 100vw, 731px\" \/><\/figure><\/div>\n\n\n<p><strong>5. <\/strong>Finally, remove the microSD card from you computer and attach it to the YX5300 module.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/YX5300-YX6300-MP3-Player-Module-Back-with-MicroSD-Card.JPG.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"YX5300 YX6300 MP3 Player Module Back with MicroSD Card\" class=\"wp-image-189801\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/YX5300-YX6300-MP3-Player-Module-Back-with-MicroSD-Card.JPG.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/YX5300-YX6300-MP3-Player-Module-Back-with-MicroSD-Card.JPG.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>You can <a href=\"https:\/\/github.com\/sarasantos\/rfmusic\/raw\/refs\/heads\/main\/Royalty_Free_Music.zip\" target=\"_blank\" rel=\"noopener\" title=\"\"><strong>click here to download a <em>.zip<\/em> folder with the royalty free music files<\/strong><\/a> used for this project.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"headphones-speakers\">Connecting Headphones or Speakers to the YX5300 Module<\/h2>\n\n\n\n<p>The YX5300 doesn&#8217;t come with any headphones or speakers, but you can use some heaphones similar to the ones illustrated in the image below and plug them into the module headphone jack.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/Headphone-speaker-examples.JPG.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Headphone speaker examples\" class=\"wp-image-189800\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/Headphone-speaker-examples.JPG.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/Headphone-speaker-examples.JPG.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"YX5300-library\">Installing the YX5300 for ESP32 Library (YX6300 compatible)<\/h2>\n\n\n\n<p>There are several libraries to interface the YX5300 serial module with the ESP32. We&#8217;ll use the <strong><a href=\"https:\/\/github.com\/bluejunimo\/YX5300_ESP32\" target=\"_blank\" rel=\"noopener\" title=\"\">YX5300_ESP32 library by bluejunimo<\/a><\/strong> (even though the library is called YX5300 for ESP32, it&#8217;s also fully compatible with the YX6300 MP3 module without any additional changes).<\/p>\n\n\n\n<p>You can install the library via the Arduino IDE library Manager. Search for <strong>YX5300 for ESP32<\/strong> and install the library by bluejunimo.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"579\" height=\"493\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/Installing-YX5300-YX6300-for-ESP32-MP3-Player-Serial-Arduino-IDE.png?resize=579%2C493&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Installing YX5300 YX6300 for ESP32 MP3 Player Serial Arduino IDE\" class=\"wp-image-189813\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/Installing-YX5300-YX6300-for-ESP32-MP3-Player-Serial-Arduino-IDE.png?w=579&amp;quality=100&amp;strip=all&amp;ssl=1 579w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/Installing-YX5300-YX6300-for-ESP32-MP3-Player-Serial-Arduino-IDE.png?resize=300%2C255&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 579px) 100vw, 579px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Preparing Arduino IDE<\/h2>\n\n\n\n<p>We\u2019ll program the ESP32 board using Arduino IDE. So, make sure you have the ESP32 add-on installed. Follow the next tutorial:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/installing-esp32-arduino-ide-2-0\/\">Install the ESP32 Board in Arduino IDE<\/a><\/li>\n<\/ul>\n\n\n\n<p>If you prefer using VSCode + PlatformIO, follow the next tutorial instead:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/vs-code-platformio-ide-esp32-esp8266-arduino\/\">Getting Started with VS Code and PlatformIO IDE for ESP32 and ESP8266<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"play-sound\">Testing the YX5300 \/ YX6300 MP3 Player (Play Sound)<\/h2>\n\n\n\n<p>The following code is the one provided by the library to test the MP3 player module. You&#8217;ll test if the module is working if you can hear the audio files being played in the headphone or speaker.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*********\n  Rui Santos &amp; Sara Santos - Random Nerd Tutorials\n  Complete project details at https:\/\/RandomNerdTutorials.com\/esp32-yx5300-yx6300-mp3-player-arduino\/\n  Example based on the library example by bluejunimo https:\/\/github.com\/bluejunimo\/YX5300_ESP32\/\n*********\/\n#include &lt;YX5300_ESP32.h&gt;\n\n\/\/ Connect to YX5300 Serial pins (RX and TX)\n#define RX 16\n#define TX 17\n\n\/\/ mp3 object\nYX5300_ESP32 mp3;\n\nvoid setup() {\n  \/\/ Initialize connection with the YX5300\/YX6300 module\n  mp3 = YX5300_ESP32(Serial2, RX, TX);\n  \n  \/\/ Shows the hex commands being sent to the mp3 device (includes helpful errors)\n  Serial.begin(115200);\n  mp3.enableDebugging();\n\n  \/\/ Plays the first track stored on the microSD Card (Track Formats .mp3\/.wav | Frequencies 8-48 kHz)\n  \/\/ MicroSD Card folder and file structure, example folder name 01 and file name 001xxx.mp3:\n  \/\/ 01\/001xxx.mp3   01\/002xxx.mp3   01\/003xxx.mp3   02\/004xxx.mp3\n  mp3.playTrack(1);\n}\n\nvoid loop() {\n  \/\/ put your main code here, to run repeatedly:\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP32\/ESP32_YX5300_YX6300_Play_Track.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How the Code Works<\/h3>\n\n\n\n<p>Let&#8217;s break down how the code works.<\/p>\n\n\n\n<p><strong>Include YX5300_ESP32 library<\/strong><\/p>\n\n\n\n<p>First, you need to include the <span class=\"rnthl rntliteral\">YX5300_ESP32.h<\/span> library created by bluejunimo that will make it very easy to interface with the MP3 player module<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#include &lt;YX5300_ESP32.h&gt;<\/code><\/pre>\n\n\n\n<p><strong>Initialize the YX5300<\/strong><\/p>\n\n\n\n<p>Set the YX5300 RX and TX pins and create an object for the module called <span class=\"rnthl rntliteral\">mp3<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#define RX 16\n#define TX 17\n\nYX5300_ESP32 mp3;<\/code><\/pre>\n\n\n\n<p><strong>setup()<\/strong><\/p>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">setup()<\/span>, start by initializing the module with the a specific Serial channel.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>mp3 = YX5300_ESP32(Serial2, RX, TX);<\/code><\/pre>\n\n\n\n<p class=\"rntbox rntclgreen\">Recommended reading: <a href=\"https:\/\/randomnerdtutorials.com\/esp32-uart-communication-serial-arduino\/\">ESP32 UART Communication (Serial): Set Pins, Interfaces, Send and Receive Data (Arduino IDE)<\/a>.<\/p>\n\n\n\n<p>Enable the Serial communication and MP3 debugging, so you can see the hex serial commands being sent to the device. With debugging enabled, you will also see helpful errors.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Serial.begin(115200);\nmp3.enableDebugging();<\/code><\/pre>\n\n\n\n<p>You can quickly play the first track stored on the microSD Card using the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>mp3.playTrack(1);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Demonstration<\/h2>\n\n\n\n<p>Upload the previous code to your ESP32 board. It will play the first track stored in the microSD card. Your serial monitor should be printing a similar message:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"746\" height=\"416\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/ESP32-YX5300-YX6300-MP3-Player-playback-track-Arduino-IDE-Serial-Monitor-Demonstration.png?resize=746%2C416&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 YX5300 YX6300 MP3 Player playback track Arduino IDE Serial Monitor Demonstration\" class=\"wp-image-189965\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/ESP32-YX5300-YX6300-MP3-Player-playback-track-Arduino-IDE-Serial-Monitor-Demonstration.png?w=746&amp;quality=100&amp;strip=all&amp;ssl=1 746w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/ESP32-YX5300-YX6300-MP3-Player-playback-track-Arduino-IDE-Serial-Monitor-Demonstration.png?resize=300%2C167&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 746px) 100vw, 746px\" \/><\/figure><\/div>\n\n\n<p>If you have the headphones or speaker plugged into the headphone jack, you should be hearing the first track stored in your microSD card. If you are experiencing any issues, follow the next troubleshooting section.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/YX5300-YX6300-MP3-Player-Serial-Module-Connected-to-Headphone-Speaker-Jack.JPG.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"YX5300 YX6300 MP3 Player Serial Module Connected to Headphone Speaker Jack\" class=\"wp-image-189802\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/YX5300-YX6300-MP3-Player-Serial-Module-Connected-to-Headphone-Speaker-Jack.JPG.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/YX5300-YX6300-MP3-Player-Serial-Module-Connected-to-Headphone-Speaker-Jack.JPG.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"troubleshooting\">Troubleshooting the YX5300\/YX6300 MP3 Player Module<\/h2>\n\n\n\n<p>If you uploaded the previous code, but you can&#8217;t hear any sound with the YX5300\/YX6300 MP3 Player Module it can be one of these following issues.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Wiring error:<\/strong> in all projects that use serial commands, you need to connect the pins TX-RX and the RX-TX. However, if the code is not running properly (not sending\/receiving serial commands), you might need to swap the wiring and connect RX-RX and TX-TX. One of our Serial MP3 players came with the wrong labels on the module, and the only way it worked was connected with TX-TX and RX-RX;<\/li>\n\n\n\n<li><strong>Not enough power: <\/strong>according to the product specifications in the manual, the VCC is works with voltages between 3.2V-5.2V. According to our testing, it works most reliably when connected to 5V (VIN);<\/li>\n\n\n\n<li><strong>MicroSD card issue:<\/strong> your microSD must be equal or less than 32GB and formated with FAT16 \/ FAT32. The track formats must be in an .mp3 \/ .wav files with 8-48 kHz frequencies;<\/li>\n\n\n\n<li><strong>Wrong folder structure \/ filenames:<\/strong> your microSD card folder and file structure is incorrect, example folder and filenames: <em>01\/001xxx.mp3 01\/002xxx.mp3 01\/003xxx.mp3 02\/004xxx.mp3<\/em>;<\/li>\n\n\n\n<li><strong>Issue headphones\/speaker:<\/strong> we recommend testing your headphones\/speakers in another device to make sure they are working.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"mp3-audio-player\">YX5300 \/ YX6300 MP3 Player with Button Controls and Volume Knob<\/h2>\n\n\n\n<p>As a project example, we&#8217;ll show you how to build an MP3 player with button controls and a volume knob. Having the Arduino IDE prepared with the library installed and the microSD card inserted in the YX5300 module with the correct folders and files described earlier, you can continue following this guide.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Parts Required<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/esp32-dev-board-wi-fi-bluetooth\/\" target=\"_blank\" rel=\"noreferrer noopener\">ESP32 Board<\/a>&nbsp;(model of your choice)<\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/yx5300-yx6300-serial-mp3-music-player-module\/\" target=\"_blank\" rel=\"noopener\" title=\"\">YX5300 \/ YX6300 Serial MP3 Music Player<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/microsd-card-raspberry-pi-16gb-class-10\/\" target=\"_blank\" rel=\"noreferrer noopener\">MicroSD Card<\/a><\/li>\n\n\n\n<li>Headphones \/ Speaker with plug<\/li>\n\n\n\n<li>3x&nbsp;<a href=\"https:\/\/makeradvisor.com\/tools\/pushbuttons-kit\/\" target=\"_blank\" rel=\"noreferrer noopener\">Pushbuttons<\/a><\/li>\n\n\n\n<li>1x <a href=\"https:\/\/makeradvisor.com\/tools\/potentiometer-assortment-kit\/\" target=\"_blank\" rel=\"noreferrer noopener\">Potentiometer<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\" rel=\"noreferrer noopener\">Jumper Wires<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\" rel=\"noreferrer noopener\">Breadboard<\/a><\/li>\n<\/ul>\n\n\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Schematic Diagram<\/h3>\n\n\n\n<p>Wiring the MP3 player to the ESP32 is quite simple, as it only requires two serial pins: <strong>RX<\/strong> and <strong>TX<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>YX5300 \/ YX6300<\/strong><\/td><td><strong>ESP32<\/strong><\/td><\/tr><tr><td>TX<\/td><td><span class=\"rnthl rntclgreen\">GPIO 16<\/span> (UART 2 RX)<\/td><\/tr><tr><td>RX<\/td><td><span class=\"rnthl rntclblue\">GPIO 17<\/span> (UART 2 TX)<\/td><\/tr><tr><td>VCC<\/td><td><span class=\"rnthl rntcred\">VIN<\/span> (5V)<\/td><\/tr><tr><td>GND<\/td><td><span class=\"rnthl rntcblack\">GND<\/span><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>According to the product specifications in the manual, the VCC is works with voltages between 3.2V-5.2V. According to our testing, it works most reliably when connected to 5V (VIN).<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Potentiometer\/Pushbuttons<\/strong><\/td><td><strong>ESP32<\/strong><\/td><\/tr><tr><td>Potentiometer<\/td><td>GPIO 4<\/td><\/tr><tr><td>Play\/Pause Pushutton<\/td><td>GPIO 5<\/td><\/tr><tr><td>Previous Track Pushbutton<\/td><td>GPIO 18<\/td><\/tr><tr><td>Next Track Pushbutton<\/td><td>GPIO 19<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Wire all the components to your ESP32 using the previous tables or by following the schematic diagram below.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"766\" height=\"900\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/ESP32-YX5300-YX6300-MP3-Player-with-Button-Controls-Wiring-Circuit.png?resize=766%2C900&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 YX5300 YX6300 MP3 Player with Button Controls Wiring Circuit\" class=\"wp-image-189799\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/ESP32-YX5300-YX6300-MP3-Player-with-Button-Controls-Wiring-Circuit.png?w=766&amp;quality=100&amp;strip=all&amp;ssl=1 766w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/ESP32-YX5300-YX6300-MP3-Player-with-Button-Controls-Wiring-Circuit.png?resize=255%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 255w\" sizes=\"(max-width: 766px) 100vw, 766px\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\">MP3 Player Code<\/h3>\n\n\n\n<p>Upload the following code to turn your ESP32 into an MP3 audio player device.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*********\n  Rui Santos &amp; Sara Santos - Random Nerd Tutorials\n  Complete project details at https:\/\/RandomNerdTutorials.com\/esp32-yx5300-yx6300-mp3-player-arduino\/\n*********\/\n#include &lt;YX5300_ESP32.h&gt;\n\n\/\/ Connect to YX5300 Serial pins (RX and TX)\n#define RX 16\n#define TX 17\n\n\/\/ Global variables for the pushbuttons\nconst uint8_t pinBtnPlay = 5;\nconst uint8_t pinBtnPrev = 18;\nconst uint8_t pinBtnNext = 19;\n\n\/\/ Bool variable to track if the audio is playing or paused\nvolatile bool isPlaying = true;\n\n\/\/ Variables for debouncing the pushbuttons\nconst unsigned long DEBOUNCE_DELAY = 500;  \/\/ in milliseconds\nvolatile unsigned long lastPressTime = 0;\n\n\/\/ Analog input pin the potentiometer is attached to\nconst uint8_t potVolume = 4; \n\n\/\/ Auxiliary volume variables\n#define MIN_VOLUME 0\n#define MAX_VOLUME 30\nint current_volume = 0;\n\n\/\/ mp3 object\nYX5300_ESP32 mp3; \n\n\/\/ Play\/Pause Button Interrupt Service Routine (ISR)\nvoid ARDUINO_ISR_ATTR buttonPlay() {\n  unsigned long now = millis();\n  if (now - lastPressTime &gt; DEBOUNCE_DELAY) {    \n    if(isPlaying) {\n      mp3.pause();\n      isPlaying = false;\n    }\n    else {\n      mp3.resume();\n      isPlaying = true;\n    }\n  }\n  lastPressTime = now;\n}\n\n\/\/ Previous Track Button Interrupt Service Routine (ISR)\nvoid ARDUINO_ISR_ATTR buttonPrev() {\n  unsigned long now = millis();\n  if (now - lastPressTime &gt; DEBOUNCE_DELAY) {    \n    mp3.prev();\n    isPlaying = true;\n  }\n  lastPressTime = now;\n}\n\n\/\/ Next Track Button Interrupt Service Routine (ISR)\nvoid ARDUINO_ISR_ATTR buttonNext() {\n  unsigned long now = millis();\n  if (now - lastPressTime &gt; DEBOUNCE_DELAY) {    \n    mp3.next();\n    isPlaying = true;\n  }\n  lastPressTime = now;\n}\n\nvoid setup() {\n  \/\/ Init pushbuttons with internal pullup resistor\n  pinMode(pinBtnPlay, INPUT_PULLUP);\n  pinMode(pinBtnPrev, INPUT_PULLUP);\n  pinMode(pinBtnNext, INPUT_PULLUP);\n\n  \/\/ Set interrupts ISR functions\n  attachInterrupt(pinBtnPlay, buttonPlay, HIGH);\n  attachInterrupt(pinBtnPrev, buttonPrev, HIGH);\n  attachInterrupt(pinBtnNext, buttonNext, HIGH);\n\n  \/\/ Initialize connection with the YX5300\/YX6300 module\n  mp3 = YX5300_ESP32(Serial2, RX, TX);\n  \n  \/\/ Shows the hex commands being sent to the mp3 device (includes helpful errors)\n  Serial.begin(115200);\n  mp3.enableDebugging();\n  \n  \/\/ Plays the first track stored on the SD Card (Track Formats .mp3\/.wav | Frequencies 8-48 kHz)\n  \/\/ SD Card folder and file structure, example folder name 01 and file name 001xxx.mp3:\n  \/\/ 01\/001xxx.mp3   01\/002xxx.mp3   01\/003xxx.mp3   02\/004xxx.mp3\n  mp3.playTrack(1);\n}\n\nvoid loop() {  \n  \/\/ Read the potentiometer's value\n  int raw_value = analogRead(potVolume);\n  \n  \/\/ Map the value to the min\/max of the mp3 device's volume values \n  int new_volume = map(raw_value, 0, 4095, MIN_VOLUME, MAX_VOLUME);\n  \n  \/\/ Change the volume if the pot position has changed\n  if(new_volume != current_volume) {\n    \/\/ Update the mp3 device's volume\n    mp3.setVolume(new_volume);\n    \/\/ Update the current volume with the new volume\n    current_volume = new_volume;\n  }\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP32\/ESP32_YX5300_YX6300_MP3_Player.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How the Code Works<\/h3>\n\n\n\n<p>Let\u2019s take a look at how the code works so that you can understand how to use the YX5300 serial commands, interrupts to trigger the button commands and potentiometer to adjust the volume.<\/p>\n\n\n\n<p><strong>Include YX5300_ESP32 library<\/strong><\/p>\n\n\n\n<p>First, you need to include the <span class=\"rnthl rntliteral\">YX5300_ESP32.h<\/span> library created by bluejunimo that will make it very easy to interface with the MP3 player module<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#include &lt;YX5300_ESP32.h&gt;<\/code><\/pre>\n\n\n\n<p><strong>Initialize the YX5300<\/strong><\/p>\n\n\n\n<p>Set the YX5300 RX and TX pins and create an object for the module called <span class=\"rnthl rntliteral\">mp3<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#define RX 16\n#define TX 17\n\nYX5300_ESP32 mp3;<\/code><\/pre>\n\n\n\n<p><strong>Variables<\/strong><\/p>\n\n\n\n<p>Create some global variables for the pushbuttons GPIOs and potentiometer.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const uint8_t pinBtnPlay = 5;\nconst uint8_t pinBtnPrev = 18;\nconst uint8_t pinBtnNext = 19;\n\nconst uint8_t potVolume = 4; <\/code><\/pre>\n\n\n\n<p>Define a bool variable to track if the audio is playing or paused.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>volatile bool isPlaying = true;<\/code><\/pre>\n\n\n\n<p>These next two variables are used for debouncing the pushbuttons.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const unsigned long DEBOUNCE_DELAY = 500;  \/\/ in milliseconds\nvolatile unsigned long lastPressTime = 0;<\/code><\/pre>\n\n\n\n<p>Finally, you need these variables to check the min\/max volume and store the courrent volume according potentiometer position.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#define MIN_VOLUME 0\n#define MAX_VOLUME 30\nint current_volume = 0;<\/code><\/pre>\n\n\n\n<p><strong>setup()<\/strong><\/p>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">setup()<\/span>, initialize the pushbuttons as inputs and set them as interrupts to detect changes on their states.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>pinMode(pinBtnPlay, INPUT_PULLUP);\npinMode(pinBtnPrev, INPUT_PULLUP);\npinMode(pinBtnNext, INPUT_PULLUP);\n\nattachInterrupt(pinBtnPlay, buttonPlay, HIGH);\nattachInterrupt(pinBtnPrev, buttonPrev, HIGH);\nattachInterrupt(pinBtnNext, buttonNext, HIGH);<\/code><\/pre>\n\n\n\n<p class=\"rntbox rntclblue\">Learn more about ESP32 interrupts: <a href=\"https:\/\/randomnerdtutorials.com\/esp32-gpio-interrupts-arduino\/\">ESP32 GPIO Interrupts with Arduino IDE<\/a>.<\/p>\n\n\n\n<p>Then, initialize the module with a specific Serial channel.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>mp3 = YX5300_ESP32(Serial2, RX, TX);<\/code><\/pre>\n\n\n\n<p>Enable the Serial communication and MP3 debugging, so you can see the hex serial commands being sent to the device. With debugging enabled, you will also see helpful errors.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Serial.begin(115200);\nmp3.enableDebugging();<\/code><\/pre>\n\n\n\n<p>You can quickly play the first track stored on the microSD Card using the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>mp3.playTrack(1);<\/code><\/pre>\n\n\n\n<p><strong>Button Interrupts<\/strong><\/p>\n\n\n\n<p>Create 3 <a href=\"https:\/\/randomnerdtutorials.com\/esp32-gpio-interrupts-arduino\/\">interrupt functions<\/a> that are instantly called when the play\/pause, previous track, and next track pushbuttons are pressed.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>void ARDUINO_ISR_ATTR buttonPlay() {\n  unsigned long now = millis();\n  if (now - lastPressTime &gt; DEBOUNCE_DELAY) {    \n    if(isPlaying) {\n      mp3.pause();\n      isPlaying = false;\n    }\n    else {\n      mp3.resume();\n      isPlaying = true;\n    }\n  }\n  lastPressTime = now;\n}<\/code><\/pre>\n\n\n\n<p>Depending on the pushbutton that was pressed, a specific function will run. These are the 4 main methods that control the MP3 player, and their names are pretty self-explanatory:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>mp3.resume();\nmp3.pause();\nmp3.prev();\nmp3.next();<\/code><\/pre>\n\n\n\n<p><strong>loop()<\/strong><\/p>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">loop()<\/span>, you constantly read the current potentiometer volume.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>int raw_value = analogRead(potVolume);<\/code><\/pre>\n\n\n\n<p>Then, if the volume has changed (increased or decreased), you adjust the volume.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>int new_volume = map(raw_value, 0, 4095, MIN_VOLUME, MAX_VOLUME);\n\nif(new_volume != current_volume) {\n  mp3.setVolume(new_volume);\n  current_volume = new_volume;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">MP3 Player Demonstration<\/h3>\n\n\n\n<p>Upload the previous code to your ESP32 board with all the components wired. It will play the first track stored in the microSD card (<a href=\"https:\/\/github.com\/sarasantos\/rfmusic\/raw\/refs\/heads\/main\/Royalty_Free_Music.zip\" target=\"_blank\" rel=\"noopener\" title=\"\"><strong>you can click here to download a <em>.zip<\/em> folder with the royalty free music files<\/strong><\/a> used for this project).<\/p>\n\n\n\n<p>In your Arduino IDE serial monitor, you should see similar messages when you press the pushbuttons.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"850\" height=\"386\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/ESP32-YX5300-YX6300-MP3-Player-with-Button-Controls-Arduino-IDE-Serial-Monitor-Demonstration.png?resize=850%2C386&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 YX5300 YX6300 MP3 Player with Button Controls Arduino IDE Serial Monitor Demonstration\" class=\"wp-image-189798\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/ESP32-YX5300-YX6300-MP3-Player-with-Button-Controls-Arduino-IDE-Serial-Monitor-Demonstration.png?w=850&amp;quality=100&amp;strip=all&amp;ssl=1 850w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/ESP32-YX5300-YX6300-MP3-Player-with-Button-Controls-Arduino-IDE-Serial-Monitor-Demonstration.png?resize=300%2C136&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/ESP32-YX5300-YX6300-MP3-Player-with-Button-Controls-Arduino-IDE-Serial-Monitor-Demonstration.png?resize=768%2C349&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 850px) 100vw, 850px\" \/><\/figure><\/div>\n\n\n<p>Check if everything is working:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>First pushbutton plays the track or pauses the track;<\/li>\n\n\n\n<li>The second pushbutton returns to the previous track;<\/li>\n\n\n\n<li>The third pushubtton skpis to the next track;<\/li>\n\n\n\n<li>Finally, you can move the potentiometer knob to adjust the volume.<\/li>\n<\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"506\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/ESP32-YX5300-YX6300-MP3-Player-with-Button-Controls-Arduino-IDE-Circuit-Demonstration.JPG.jpg?resize=900%2C506&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 YX5300 YX6300 MP3 Player with Button Controls Arduino IDE Circuit Demonstration\" class=\"wp-image-189797\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/ESP32-YX5300-YX6300-MP3-Player-with-Button-Controls-Arduino-IDE-Circuit-Demonstration.JPG.jpg?w=900&amp;quality=100&amp;strip=all&amp;ssl=1 900w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/ESP32-YX5300-YX6300-MP3-Player-with-Button-Controls-Arduino-IDE-Circuit-Demonstration.JPG.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/ESP32-YX5300-YX6300-MP3-Player-with-Button-Controls-Arduino-IDE-Circuit-Demonstration.JPG.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 900px) 100vw, 900px\" \/><\/figure><\/div>\n\n\n<p>Watch the next video for a project live demonstration.<\/p>\n\n\n<div style=\"text-align:center\"><iframe src=\"https:\/\/player.vimeo.com\/video\/1164293373?color=ff9933&title=1&byline=0&portrait=0\" width=\"720\" height=\"405\" frameborder=\"0\" webkitallowfullscreen mozallowfullscreen allowfullscreen><\/iframe><\/div><\/br>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>This was a comprehensive guide on how to interface the YX5300\/YX6300 MP3 Player with the ESP32. It can be quite useful to play sounds or music with your ESP32 board. Additionally, you can add any sensor to your project so that the ESP32 starts playing audio when a certain condition is met.<\/p>\n\n\n\n<p>We hope you&#8217;ve found this guide useful. We have other guides that might be helpful:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-neo-m8n-gps-logger-google-earth\/\">ESP32 with NEO-M8N GPS Module: GPS Logger and Display on Google Earth<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-apds9960-sensor-arduino\/\">ESP32 with APDS9960 Proximity, Light, RGB, and Gesture Sensor<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/cheap-yellow-display-esp32-2432s028r\/\">Getting Started with ESP32 Cheap Yellow Display Board<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-guides-sensors-modules\/\">ESP32: Free Guides for Sensors and Modules<\/a><\/li>\n<\/ul>\n\n\n\n<p>To learn more about the ESP32, make sure to check out our resources:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/learn-esp32-with-arduino-ide\/\">Learn ESP32 with Arduino IDE (eBook)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/projects-esp32\/\">All our ESP32 Projects and Guides<\/a><\/li>\n<\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a guide on how to interface the YX5300 \/ YX6300 Serial MP3 Music Player Module with the ESP32 programmed with Arduino IDE. You&#8217;ll learn how to wire the &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"ESP32 with YX5300\/YX6300 MP3 Player (Arduino IDE)\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/esp32-yx5300-yx6300-mp3-player-arduino\/#more-189808\" aria-label=\"Read more about ESP32 with YX5300\/YX6300 MP3 Player (Arduino IDE)\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":1,"featured_media":189806,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[281,276,277,299,264],"tags":[],"class_list":["post-189808","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp32-project","category-esp32","category-esp32-arduino-ide","category-0-esp32","category-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/02\/ESP32-Guide-YX5300-YX6300-MP3-Player-Arduino-IDE.jpg?fit=1920%2C1080&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/189808","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=189808"}],"version-history":[{"count":25,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/189808\/revisions"}],"predecessor-version":[{"id":190118,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/189808\/revisions\/190118"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/189806"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=189808"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=189808"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=189808"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}