August 8, 2023 by Ellie Nguyen
Have you noticed? Vinyl records are making a comeback! There’s just something so timeless about listening to an album all the way through and appreciating how the artist curated the songs to tell a story.
In this project, you’ll create your own modern day record player using an Arduino board and Radio-frequency identification (RFID). In just a few steps, this is a beginner friendly project that will allow you to enjoy all of your favorite albums and control your Spotify player without the distraction of a screen!
Follow the steps below or watch the video tutorial here:
Table of Contents:
- Bill of Materials
- Clone the GitHub Repo
- Connecting Arduino MKR 1010 to RC522 RFID Reader
- Setting Up Arduino Environment
- Storing Spotify Data in Google Sheets
- Uploading Sketches to the Arduino Board
- Sketch 1: Get Card UIDs
- Sketch 2: Authenticate Spotify
- Sketch 3: Read NFC Card and Send Album to Spotify
- Wrapping Up
- Connect with Me
Bill of Materials
Clone the GitHub Repo
GitHub - ellienguyendev/spotify-player-arduino-rfid: Spotify player and controller with Arduino MKR WiFi 1010 and RFID RC522
Spotify player and controller with Arduino MKR WiFi 1010 and RFID RC522 - GitHub - ellienguyendev/spotify-player-arduino-rfid: Spotify player and controller with Arduino MKR WiFi 1010 and RFID RC522
Connecting Arduino MKR 1010 to RC522 RFID Reader
- If your RFID reader doesn't come with pre-soldered pins, you'll need to solder right-angle header pins onto it.
- Soldering is the method of fusing two metal components using special metal alloy called solder. These pins act as connectors, ensuring a reliable and stable connection between the RFID reader and the Arduino board.
- These connections will enable seamless communication and data transfer, allowing your Arduino project to interact with the RFID reader effectively.
- The Arduino should have solid green and orange lights.
- The RFID reader should have a solid red light.
Setting Up Arduino Environment
Before we delve into the hands-on process, let's prepare the tools that will empower you to program and interact with the Arduino board effectively.
- Arduino Create Agent: Download and install the Arduino Create Agent to enable uploading sketches from Arduino Cloud to your board. Activate the app after installation.
- Arduino Cloud Account: Sign up for an account on Arduino Cloud, complete the registration process, and verify your email address. Access the IoT Cloud menu to create your first Thing, connect your device, and configure network settings.
- Arduino IDE: Download the Arduino IDE, where you'll write and upload sketches to your Arduino board. In the IDE:
- Install the
Arduino SAMD Boardsin the Boards Manager
- In the Library Manager, add the following libraries:
ArduinoHttpClientby Arduino, and
MFRC522by GitHub Community
- Select the appropriate Board and Port to match your connected Arduino board.
Storing Spotify Data in Google Sheets
In this section, you will use the NFC Albums Template in Google Sheets to manage album information and other project data. It easily formats your data for you to use in the code later.
- Fill in the album information in the corresponding columns (B & C) and use Spotify to get album links. Repeat this process for all your albums.
- Note: The Spotify APIs used can also play artists and playlists, but not individual songs.
Uploading Sketches to the Arduino Board
Now, let's take a closer look at the code and sketches involved in this project. The first two are used to initialize our projects and Sketch 3 will be the main program that lives on our board.
- Sketch 1: Get unique IDs of each NFC card
- Sketch 2: Create and authenticate your Spotify app
- Sketch 3: Read NFC cards to play albums and control the Spotify player
Sketch 1: Get Card UIDs
get_card_uid.inofile. This code is a simple sketch that uses an Arduino board and an MFRC522 RFID reader module to detect and read the Unique Identifier (UID) of NFC cards when they are presented to the reader. It prints the UID of the detected card to the Serial Monitor.
- Upload & Monitor the Sketch
- Upload the sketch to the Arduino board. Then, open the Serial Monitor to establish communication with the board and view messages and debugging information.
- Prepare the NFC Cards
- Each NFC card must be associated with a specific album. Either write the album names onto each card or place them into album sleeves. Additionally, for control cards, write the corresponding "action" on each card to control the Spotify player.
- 🚨 Arrange the Cards in Spreadsheet Order
- It’s crucial to arrange the NFC cards in the same order as they appear in the Google Sheets spreadsheet. This order will ensure that the correct album is played when a card is tapped on the RFID reader.
- Tap Album Cards onto the RFID Reader
- One by one, tap each album card in the order specified in the spreadsheet onto the RFID reader. The Serial Monitor will display the unique ID of each card, confirming that the Arduino can read them.
- Paste Card UIDs into the Spreadsheet
- After tapping all the album cards, copy the list of Unique IDs (UIDs) displayed in the Serial Monitor and paste them into the Card UID column (A) in the spreadsheet. Select and drag rows D3 - G3 down to copy the formula
- Repeat for Control Cards: Clear the Serial Monitor to prepare it for the next set of cards. Following the steps above, tap each control card onto the RFID reader, and its UID will be displayed in the Serial Monitor. Navigate to the Controllers tab in the spreadsheet and add the respective UIDs there.
These steps ensure that the RFID cards are properly associated with the correct albums and control actions. Whenever you want to add new albums, repeat the process by uploading this sketch and adding the new card UIDs to the spreadsheet!
Sketch 2: Authenticate Spotify
authenticate_spotify.inofile. To use the Spotify player with your Arduino board, you'll need to set up a Spotify app and authorize it for your project. This Arduino sketch establishes a web server on the board, enabling users to authenticate their Spotify app through the OAuth 2.0 authorization code flow. Once authenticated, the sketch retrieves the user's access token and refresh token from Spotify, which will enable us to successfully send API requests.
- Create Spotify App
- Visit the Spotify Developer Dashboard and log in with your Spotify account credentials.
- Once you're logged in, navigate to "Dashboard" and "Create an App".
- Give your app a name and description. For now, you can put dummy links in the “Website” and "Redirect URIs" fields.
- Go to “Settings” and copy your "Client ID" and "Client Secret” into the
arduino_secrets.hfile, along with your wifi network name and password.
- Get IP Address
- Upload the Arduino sketch to your board and open the Serial Monitor.
- Copy the IP address displayed on the Serial Monitor.
Please authenticate at <your_ip_address>
- Return to your Spotify app's settings, and replace the dummy links with the IP address in this format:
http://<your_ip_address>/redirect/. Save the changes.
- Authorizing Spotify
- Ensure your Arduino is connected to Arduino IoT Cloud by checking the Serial Monitor.
- Open a web browser and go to
http://<your_ip_address>/redirect/, using your board's IP address.
- You will see a web page hosted by your Arduino board, prompting you to authenticate Spotify. Click "Authenticate" to grant the necessary permissions. If successful, you will see "Authenticated!" on the web page.
- 🚨 Be sure to copy the refresh token displayed in the Serial Monitor and store it somewhere you can access later. This token will be used to obtain access tokens for Spotify API calls.
With these steps completed, your Arduino board will be authorized to interact with Spotify and send API calls. You won't need to repeat the authorization process unless your refresh token becomes invalid or you want to switch to a different Spotify app!
Sketch 3: Read NFC Card and Send Album to Spotify
- Copy Values to Arduino Secrets File
- Transfer the values from the
arduino_secrets.hfile in Sketch 2 to the
arduino_secrets.hfile in Sketch 3. Also include the refresh token you saved earlier into the variable provided.
- Include Album and Controller Information
- Copy the albumUIDs, albumURIs, controllerUIDs, and controlActions from the Google Sheets into the corresponding arrays in
album_info.h. This ensures that your sketch knows which NFC card corresponds to which album and controller action.
- Upload and Monitor the Sketch:
- Open the Serial Monitor and upload the main sketch to your Arduino board. Use the Serial Monitor to monitor the connection status to Arduino IoT Cloud, which may take a few minutes to establish.
- Connect to a Device on Spotify
- Go to Spotify on your phone/computer and connect to a device to activate the Spotify Player. This will be the only time you’ll need to use your device.
- Send Albums to Spotify
- Tap an NFC album card onto the RFID reader, and the sketch will send an API request to Spotify to play the corresponding album.
- Control the Spotify Player
- To change tracks or control the Spotify player, tap the NFC control cards on the RFID reader. Each control card corresponds to a specific action, such as play/pause, skip song, shuffle, or volume control.
You can now disconnect the Arduino from your computer and plug it into a wall charger for future use! Just be sure to connect to a device on Spotify before playing your albums each session. If you’d like to add more albums— you can add them to your spreadsheet, update the arrays in
album_info.h, and re-upload your sketch!
Display: RFID reader attached to the inside cover of a decorative book
Congratulations! You've successfully built your own modern day record player using Arduino and RFID technology. I hope you enjoyed this project and continue to find joy in it. Stay tuned on my YouTube channel for an upcoming tutorial on how to make the album sleeves to complement your project. Now, sit back, relax, and put your records on! 🎶
- Inspiration for the Project by Talaexe
- Arduino Uno - RFID / NFC Tutorial
- Arduino Datasheet & Board Diagram
- RFID RC522 Pinout Diagram
- Base code for Spotify APIs and Controllers
- Spotify API Documentation