Zen Pen: Mindfulness & Meditation Device
by mogrinz in Circuits > Gadgets
209 Views, 1 Favorites, 0 Comments
Zen Pen: Mindfulness & Meditation Device
"A healthy heart is not a metronome." (source)
I was shocked to learn this. Growing up, I had always heard that 60bpm (beats per minute) was a good thing. But as I learned more about stress and meditation, I discovered that Heart Rate Variability (HRV) was the real indicator. HRV is the change in the time intervals between adjacent heartbeats.
Think about it: When you reach for that jar in a tall cabinet, or bend over to pick up that Lego you just stepped on, your heart must make minor adjustments because you are suddenly calling on your body to perform more work. It's not heavy cardio, but it is different than just sitting sedentary on a couch.
As I learned more about HRV, I discovered that scientists have known about it's importance since at least the 1960's. Based on multiple studies, poor HRV can be correlated to disease, obesity, and even mortality. Good HRV on the other hand, has been correlated to all kinds of positive outcomes including weight loss, increased concentration, and even success quitting smoking. I'll link to a few helpful studies below.
Stress is Everywhere.
This is one thing we can all agree upon. Kids are stressed at school, and adults are stressed at work and at home. Stress is bad for your health for many reasons, and stress can have a negative impact on HRV (study).
Breathing is the answer!
Practitioners of meditation already know breath control is important. Studies have shown that breathing at a rate of 5 to 6 breaths per minute (source) can help synchronize your heart rate and breath rate into a state known as Coherence. The challenge is, most of us are too busy to take the time to focus on our breathing pattern. What's worse - in a stressful situation many of us start breathing at intervals that actually make us fell worse.
Enter the Zen Pen
The Zen Pen helps you achieve a balance between two parts of the autonomic nervous system (the parasympathetic and sympathetic).
As you hold it in your hand (the design is ambidextrous) with your thumb over the sensor, and it will calculate your HRV. The nozzle of the Zen Pen will slowly brighten and fade to correspond to that ideal 6bpm breathing cycle. As you match your breathing to the gentle, pulsing glow and your Coherence improves, the Zen Pen will change colors as progress though 9 "levels".
Here's the really cool feature: You can insert a pen or pencil into the Zen Pen and use it while you are taking a test, doing a crossword, coloring a picture, etc. You get unobtrusive, direct coaching on your stress and breathing without interrupting the task at hand.
Further reading you may find interesting
There are literally tons of articles on the web about the importance of HRV, Coherence, and a 6bpm (breaths-per-minute) breathing cycle. I've linked to a few interesting sources below:
What Does Heart Rate Variability Mean (health.com)
Supplies
- Arduino Pro Micro (Amazon link) It's possible to use other Arduino controllers, but the case for this project will only fit the Pro Micro.
- Optical Heart-Rate Sensor: MAX30102 (Amazon link)
- 3 WS2812 individual LEDs (Sparkfun sells a 5-pack here). You can also use 3 separate Neopixels LEDs (Amazon link). You can even cut individual LEDs from a strip like this one
- Some thin, flexible hook-up wire. I like this assortment on Amazon
- A simple 12mm SPDT switch (example on Amazon)
- A 3.7v 290MAH Battery (I am using this tiny one) It's possible some other 3.7v batteries might fit inside the case.
- Small battery connectors. I am using JST 1.25mm (Amazon link)
- A simple charger for the internal battery (such as this one on Amazon)
- Access to a 3D printer (or 3D printing service) and a soldering iron
- A hot glue gun and some superglue for assembly. Accelerant for the superglue is really handy (link).
Prototype
Any time you are building a device - particularly something "consumer friendly" - extensive prototyping & testing is required. I didn't want to share this project without showing all the different shapes, designs, sensors, etc. that I tried and abandoned for one reason or another. The picture only scratches the surface: there were also plenty of tweaks to the code until I was happy I had something that worked and was easy to use.
The Case
The case is designed to be 3D printing using either an FDM (filament) or SLA (resin) printer. For the cleanest results on the body (for an FDM printer), I find the orientation in the attached image to be the best approach.
Feel free to use different filament colors for the body, or apply a coat of paint to customize it to your liking.
I usually print the nozzle in the orientation shown, which means some clean-up sanding after I remove all the support material. Feel free to print it whatever way gets you results you are satisfied with. It's very important to print the nozzle in clear filament (FDM) or translucent resign (SLA) because the glow from the LEDs needs to be visible to the user. If you print it in a solid material, the soft, pulsing glow which encourages proper breathing won't be noticeable.
Once you've printed the 3 pieces, you can glue the nozzle to the bottom of the case using some superglue.
Bonus: I made an alternative "Iron Man-style" version of the top. You'll have to hand-paint it (and it screws, rather than snaps to the bottom), but I thought kids might like it.
The Circuit
The circuit diagram in this step will give you an overview of how all the parts connect, but let's talk though the steps.
Of course, you're not going to use a breadboard in the final version; you're going to want to solder the circuit together because you're going to stick it into the case. But I like to start on a breadboard so I know I've got everything wired correctly (see attached photo). How long should you make all the wires? If you use 3" or so I think you'll be fine. That's partly why you want to use the lightweight hookup wire in the Shopping List. It will bunch up easily when you tuck it into the case.
Let's start with the battery. Your battery might not come with the right type of connector. If that's the case, snip off what's currently on there and solder on the JST 2 pin male connector. Cover your connections with a little electrical tape or some heat-shrink tubing.
Next, take the JST 2 pin female connector. Solder the red wire to one of the outer contacts on the switch. Solder the black wire to the GND contact on the Pro Micro.
Solder a red wire from the center contact on the switch to the RAW input on the Pro Micro. Do not connect the battery to the Pro Micro at this time.
Now let's connect the MAX30102 sensor. The VIN contact on the sensor connects to the VCC contact on the Pro Micro. GND on the Max30102 connects to GND on the Pro Micro. SCL on the Sensor connects to Pin 3 on the Micro. Finally, SDA on the Sensor connects to the Micro's Pin 2. The INT contact on the Sensor is not used.
We need the sensor to stick out in the case as much as possible - so look at the attached images for good and bad examples. If your solder connections are higher than the sensor itself - that's going to prevent the sensor from detecting heartbeats accurately. You can always grind down a tall connection using a nail file or a Dremel. You want it almost flush to the circuit board.
Let there be light!
There are 3 WS2812 LEDs used on the Zen Pen. Two of them will be used to provide the glow for the Nozzle. One LED mounts to the top of the shell and will blink in sync with the user's heartbeat. It's a quick way of letting the user know the device is working correctly (otherwise, they may need to reposition their thumb over the sensor).
In the attached circuit diagram, the leftmost LED will be the one that shows the heartbeat, and the two on the right will mount into the nozzle. In the closeup photo I provide, you will see that I used almost no wire between the 2 LEDs on the right and soldered their pins directly together. It's important to have 2-3" of wire on the left LED though to make it easy to open and close the case.
Pay very close attention to the LEDs when you connect them. There are 2 short pins on one side, and 2 long pins on the other. If you place the LEDs on a table with the short pins on the left, then connect the 2nd pin from the left on each LED to VCC on the Pro Micro. Connect the 3rd pin from the left on each LED to GND.
The LEDs are wired in a series, which each one basically passing data along to the next one in the chain. If you have all 3 LEDs laid out on a table (with the short pins on the left side), connect Pin 1 on the first LED to the Micro's Pin 4.
Connect Pin 4 on the first LED to Pin 1 on the second LED. And finally, connect Pin 4 of the second LED to Pin 1 on the third LED. Whew! All the hard stuff is over. While your soldering iron cools down, cool down yourself with a nice beverage.
Setting Up the Arduino Pro Micro
We'll need to load the Zen Pen code onto the Pro Micro. If you haven't used a Pro Micro before (or any Arduino for that matter), this can seem a little daunting at first. Don't be intimidated: the Arduino project homepage has lots of guides to help you get started and there are many Instructables and YouTube videos if you get stuck.
Once you have set up your Arduino environment to program the Pro Micro, you need to install two additional libraries to work with the ZenPen: The SparkFun MAX3010x Pulse and Proximity Sensor Library and the FastLED Library.
Generally, the process for installing a library on the Arduino IDE is very simple. Under the Tools menu, select Manage Libraries and a dialog will display with a Search box. Type in "MAX30105" in the search field, and from the list of results, click the latest version and press the Install button.
Next, type "FastLED" and from the list of results choose the latest version and click Install. There are lot of results for this search; you want the basic one written by Daniel Garcia.
Time for a test!
After you've built the Zen Pen circuit and prepared your Arduino programming environment is a good time for a simple test. Upload the ZP_Test_Program sketch attached to this step.
If everything is wired & working corrected, you should see the red light on the pulse sensor blink on and off. The 3 LEDs you connected should blink Red, Green, and Blue (in that order). If they blink in the order Green, Red, Blue, read the comment on line 25, edit the sketch, and re-upload it to the board.
If some of the LEDs are not blinking, examine the circuit closely and make sure you have all the wires properly connected to the correct endpoints.
Unplug the Arduino from your computer and connect the battery (make sure it's charged). If the lights do not come on, flick the power switch you connected. You should get the same behavior from the LEDs.
A note about the attached image
I like to test my projects on a breadboard before I solder them. The attached photo is of my circuit running the test program before I soldered everything together. Note that I am using a strip of 3 WS2812 LEDs. These need to be cut apart with some wire soldered in between them in the final assembly.
Downloads
Putting It All Together
Once you've verified the LEDs and sensor are wired correctly and working, it's time to complete the assembly of the Zen Pen device.
Code
Before we start gluing things together, load the Zen Pen code attached to this step onto the device (ZenPen_Instructable.ino)
Top of the Case
Next, check the fit of the sensor into the top of the case. The sensor should be almost even with the case itself. If your solder joints are too high and preventing a tight fit, trim them down using a nail file or Dremel.
You can secure the sensor with some hot glue on the corners. My preferred method is to cut a short piece of PLA filament, place it across the back of the sensor, and secure the ends with super glue (see picture).
The first LED in the series will blink in time with the user's pulse. It also gets secured to the top of the case, just behind the tiny opening. I use a dab of hot glue to hold it in place.
Nozzle
The second two LEDs mount into the circular openings in the nozzle. You don't have to push them all the way in. See the sample picture for how I've mounted them. Secure them with some hot glue or super glue.
Bottom of the Case
Mount the switch in the small opening provided. Don't use super glue here - it's too easy to drip a little into the switch and ruin it. I use my favorite method again: A snip of PLA filament holding it in place and glued at each end to the case.
Slide the Pro Micro into the case and secure it with hot glue or PLA filament (see picture). Make sure that the USB port is facing towards the opening. We want to allow a USB cable to be hooked up in case we want to collect data from the device in the future, or power it over USB instead of a battery.
If the battery isn't already connected, plug it in now (make sure it's charged first) and tuck it gently inside the case, opposite the Pro Micro.
Snap it together
The top of the case has a small lip, and you should be able to carefully snap the top and bottom together to complete the assembly. There are also two optional holes in the bottom which you can use with two small self-tapping screws to secure the halves.
Downloads
The Code
Let's review the code itself, and what it does. After all, this is the heart of the project (pun intended).
Theory of Operation
The first thing we need to do is detect the user's heartbeat so we can start collecting data. The Zen Pen nozzle will start off Red (pulsing in and out to that 6bpm healthy breathing cycle).
In a loop, we read a raw value from the MAX30105 library using the .getIR() function. Then, we pass this value to the .checkForBeat() function (also part of the MAX30105 library) to determine if a heartbeat is detected. If so, a couple of things happen:
- The LED on the top of the case will blink in synchronization with the user's pulse
- We record the time of the current heartbeat. We also take the difference between the current heartbeat and the last one detected to calculate the IBI (intra-beat interval)
Next, we use the IBI to create a Coherence score. Recall that Coherence represents a synchronization between your heart rate and breathing rhythm. We're trying to steer the user towards a sine wave-like HRV pattern at a very specific interval correlated with reduced stress and anxiety (source).
Way back in the late 60's, Russian scientist Evgeny Vaschillo was involved with studying how breathing could help cosmonauts handle the physical and mental stress of working in space. He later expanded that work to involve fighter pilots and Olympic athletes (source).
Along the way he made this important discovery that "Relaxed breathing at about 6 b/m produces a spike of heart rate variability at about 0.1 Hz and tends to maximize most other measures of heart rate variability in most people."
What does "0.1 Hertz" mean? Hertz is the number of cycles per second. At this stage, we are not graphing the measurement of the pulse itself, but of the variation in the IBI to measure our progress towards that "ideal" cycle.
Side note: Observant viewers of the code will note that it stores a series of readings (in sets of 20), calculates their Standard Deviation and Root Mean Square of Successive Differences between normal heartbeats (RMSSD) (source) and prints them to the serial output of the Zen Pen. This code was part of several experimental measurements I conducted; I left it in (along with some other debugging output) for future researchers to potentially use.
Using the Zen Pen
Optional: Insert a pencil or pen into the Zen Pen. If the pencil is loose, wrap a little tape around it.
Turn on the Zen Pen - the nozzle should immediately be a slowly pulsing in red. Hold it in your hand with your thumb gently over the sensor. Once a pulse is detected, the light on the top of the case should start blinking in sync with your heartbeat. I find it helpful to use two fingers on my opposite hand to take my pulse in my neck. If your heartbeat isn't detected after 15 seconds or so, try repositioning your thumb. You don't need to use any pressure on the sensor.
Try to not move your thumb around too much if you are writing with the Zen Pen. If your heartbeat can't be detected, you will drop back to the lowest level (red).
As your Coherence score improves (or declines), we change the color of the nozzle's LEDs according to this scale (from worst -> best)
- Red (or, no reading)
- Dark Blue
- Green
- Yellow
- Light Purple
- Cyan
- Orange
- Dark Purple
- Light Blue
- White
It's not critical to memorize the order of the colors. With regular use you'll start to associate particular colors with being more relaxed and know when you are making progress or falling backwards. Initially, you'll probably get excited when you see the colors change and that may undo some of your progress! Stick with it and you'll be able to predict the color changes based as you feel yourself become more relaxed.
Coherence does not necessarily imply a lowering of your heart rate. We could measure that with a simple pulse metric. What you are trying to achieve is a change in heart rhythm to achieve a balance between two parts of the autonomic nervous system (the parasympathetic and sympathetic).
Recharging
The charger in the Shopping List can be used to re-charge the battery when necessary. Alternatively, you can power the Zen Pen over the USB connection from either a computer or a portable battery.
The Future
If you're reading this for the first time, I know it probably sounds like crazy, pseudo-science stuff. I was skeptical at first myself. But the more I looked into it, the more credible research I found. I've included lots of "source" links throughout this Instructable so you can learn more.
Whether you use it while writing or as a standalone device, with practice the Zen Pen should help improve your physical and mental performance through proper breathing and improved HRV & Coherence.
From a hardware perspective, possible enhancements include using additional sensors (i.e., temperature) or feedback mechanisms (i.e., an internal buzzer or speaker). Allowing the device to be charged directly over USB would be convenient (let me know in the comments if you want this!) Software-wise, there are many different directions the project could go. The processing power of the Pro Micro is limited, so storing readings for export and further analysis would be interesting.
Thanks for checking out this project. I would love to hear about your experiences with the Zen Pen, and I look forward to reading your comments!