How do I get my core to play an MP3?

Hi Everyone -

I’m working on a small project, and I have limited experience with programming and the Spark system. I’m hooking up my Spark core to two ultrasonic rangefinders, pointed in different directions. When the rangefinder detects something, I want a corresponding MP3 to play from the computer speakers that I have. Each rangefinder would trigger a different MP3.

I am fine with the MP3s playing from my laptop. I can put the files in the library for the .ino that I’m going to write, if need be. I was just wondering if anyone had any experience with something like this.


I’m using a VS1053 shield from adafruit:

and the ported library from McTristan (a fork of the original port by Paul Kourany (I think)):

It works a treat!

If you don’t mind playing the sounds from your laptop then a Node.js app which listening for two different Spark Events and then plays the MP3s would work for you! You’d have an app running on your laptop and some code on your Spark Core pushing out events

Hi Harrison,

That sounds promising. Do you have any more specifics for a beginner?

Here’s a brief starter:

Playing sounds/music:

Spark’s Node API Wrapper:

Some Psuedo Code:
On Core:

On Node (something LIKE this. This is untested and probably won’t even compile but should give you the right idea)

var spark = require('spark');
play = require('play-audio');

//example code to re open the SSE stream when it ends
 var openStream = function() {

    //Get your event stream
    var req = spark.getEventStream(false, 'mine', function(data) {
      console.log("Event: " + JSON.stringify(data));

      var eventName = data['eventName'] // This is probably wrong. Use the above console.log to figure out the correct array key
      if (eventName == "SND_PLAY")


    req.on('end', function() {
        console.log("ended!  re-opening in 1 second...");
        setTimeout(openStream, 1000);

spark.on('login', function() {

spark.login({ username: '', password: 'password' }, function(err, body) {
  console.log('API call login completed on callback:', body);