There are three areas to "code" for this project.

  • First, we have the Arduino code that'll run on the Feather board.
  • Second, we have Adafruit IO feeds and dashboard to configure.
  • And lastly, we'll got to to set up applets that can trigger the Adafruit IO feeds.

Arduino Code

The program running on the Feather is pretty simple. It is adapted from two sample sketches. One that plays music using the Music Maker FeatherWing, and another that connects the board to WiFi and waits for commands from Adafruit IO.

First, make sure you're familiar with the setup and coding of the Feather board, by going through this guide and connecting to WiFi successfully.

Next, become familiar with playing MP3s with the Music Maker FeatherWing by following the setup in this guide.

Now, you're ready to download the Music Alert Box code and configure it to your needs.

Download this file and then unzip it and move the directory into your Arduino sketch folder.

The sketch contains two files. First, we'll look at the config.h file. Here, you need to change the IO_USERNAME to your Adafruit IO username, and the key to your Adafruit IO key.

You can find more info on this here.

Once you've made these changes, save the file.

/************************ Adafruit IO Config *******************************/

// visit if you need to create an account,
// or if you need your Adafruit IO key.
#define IO_USERNAME  "your adafruit io username"
#define IO_KEY       "your adafruit io key"

/******************************* WIFI **************************************/

// the AdafruitIO_WiFi client will work with the following boards:
//   - HUZZAH ESP8266 Breakout ->
//   - Feather HUZZAH ESP8266 ->
//   - Feather M0 WiFi ->
//   - Feather WICED ->

#define WIFI_SSID       "your wifi sside"
#define WIFI_PASS       "your wifi password"

// comment out the following two lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

/******************************* FONA **************************************/

// the AdafruitIO_FONA client will work with the following boards:
//   - Feather 32u4 FONA ->

// uncomment the following two lines for 32u4 FONA,
// and comment out the AdafruitIO_WiFi client in the WIFI section
// #include "AdafruitIO_FONA.h"

/**************************** ETHERNET ************************************/

// the AdafruitIO_Ethernet client will work with the following boards:
//   - Ethernet FeatherWing ->

// uncomment the following two lines for ethernet,
// and comment out the AdafruitIO_WiFi client in the WIFI section
// #include "AdafruitIO_Ethernet.h"
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);

Next, you'll change the MusicAlertBox.ino file to include the names of the .mp3 files you're using. Be sure to copy these to the SD card, and keep the names short (eight-dot-three format is a safe way to go). The names must match exactly between the files and their callouts in the code.

//WiFi Music Alert Box
// Uses Feather Huzzah ESP8266 WiFi board and Music Maker FeatherWing
// along with Adafruit IO and IFTTT to play triggered sound files
// written by John Park
// based on Todd Trece's Digital Input sample code
//MIT license
/************************** Configuration ***********************************/

// edit the config.h tab and enter your Adafruit IO credentials
// and any additional configuration needed for WiFi, cellular,
// or ethernet clients.
#include "config.h"

/************************ libraries *****************************************/
// include SPI, MP3 and SD libraries
#include <SPI.h>
#include <SD.h>
#include <Adafruit_VS1053.h>

/************************ Music Maker definitions ***************************/
// These are the pins used
#define VS1053_RESET   -1     // VS1053 reset pin (not used!)

// Feather ESP8266
  #define VS1053_CS      16     // VS1053 chip select pin (output)
  #define VS1053_DCS     15     // VS1053 Data/command select pin (output)
  #define CARDCS          2     // Card chip select pin
  #define VS1053_DREQ     0     // VS1053 Data request, ideally an Interrupt pin

Adafruit_VS1053_FilePlayer musicPlayer = 
  Adafruit_VS1053_FilePlayer(VS1053_RESET, VS1053_CS, VS1053_DCS, VS1053_DREQ, CARDCS);

/************************ Define Feeds**************************************/
// set up the 'song' feed
AdafruitIO_Feed *song = io.feed("music-player-01-song");
//set up the 'volume' feed
AdafruitIO_Feed *volume = io.feed("music-player-01-volume");
//set up the 'pause' feed
AdafruitIO_Feed *pause = io.feed("music-player-01-pause");

/************************ setup ********************************************/
void setup() {

  if (! musicPlayer.begin()) { // initialise the music player
     while (1);

  musicPlayer.sineTest(0x44, 500);// tone to indicate VS1053 is working
  if (!SD.begin(CARDCS)) {
    while (1);  // don't do anything more
  // Set volume for left, right channels. lower numbers == louder volume!

  musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT);  // DREQ int

  // set led pin as a digital output

  // start the serial connection

  // wait for serial monitor to open
  //while(! Serial);

  // connect to
  Serial.print("Connecting to Adafruit IO");

  // set up a message handler for each of the feeds.
  // e.g., the handleSongMessage function (defined below)
  // will be called whenever a "song message" is
  // received from adafruit io


  // wait for a connection
  while(io.status() < AIO_CONNECTED) {

  // we are connected


/************************ loop *********************************************/
void loop() {
  //; is required for all sketches.
  // it should always be present at the top of your loop
  // function. it keeps the client connected to
  //, and processes any incoming data;

/************************ handleSongMessage ********************************/
// this function is called whenever a 'song' feed message
// is received from Adafruit IO. it was attached to
// the 'song' feed in the setup() function above.
void handleSongMessage(AdafruitIO_Data *data) {

  Serial.print("song received <- ");

  // write the current state to the led
  else if(data->toInt()==2){
  else if(data->toInt()==3){
  else if(data->toInt()==4){
  else if(data->toInt()==5){
  else if(data->toInt()==6){
  else if(data->toInt()==7){
  else if(data->toInt()==8){
  else if(data->toInt()==9){
  else if(data->toInt()==10){
  else if(data->toInt()==11){
  else if(data->toInt()==12){
  else if(data->toInt()==13){
  else if(data->toInt()==14){
  Serial.print(" ");

/************************ handleVolume ************************************/
// this function is called whenever a 'volume' feed message
// is received from Adafruit IO. it was attached to
// the 'volume' feed in the setup() function above.
void handleVolumeMessage(AdafruitIO_Data *data) {

  Serial.print("volume received <- ");
    // since we are using the same function to handle
  // messages for two feeds, we can use feedName() in
  // order to find out which feed the message came from.
  Serial.print(" ");

  musicPlayer.setVolume(data->toInt(), data->toInt());


/************************ handlePauseMessage *******************************/
// this function is called whenever a 'pause' feed message
// is received from Adafruit IO. it was attached to
// the 'pause' feed in the setup() function above.
void handlePauseMessage(AdafruitIO_Data *data) {

  Serial.print("pause received <- ");

  // write the current state to the led
  else if(data->toInt()==0){
  Serial.print(" ");


Save and then upload the sketch to your Feather ESP8266 Huzzah and test it out. You should see the board connect to your WiFi network by checking the serial monitor.

Adafruit IO

Now, we can set up Adafruit IO to act as a WiFi connected playback UI for the Feather and its songs.

The Adafruit IO Basics: Digital Input guide is an excellent place to start to get an understanding of how the system works. Familiarize yourself with the guide, end even try out the example to get started. Then, we'll modify the feeds and dashboard for our needs.


For the WiFi Music Alert Box we'll set up three feeds: Song, Volume, and Pause. 

Create the Song Feed

Start by creating a new feed Named Music Alert Box Song. If you need help getting started with creating feeds on Adafruit IO, check out the Adafruit IO Feed Basics guide.

Edit the feed to adjust the key name if needed -- this is the name that will be used by the Arduino sketch to interact with the feed. In this case, the key is set to music-player-01-song. You can see this in the Arduino sketch where it says:

// set up the 'song' feed
AdafruitIO_Feed *song = io.feed("music-player-01-song");

Create two more feeds, Music Alert Box Volume, and Music Alert Box Pause. Each of these will be used to handle different kinds of data. use the key names seen here.


Create Dashboard

In order to assign meaning to the feeds you've created, make a new Dashboard called Music Alert Box. If you need help getting started with Dashboards on Adafruit IO, check out the Adafruit IO Dashboard Basics guide.

Create Song Blocks

Create a new block that will play a song when clicked. For this, you can use a momentary button block.

The pop up window will ask you to select to which feed to connect the button. In this case, we'll choose Music Alert Box Song feed by clicking the group/feed checkbox for that line, and then clicking Next Step.

In the Block Settings window that pops up, you can name the block, adjust the button text to the name of the song you want it to trigger, and give the Press Value a number that correlates to your Arduino sketch if statement. You can delete the Release Value, we won't use it in this case, and then click Create block

Your dashboard will now have on button on it. Click it and your song will play!

Add more buttons to correlate to each song, and then you can arrange them by clicking the gear icon on your dashboard.

Don't need a name over each button? Edit the button's Block Title to be a space character!

Create Volume Slider

You can create a slider element to control the volume. 

For this block, select the Music Alert Box Volume feed.

Adjust the block settings in the next popup window to match these.

Note: Volume on the Music Maker FeatherWing gets louder as the numbers get lower!

Test this out -- now as you play back songs you can adjust the volume.

Pause/Play Block

For fun, let's set up a block that can pause and play the songs! Create a new toggle block.

Choose the Music Alert Box Volume feed.

Use the title Pause/Play to label the block on the UI. Set the On text to 1 and the Off text to 0. These are the values that will be sent to the Feather when the block is clicked.

Stream Block

Lastly, we'll create a data stream block. This will allow us to see the values flowing from our button presses to the Feather.

Select all three Music Alert Box feeds.

Place the data feed block where you like. Now, you can see updates as your feed data changes.

If This then That - IFTTT

The third part of the setup is to trigger the songs using Internet alerts via IFTTT applets. These can be any of hundreds of possible triggering services! For example, Twitter, Date & Time, Flickr, YouTube, just to name a few.

If you haven't already, create an account on 

Once you have logged in, click on your user profile and choose, Services from the drop-down menu.

Click on "All service", then type "Adafruit" into the search bar, and then click on the Adafruit service icon.

Click the big, huge Connect button. Because how can you resist?

If you are logged into your account, you'll be asked to authorized the IFTTT connection. (If not, you need to first log into Adafruit.)

Now, back in IFTTT, you can create a new Applet. Click on My Applets and then click New Applet.

Click on the +this link.

Pick the Date & Time service.

Choose the Every hour at  trigger

Leave it set to 00 and click Create trigger.

That takes care of the if this, so on to the then that. Click the +that link.

Type adafruit into the search, then click on the Adafruit icon.

There's just the one option, Send data to Adafruit IO.

From the dropdown for Feed names, pick Music Alert Box Song. This tells the action to send data to that Adafruit IO feed. Then, type in a in the Data to save field. This is the number of the song you want to play on the hour. Then click Create action.

Click Finish because you're all done!

You can check that all of the connections between services are working properly by clicking the applet to expand its info, and then clicking Check now.

This guide was first published on Jun 21, 2017. It was last updated on Jun 21, 2017.

This page (Code It) was last updated on May 26, 2017.

Text editor powered by tinymce.