Build a Modern Day Record Player with Arduino and RFID Technology
Build a Modern Day Record Player with Arduino and RFID Technology

Build a Modern Day Record Player with Arduino and RFID Technology

image

August 8, 2023 by Ellie Nguyen

Intro

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

image

Clone the GitHub Repo

icon
Download the code from the GitHub repository onto your local machine. It contains 3 sketches that you will upload to your Arduino board and the wiring diagram to reference when configuring our hardware.

Connecting Arduino MKR 1010 to RC522 RFID Reader

image
  1. 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.
  2. Use the wiring diagram to connect jumper cables to the corresponding pins on both devices.
    • These connections will enable seamless communication and data transfer, allowing your Arduino project to interact with the RFID reader effectively.
  3. Plug the USB cable into your Arduino board and connect it to your computer. If all of the wiring configuration is successful:
    1. The Arduino should have solid green and orange lights.
    2. The RFID reader should have a solid red light.
    3. image

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.

  1. 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.
  2. 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.
  3. image
    image
    image
  4. Arduino IDE: Download the Arduino IDE, where you'll write and upload sketches to your Arduino board. In the IDE:
    1. Install the Arduino SAMD Boards in the Boards Manager
    2. In the Library Manager, add the following libraries: ArduinoJson by Benoit, ArduinoHttpClient by Arduino, and MFRC522 by GitHub Community
    3. 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.

image
  1. 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.
  2. Leave the Card UID column (A) blank for now. You will update it in the next step!

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

icon
Open the get_card_uid.ino file. 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.

  1. Upload & Monitor the Sketch
    1. Upload the sketch to the Arduino board. Then, open the Serial Monitor to establish communication with the board and view messages and debugging information.
  2. Prepare the NFC Cards
    1. 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.
    2. image
  3. 🚨 Arrange the Cards in Spreadsheet Order
    1. 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.
  4. Tap Album Cards onto the RFID Reader
    1. 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.
  5. Paste Card UIDs into the Spreadsheet
    1. 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
    2. image
      image
  6. 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

icon
Open the authenticate_spotify.ino file. 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.

  1. Create Spotify App
    1. Visit the Spotify Developer Dashboard and log in with your Spotify account credentials.
    2. Once you're logged in, navigate to "Dashboard" and "Create an App".
    3. Give your app a name and description. For now, you can put dummy links in the “Website” and "Redirect URIs" fields.
    4. Go to “Settings” and copy your "Client ID" and "Client Secret” into the arduino_secrets.h file, along with your wifi network name and password.
    5. image
  2. Get IP Address
    1. Upload the Arduino sketch to your board and open the Serial Monitor.
    2. Copy the IP address displayed on the Serial Monitor. Please authenticate at <your_ip_address>
    3. 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.
  3. Authorizing Spotify
    1. Ensure your Arduino is connected to Arduino IoT Cloud by checking the Serial Monitor.
    2. image
    3. Open a web browser and go to http://<your_ip_address>/redirect/, using your board's IP address.
    4. 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.
    5. 🚨 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

icon
Finally our main sketch! When an NFC card is tapped, you’ll send API requests to either play an album or control the player.

  1. Copy Values to Arduino Secrets File
    1. Transfer the values from the arduino_secrets.h file in Sketch 2 to the arduino_secrets.h file in Sketch 3. Also include the refresh token you saved earlier into the variable provided.
  2. Include Album and Controller Information
    1. 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.
  3. Upload and Monitor the Sketch:
    1. 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.
    2. image
  4. Connect to a Device on Spotify
    1. 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.
    2. image
  5. Send Albums to Spotify
    1. Tap an NFC album card onto the RFID reader, and the sketch will send an API request to Spotify to play the corresponding album.
  6. Control the Spotify Player
    1. 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!

Wrapping Up

image

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! 🎶

Sources

icon
I took bits and pieces of each of these in order to put this project together. Thank you to all of the original creators!

Connect with Me

image

Other places to find me:

🚨 Looking for a creative and dedicated engineer to join your team? I’m open for hire!

☕️ Let’s have a coffee chat!

💭 For questions or comments:

  • holistictech.io@gmail.com