Hacking Mindfulness with an Arduino and the iPhone

Meditation VS Web

For the past six months, I’ve been working on measuring human physiology during meditation. Most notably, instead of focusing on measuring using an EEG (to record brainwaves), I’ve been focusing on measuring the changes in physiology caused by the autonomic nervous system.

And so, I started out building an Arduino based device to measure galvanic skin response, skin temperature, and heart rate. Within a few months, I found the most major physiological changes from meditation occur in the heart rate.

With this in mind, I built an iPhone app called buddha mind to measure and see the changes meditation makes on your heart rate.

This app was an amazing success, and within the first hour made the front page of Hacker News and brought over 4,000 people to the launch site.

Well, now we’ve reached another breakthrough. We’ve developed the very first version of an algorithm to measure and know when you entered a meditative state based upon heart rate variability.

We figured the best way to demo this new algorithm would be by controlling and manipulating a physical object with meditation. With that in mind, we built this light orb:

How it Works

This light orb is a DMX controlled strip of RGB LEDs house inside of a glass orb. It’s receiving DMX data from an Arduino triggered by an Electric Imp.

The Electric Imp is a really exciting project, and this build would have never been possible without it. An Electric Imp allows you to connect any device to the internet, and exposes and entire API for it. The code is fairly straightforward (written in Squirrel), and easy enough to debug based upon the insane complexity going on behind the scenes.

The buddha mind sends an API call to the Electric Imp as soon as the Bluetooth LE heart rate monitor is connected in app. This starts the pulsing white light of the orb.

Once the user starts meditating, our algorithm tracks the heart data, waiting for the heart rate variability to reach a threshold. Once reached, buddha mind makes API call to the Electric Imp to tell it to begin sending the Arduino the trigger for running the meditation lights.

Here’s what the Squirrel code for the Electric Imp looks like:

val <- 0.4; // Default value to send with PWM
 
function blink()
{
        hardware.pin1.write(val); // Update the value sent with PWM on pin 1
}
 
}
class input extends InputPort // This is how we create an API input
{
  name = "LED control"
  type = "number"
  function set(value)
  {
         server.show(value);
         val = value;
         blink();
  }
}
imp.configure("First Program", [input()], []); // Also need to register input for API here.
hardware.pin1.configure(PWM_OUT, 1.0/500.0, 1.0); // Configure pin1 for PWM to send values to Arduino
blink();

We send data to this Electric Imp with a post request. It looks like this example, only not with curl in app obviously:

curl --form "value=0.4" https://electricimpssecreturlgoeshere.com/12949332/

The Arduino then reads this PWM and creates and sends signals via the DMX output. This is also very straightforward (psuedocode ish stuff below):

// Before all of this is the awesome code setting up DMX from Triniculo's Attic. It allows us to use the DMXinit, etc. 
// functions.
 
void setup()
{
  DMXinit(1,512); // Initializes DMX output with all 512 slots and starting with 1
  pinMode(4,INPUT);
  pinMode(13,OUTPUT); // LED for status
 
}
 
void loop()
{
  float duration = pulseIn(4, HIGH);
  if (duration < 200) {  // We've received a low signal (0.1 from the Imp)
  for(x = 0; x < 256; x++)
  {
    red = (int) (sin(frequency*x + 0) * 127 + 128);
    green = (int) (sin(frequency*x + 2) * 127 + 128);
    blue = (int) (sin(frequency*x + 4) * 127 + 128);
    DMXput(1,red);  // Fade channel 1 from 0-255
    DMXput(2,green);  // DMXput takes the channel number and the value 
    DMXput(3,blue);
    delay(20); // Take 2.55 seconds (2550 milliseconds) to execute fade 
  }
 }
  // Fill in the rest of the code here for the triggers you'd like. Cut for brevity here.
}

The electronic layout is very simple, thanks to the DMX shield from Triniculo’s Attic. It consists of a single connection from the Electric Imp to the Arduino, using pulse width modulation to let the Arduino know what DMX states should be generated.

The DMX data from the Arduino is then sent to a DMX driver, which decodes and powers a strip of RGB LEDs.

The exciting thing about this build is that it’s 100% expandable. We only controlled a single orb, but with DMX we could control and light an entire room with multiple effects. DMX 512 allows up to 70 individually controlled lights! (!!!)

This project will be displayed and demoed in Jacksonville for the BeOneSpark event. You’ll be able to try meditating and changing the lights yourself.

We hope to see everyone there.

If you want to sign up to buy this Orb on indiegogo, to find out when the Android version of the app will be released, or to just hear more about what I’m working on, I’d appreciate it if you signed up for my mailing list.

I won’t spam ya, promise!

Fill out my online form.

15 thoughts on “Hacking Mindfulness with an Arduino and the iPhone

  1. Pingback: Measuring meditation with a heart rate

  2. Pingback: Measuring meditation with a heart rate - RaspberryPiBoards

  3. Pingback: Measuring meditation with a heart rate | Daily IT News on IT BlogIT Blog

  4. Hi there; this is pretty cool but have you tested it with anyone whom does not breathe any more deeply than normal (i.e. just focusing on the breath as it is) while meditating?

    The reason I ask is I noticed you were breathing very deeply and I was curious to know if what you’re seeing is an effect of the deep breathing or actually entering any kind of meditation. A quick google found this artcicle / paper http://www.ccjm.org/content/76/Suppl_2/S37.full

    It suggests that this approach will not work if breathing is not deeper, nor if the user has certain medical conditions / is on certain medications.

    • So with my project, I’m very specifically focusing on one type of meditation, and that is mindfulness.

      Every user I’ve tested this with so far has the same response. I haven’t tried it out on people with breathing conditions, although I’m working on a new piece of hardware that should work for them too.

      Thanks for posting the link, and I’ll look further into it.

  5. Pingback: Measuring meditation with a heart rate | Make, Electronics projects, electronic Circuits, DIY projects, Microcontroller Projects - makeelectronic.com

  6. I already have an ANT-compatible heart rate strap and a Digifit-branded ANT-to-iPhone sensor. If this is a “small matter of programming” I’d be really thrilled to hop on. If not, I guess I need a new heart rate strap. (I also have some “Wild Divine” products and their “Lightstone” sensor.)

    • Hey Al,
      Yes, I actually began development a few months ago on that very same Pulse Sensor. The problem I had with it was inconsistent results, something they’ve improved on since then with a newer version.

      I’m currently working on a project which would incorporate the Pusle Sensor and be cross platform. I suggest you sign up for my mailing list if you want to be notified when that becomes available.

      Thanks for the suggestion.

  7. Pingback: Concentrarse vs. Navegar por la Web | Noticias CEU

  8. I love the way you mixed meditation and eletronics. Amazing work, thanks for sharing.
    Greetings from Argentina!

  9. Pingback: Tu corazón es una KPI | Hello Google | Posicionamiento Web en Google | Consultoria SEO | Desarrollo Web | SEM

  10. Pingback: Measuring meditation through heart rateMUR | MUR

  11. All the gizmos on the internet, including the Heartmath one seem to think that a regular beat is good, but nothing is further form the truth. The way to tell is a good (resilient) heartbeat vs a bad one is by measuring the statistical self-similarity (think statistical fractals) of the HRV. A healthy heart has a lot of variability, but when looked at from the fractal/self-similarity perspective it is quite consistent (all the information and free code/algorithms here: http://www.physionet.org/tutorials/fmnc/node7.html ).
    Highly regular heartbeat is a sign of aging or disease. Completely chaotical heartbeat is also bad. Fractal scaled (following a power law) variability is a sign of vigor, adaptability, resilience., and a characteristic of different dimensions (static or dynamic) in complex adaptive systems found in nature.
    Hope this helps.

Leave a Reply to thornad Cancel reply

Your email address will not be published. Required fields are marked *