# Heart Rate Badge

## Overview

http://youtu.be/eGz46KKPYCg

Build a badge to show the beat of your heart! This wearable project uses the Polar heart rate sensor, which you wear around your ribcage and it wirelessly transmits heart beats to the receiver chip included in our educational starter pack. The badge can be worn on your clothes or bag, and is held in place by a magnetic pin back. Make the heart-shaped NeoPixel version, or use one of our 8x8 LED matrices with i2c backpack to display your heart rate as a number or make your own bitmap animations.

![](https://cdn-learn.adafruit.com/assets/assets/000/009/618/medium800/flora_two-heart-rate-badges.jpg?1396893969)

# Heart Rate Badge

## Tools & Supplies

![](https://cdn-learn.adafruit.com/assets/assets/000/009/596/medium800/flora_adafruit-heart-rate-brooch-00.jpg?1396893495)

You will need the following items:

- [Polar Wireless heart sensor educational starter pack](http://www.adafruit.com/products/1077)
- [FLORA main board](http://www.adafruit.com/products/659)
- [150 mAh lipoly battery](http://www.adafruit.com/products/1317) (with [charger](http://www.adafruit.com/products/1304))
- Eight [FLORA NeoPixels](http://www.adafruit.com/products/1260) or [8x8 LED matrix w i2c backpack](http://www.adafruit.com/products/1049)
- [Magnetic pin back](http://www.adafruit.com/products/1170)
- [Sugru](http://www.adafruit.com/products/437)
- Thin stranded wire
- Double-stick tape or foam

Any entry level 'all-in-one' soldering iron that you might find at your local hardware store should work. As with most things in life, you get what you pay for.   
Upgrading to a higher end soldering iron setup, like the [Hakko FX-888 that we stock in our store](http://adafruit.com/products/180 "Link: http://adafruit.com/products/180"), will make soldering fun and easy.   
<u><br>Do not use a "ColdHeat" soldering iron</u>! They are not suitable for delicate electronics work and can damage the Flora ([see here](http://www.epemag.wimborne.co.uk/cold-soldering2.htm "Link: http://www.epemag.wimborne.co.uk/cold-soldering2.htm")).   
  
[Click here to buy our entry level adjustable 30W 110V soldering iron.](http://adafruit.com/products/180 "Link: http://adafruit.com/products/180")   
  
[Click here to upgrade to a Genuine Hakko FX-888 adjustable temperature soldering iron.](http://adafruit.com/products/303 "Link: http://adafruit.com/products/303")   
  
[Learn how to solder with tons of tutorials!](http://learn.adafruit.com/adafruit-guide-excellent-soldering "Link: http://learn.adafruit.com/adafruit-guide-excellent-soldering")

![flora_hakko-soldering-iron.jpg](https://cdn-learn.adafruit.com/assets/assets/000/009/611/medium640/flora_hakko-soldering-iron.jpg?1396893872)

![flora_simple-soldering-iron.jpg](https://cdn-learn.adafruit.com/assets/assets/000/009/612/medium640/flora_simple-soldering-iron.jpg?1396893883)

You will want rosin core, 60/40 solder. Good solder is a good thing. Bad solder leads to bridging and cold solder joints which can be tough to find.  
  
[Click here to buy a spool of leaded solder (recommended for beginners).](http://adafruit.com/products/145)  
  
[Click here to buy a spool of lead-free solder.](http://adafruit.com/products/734)

![flora_solder.jpg](https://cdn-learn.adafruit.com/assets/assets/000/009/613/medium640/flora_solder.jpg?1396893897)

You will need a good quality basic multimeter that can measure voltage and continuity.  
  
[Click here to buy a basic multimeter.](http://adafruit.com/products/71)  
  
[Click here to buy a top of the line multimeter.](http://adafruit.com/products/308)  
  
[Click here to buy a pocket multimeter.](http://adafruit.com/products/850)  
  
[Don't forget to learn how to use your multimeter too!](http://learn.adafruit.com/multimeters)

![flora_multimeter.jpg](https://cdn-learn.adafruit.com/assets/assets/000/009/614/medium640/flora_multimeter.jpg?1396893910)

Don't forget your [wire strippers](https://www.adafruit.com/products/527 "Link: https://www.adafruit.com/products/527"), [pliers](https://www.adafruit.com/products/146 "Link: https://www.adafruit.com/products/146"), and [flush snips](https://www.adafruit.com/products/152 "Link: https://www.adafruit.com/products/152")!

![flora_wire-strippers.jpg](https://cdn-learn.adafruit.com/assets/assets/000/009/615/medium640/flora_wire-strippers.jpg?1396893923)

![flora_snips.jpg](https://cdn-learn.adafruit.com/assets/assets/000/009/616/medium640/flora_snips.jpg?1396893937)

![flora_pliers.jpg](https://cdn-learn.adafruit.com/assets/assets/000/009/617/medium640/flora_pliers.jpg?1396893954)

# Heart Rate Badge

## Circuit Diagram

![](https://cdn-learn.adafruit.com/assets/assets/000/010/967/medium800/flora-heart-rate-badge-diagram-adafruit.jpg?1379077324)

Two versions! Make a heart-shaped display with eight FLORA NeoPixels, or use an 8x8 LED matrix with i2c backpack.

# Heart Rate Badge

## Build Circuit

Solder three small wires to the Polar heart rate receiver, and stick it to the FLORA main board with a piece of double-stick tape or foam.

![flora_adafruit-heart-rate-brooch-01.jpg](https://cdn-learn.adafruit.com/assets/assets/000/009/597/medium640/flora_adafruit-heart-rate-brooch-01.jpg?1396893529)

![flora_adafruit-heart-rate-brooch-02.jpg](https://cdn-learn.adafruit.com/assets/assets/000/009/599/medium640/flora_adafruit-heart-rate-brooch-02.jpg?1396893574)

![flora_adafruit-heart-rate-brooch-03.jpg](https://cdn-learn.adafruit.com/assets/assets/000/009/603/medium640/flora_adafruit-heart-rate-brooch-03.jpg?1396893640)

Wire up and solder the sensor to the FLORA main board according to the circuit diagram on the previous page.

![flora_adafruit-heart-rate-brooch-04.jpg](https://cdn-learn.adafruit.com/assets/assets/000/009/604/medium640/flora_adafruit-heart-rate-brooch-04.jpg?1396893711)

![flora_adafruit-heart-rate-brooch-05.jpg](https://cdn-learn.adafruit.com/assets/assets/000/009/605/medium640/flora_adafruit-heart-rate-brooch-05.jpg?1396893739)

Place a piece of tape over the sensor to prevent the pixel display from shorting its contacts. Lay out and solder together your heart-shaped pixel display according to the circuit diagram on the previous page, then solder the heart shape to VBATT, GND, and D12 on the FLORA main board.  
  
If using the LED matrix instead, solder it up according to the [LED Backpack guide](http://learn.adafruit.com/adafruit-led-backpack/), then wire it to FLORA's 3.3v, SCL, SDA, and GND pins according to the circuit diagram.

![flora_adafruit-heart-rate-brooch-06.jpg](https://cdn-learn.adafruit.com/assets/assets/000/009/606/medium640/flora_adafruit-heart-rate-brooch-06.jpg?1396893768)

![flora_adafruit-heart-rate-brooch-07.jpg](https://cdn-learn.adafruit.com/assets/assets/000/009/607/medium640/flora_adafruit-heart-rate-brooch-07.jpg?1396893805)

![](https://cdn-learn.adafruit.com/assets/assets/000/009/609/medium800/flora_adafruit-heart-rate-brooch-08.jpg?1396893851)

Stick the metal bar of the magnetic pin back on the back of the board, and use another piece of double-stick tape to attach the small lipoly battery right next to it.

# Heart Rate Badge

## Program it

Eight FLORA NeoPixels, arranged in the shape of a heart, are controlled by the following code according to incoming beats from the heart rate sensor. The LEDs flash brightly with each beat, visually representing your beating heart. Make sure you've got the [NeoPixel library](https://github.com/adafruit/Adafruit_NeoPixel) installed, then copy and paste the following code into the [Adafruit Arduino IDE](http://learn.adafruit.com/getting-started-with-flora/download-software "Link: http://learn.adafruit.com/getting-started-with-flora/download-software"):

```auto
/*
Heart Rate Badge with heart-shaped neopixel display
written by Becky Stern for Adafruit Industries
Based on sample code from http://learn.parallax.com/KickStart/28048
*/

#include &lt;Adafruit_NeoPixel.h&gt;

// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_RGB     Pixels are wired for RGB bitstream
//   NEO_GRB     Pixels are wired for GRB bitstream
//   NEO_KHZ400  400 KHz bitstream (e.g. FLORA pixels)
//   NEO_KHZ800  800 KHz bitstream (e.g. High Density LED strip)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, 12, NEO_GRB + NEO_KHZ800);

//Definitions  
const int HR_RX = 2;
byte oldSample, sample;

void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  colorWipe(strip.Color(20, 0, 0), 50); // Red
  
  Serial.begin(9600);
  pinMode (HR_RX, INPUT);  //Signal pin to input  
  
  Serial.println("Waiting for heart beat...");

 // Wait until a heart beat is detected  
  while (!digitalRead(HR_RX)) {};
  Serial.println ("Heart beat detected!");
}

void loop() {
  sample = digitalRead(HR_RX);  //Store signal output 
  if (sample &amp;&amp; (oldSample != sample)) {
    Serial.println("Beat");
    heartBeat();
  }
  oldSample = sample;           //Store last signal received 
  

for (volatile int i=0; i&lt;strip.numPixels(); i++){
      strip.setPixelColor(i, strip.Color(20, 0, 0)); 
    }
    strip.show();
}


// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i&lt;strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
  }
}

void heartBeat (){
  Serial.println("heartbeat");
for (volatile int i=0; i&lt;strip.numPixels(); i++){
      strip.setPixelColor(i, strip.Color(255, 0, 0)); 
    }
    strip.show();
   delay(10);
}
```

Here's some code for a different version of the badge, using our i2c 8x8 matrix display. It scrolls your current beats per minute across the display, great for taking with you on your workout. You will need the [GFX Library](https://github.com/adafruit/Adafruit-GFX-Library), [Adafruit BusIO](https://github.com/adafruit/Adafruit_BusIO) and the [LED Backpack Library](https://github.com/adafruit/Adafruit-LED-Backpack-Library).

```auto
/*
Heart Rate Badge with 8x8 i2c matrix
displays beats per minute
written by Becky Stern for Adafruit Industries
BPM calculation adapted from http://randomcontent.wolfnexus.net/RandomSite/arduino-hrm/
*/

#include &lt;Wire.h&gt;
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"

volatile int diff1 = 0;
volatile int diff2 = 0;
volatile int diff3 = 0;
volatile int diff4 = 0;
volatile int diff5 = 0;
volatile int diff6 = 0;
volatile int diff7 = 0;
volatile int diff8 = 0;
volatile int diff9 = 0;
volatile int diff10 = 0;
int BPM, BPMforDisplay;
unsigned long iterationCounter;
int animationPosition = 4;
byte oldSample, sample;
long pulsetime, lastpulsetime;

Adafruit_8x8matrix matrix = Adafruit_8x8matrix();

void setup() {
  Serial.begin(9600);
  Serial.println("8x8 LED Matrix Test");
  pinMode(10, INPUT);
  Serial.println("Waiting for heart beat...");

  //Wait until a heart beat is detected  
  while (!digitalRead(10)) {};
  Serial.println ("Heart beat detected!");
  matrix.begin(0x70);  // pass in the address
  matrix.setTextSize(1);
  matrix.setTextWrap(false);  // we dont want text to wrap so it scrolls nicely
  matrix.setTextColor(LED_ON);
}

void loop() {
/*
  sample = digitalRead(10);  //Store signal output 
  if (sample &amp;&amp; (oldSample != sample)) {
    Serial.print("Beat: ");
    Serial.println(BPM);
    HRpulse();
  }
  oldSample = sample;           //Store last signal received
  */
  if (animationPosition &lt; -20){
    animationPosition = 6;
    BPMforDisplay = BPM;
  }
      sample = digitalRead(10);  //Store signal output 
  if (sample &amp;&amp; (oldSample != sample)) {
    Serial.print("Beat: ");
    Serial.println(BPM);
    HRpulse();
  }
  oldSample = sample;           //Store last signal received
    if (iterationCounter % 900 == 0){
    
    matrix.clear();
    matrix.setCursor(animationPosition,0);
    matrix.print(BPMforDisplay);
    matrix.writeDisplay();
    //delay(100);
    animationPosition--;
  }
  
 iterationCounter++;
 //Serial.println(iterationCounter % 1200);
}

void HRpulse()
{
  pulsetime = millis();
  rollBuffer();
  diff1 = pulsetime - lastpulsetime;
  if (diff10 != 0) {
    BPM = 60000 / ((diff1 + diff2 + diff3 + diff4 + diff5 + diff6 + diff7 + diff8 + diff9 + diff10)/10);
  }
  lastpulsetime = pulsetime;
}

void rollBuffer()
{
  diff10 = diff9;
  diff9 = diff8;
  diff8 = diff7;
  diff7 = diff6;
  diff6 = diff5;
  diff5 = diff4;
  diff4 = diff3;
  diff3 = diff2;
  diff2 = diff1;
  diff1 = 0;
}
```

# Heart Rate Badge

## Wear it!

![](https://cdn-learn.adafruit.com/assets/assets/000/009/598/medium800/flora-heart-rate-badge-adafruit-becky-stern.jpg?1396893539)

The LEDs are bright enough to shine through a layer of fabric, so diffuse with your favorite fashions or wear as-is!


## Featured Products

### FLORA - Wearable electronic platform: Arduino-compatible

[FLORA - Wearable electronic platform: Arduino-compatible](https://www.adafruit.com/product/659)
FLORA is Adafruit's fully-featured wearable electronics platform. It's a round, sewable, Arduino-compatible microcontroller designed to empower amazing wearables projects.FLORA comes with Adafruit's support, [tutorials and...](http://learn.adafruit.com/category/flora)

In Stock
[Buy Now](https://www.adafruit.com/product/659)
[Related Guides to the Product](https://learn.adafruit.com/products/659/guides)
### Heart Rate Educational Starter Pack with Polar Wireless Sensors

[Heart Rate Educational Starter Pack with Polar Wireless Sensors](https://www.adafruit.com/product/1077)
 **Discontinued** - [you can grab this&nbsp;Pulse Sensor Amped instead!](https://www.adafruit.com/product/1093)

Read wireless heart-rate data into your electronics projects in under 10 minutes with this educational experimentation kit for Polar wireless heart rate...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/1077)
[Related Guides to the Product](https://learn.adafruit.com/products/1077/guides)
### Flora RGB Smart NeoPixel version 3 - Pack of 4

[Flora RGB Smart NeoPixel version 3 - Pack of 4](https://www.adafruit.com/product/1260)
What's a wearable project without LEDs? Our favorite part of the Flora platform is these tiny smart pixels. Designed specifically for wearables, these updated Flora NeoPixels have ultra-cool technology: these ultra-bright LEDs have a constant-current driver cooked right into the LED...

Out of Stock
[Buy Now](https://www.adafruit.com/product/1260)
[Related Guides to the Product](https://learn.adafruit.com/products/1260/guides)
### Lithium Ion Polymer Battery - 3.7v 150mAh

[Lithium Ion Polymer Battery - 3.7v 150mAh](https://www.adafruit.com/product/1317)
Lithium-ion polymer (also known as 'lipo' or 'lipoly') batteries are thin, light, and powerful. The output ranges from 4.2V when completely charged to 3.7V. This battery has a capacity of 150mAh for a total of about 0.6 Wh. If you need a larger battery, <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/1317)
[Related Guides to the Product](https://learn.adafruit.com/products/1317/guides)
### Adafruit Micro Lipo - USB LiIon/LiPoly charger

[Adafruit Micro Lipo - USB LiIon/LiPoly charger](https://www.adafruit.com/product/1304)
Oh so adorable, this is the tiniest little lipo charger, so handy you can keep it any project box! Its also easy to use. Simply plug in the gold plated contacts into any USB port and a 3.7V/4.2V lithium polymer or lithium ion rechargeable battery into the JST plug on the other end. There are...

In Stock
[Buy Now](https://www.adafruit.com/product/1304)
[Related Guides to the Product](https://learn.adafruit.com/products/1304/guides)
### Adafruit Small 1.2" 8x8 LED Matrix w/I2C Backpack - Red

[Adafruit Small 1.2" 8x8 LED Matrix w/I2C Backpack - Red](https://www.adafruit.com/product/1049)
What's better than a single LED? Lots of LEDs! A fun way to make a small display is to use an [8x8 matrix](https://www.adafruit.com/category/37_88) or a [4-digit 7-segment display](https://www.adafruit.com/category/37_103). Matrices like these are...

Out of Stock
[Buy Now](https://www.adafruit.com/product/1049)
[Related Guides to the Product](https://learn.adafruit.com/products/1049/guides)
### Magnetic Pin Back

[Magnetic Pin Back](https://www.adafruit.com/product/1170)
These magnetic pin backs have two pieces: a metal bar with adhesive strip and a plastic piece with two strong rare-earth magnets. Affix the metal bar to your FLORA projects-- it's just the right size! Then attach your FLORA project to any garment without poking holes in your clothes. The...

Out of Stock
[Buy Now](https://www.adafruit.com/product/1170)
[Related Guides to the Product](https://learn.adafruit.com/products/1170/guides)
### Sugru - Black and White Pack

[Sugru - Black and White Pack](https://www.adafruit.com/product/437)
Discontinued - **you can grab the&nbsp;** [Hand-Moldable Plastic - Low Temperature Thermoplastic - 100g Bag](https://www.adafruit.com/product/2504) **&nbsp;instead!&nbsp;**

Sugru! Soft-touch silicone rubber that molds and sets permanently. Sticks to aluminum, steel,...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/437)
[Related Guides to the Product](https://learn.adafruit.com/products/437/guides)

## Related Guides

- [Adafruit LED Backpacks](https://learn.adafruit.com/adafruit-led-backpack.md)
- [PianoGlove](https://learn.adafruit.com/pianoglove.md)
- [FLORA TV-B-Gone](https://learn.adafruit.com/flora-tv-b-gone.md)
- [Pathfinder Robot Companion](https://learn.adafruit.com/pathfinder.md)
- [Washing Wearable Electronics](https://learn.adafruit.com/washing-wearable-electronics.md)
- [Magic Storybook with ChatGPT](https://learn.adafruit.com/magic-storybook-with-chatgpt.md)
- [Light-Activated Pixel Heart](https://learn.adafruit.com/light-activated-pixel-heart.md)
- [Adafruit NeoPixel Überguide](https://learn.adafruit.com/adafruit-neopixel-uberguide.md)
- [Wireless Control Button for WLED Projects](https://learn.adafruit.com/wireless-control-button-for-wled-projects.md)
- [Gemma 3D Printed Tree Topper](https://learn.adafruit.com/gemma-3d-printed-tree-topper.md)
- [Cartoon Network and Make Code - Rose Quartz Shield Umbrella](https://learn.adafruit.com/cartoon-network-and-make-code-rose-quartz-shield-umbrella.md)
- [LED Backpack Displays on Raspberry Pi and BeagleBone Black](https://learn.adafruit.com/led-backpack-displays-on-raspberry-pi-and-beaglebone-black.md)
- [Capacitive Touch with Conductive Fabric & Flora](https://learn.adafruit.com/capacitive-touch-with-conductive-fabric-and-flora.md)
- [Glowing WhoVille Hat](https://learn.adafruit.com/glowing-whoville-hat.md)
- [Glue Stick Light Pipe Sculpture](https://learn.adafruit.com/glue-stick-archway.md)
- [Snow Globe with Circuit Playground Bluefruit](https://learn.adafruit.com/snow-globe-bluefruit-cpb.md)
