Heart Rate Badge

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 heartbeats to the receiver chip included in the 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 an 8×8 LED matrix with an i2c backpack to display your heart rate as a number or make your own bitmap animations.

Supplies

You will need the following items:

To keep up with what I’m working on, follow me on YouTubeInstagramTwitterPinterest, and subscribe to my newsletter. As an Amazon Associate I earn from qualifying purchases you make using my affiliate links.

Circuit Diagram

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

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.

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

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, then wire it to FLORA’s 3.3v, SCL, SDA, and GND pins according to the circuit diagram.

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.

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 installed, then copy and paste the following code into the Arduino IDE:

/*
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 <Adafruit_NeoPixel.h>

// 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 && (oldSample != sample)) {
    Serial.println("Beat");
    heartBeat();
  }
  oldSample = sample;           //Store last signal received 
  

for (volatile int i=0; i<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<strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
  }
}

void heartBeat (){
  Serial.println("heartbeat");
for (volatile int i=0; i<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 an i2c 8×8 matrix display. It scrolls your current beats per minute across the display, which is great for taking with you on your workout. You will need the GFX LibraryAdafruit BusIO, and the LED Backpack Library.

/*
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 <Wire.h>
#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 && (oldSample != sample)) {
    Serial.print("Beat: ");
    Serial.println(BPM);
    HRpulse();
  }
  oldSample = sample;           //Store last signal received
  */
  if (animationPosition < -20){
    animationPosition = 6;
    BPMforDisplay = BPM;
  }
      sample = digitalRead(10);  //Store signal output 
  if (sample && (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;
}

Wear it!

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

Originally posted to Adafruit.


You may be interested in some of my other work:

To keep up with what I’m working on, follow me on YouTubeInstagramTwitterPinterest, and subscribe to my newsletter.

%d bloggers like this: