An easy way to send your heartbeat to the Cloud using arduino

This cool (and very low price) sensor is attached on your ear and can detect your heart’s pulse through transmitting infrared light and checking the absorption variation caused by the blood flow on your ear lobe. The site of the products provides also the Arduino code for detecting the beats and calculating an average heart rate (in bpm  – beats per minute). The sensor comes with a grove connector, so setting up and running the code took less than 5 mins! (thanks again @seeedstudio for providing me with a complete Grove kit).

An easy way to send your heartbeat to the CloudAfter playing with it a while I realized that I could make a cool Cloud-based heart rate tracker by simply using an ADK board and my Android phone. This way I could be completely mobile (given that the 9V battery that powers the ADK board can last!).

I modified the Arduino code to send the heart rate to the Android using the ADB and made also a simple Android app that takes the heart rate and sends it to Cosm  (former Pachube) using the jpachube library.

Despite being very mobile (the cable is long enough to reach my pocket where both boards and mobile phone are) I am sure the graph-feed will stop being live quite soon (will either get bored, battery will die or will take it off to go to sleep…)

/************************* 2011 Seeedstudio **************************
* File Name : Heart rate sensor.pde
* Author : Seeedteam
* Version : V1.0
* Date : 30/12/2011
* Description : This program can be used to measure heart rate,
the lowest pulse in the program be set to 30.
*************************************************************************/
//Modified by @BuildingIoT
//for communication with Android
#include <SPI.h>
#include <Adb.h>
// Adb connection.
Connection * connection;
// Elapsed time for ADC sampling
long lastTime;
unsigned char pin = 13;
unsigned char counter=0;
unsigned int heart_rate=0;
unsigned long temp[21];
unsigned long sub=0;
volatile unsigned char state = LOW;
bool data_effect=true;
const int max_heartpluse_duty=2000;//you can change it follow your system's request.2000 meams 2 seconds. System return error if the duty overtrip 2 second.
void setup() {
pinMode(pin, OUTPUT);
Serial.begin(9600);
//Serial.println("Please put on the ear clip.");
delay(5000);//
array_init();
//Serial.println("Heart rate test begin.");
attachInterrupt(0, interrupt, RISING);//set interrupt 0,digital port 2
// Initialise the ADB subsystem.
ADB::init();
// Open an ADB stream to the phone's shell. Auto-reconnect
connection = ADB::addConnection("tcp:4567", true, adbEventHandler);
}
void loop() {
digitalWrite(pin, state);
}
void sum()//calculate the heart rate
{
if(data_effect)
{
heart_rate=1200000/(temp[20]-temp[0]);//60*20*1000/20_total_time
//Serial.print("Heart_rate_is:\t");
Serial.println(heart_rate);
connection->write(2, (uint8_t*)&heart_rate);
ADB::poll();
}
data_effect=1;//sign bit
}
void interrupt()
{
temp[counter]=millis();
state = !state;
//Serial.println(counter,DEC);
//Serial.println(temp[counter]);
switch(counter)
{
An easy way to send your heartbeat to the Cloud
case(0):
sub=temp[counter]-temp[20];
//Serial.println(sub);
break;
default:
sub=temp[counter]-temp[counter-1];
//Serial.println(sub);
break;
}
if(sub>max_heartpluse_duty)//set 2 seconds as max heart pluse duty
{
data_effect=0;//sign bit
counter=0;
Serial.println("Heart rate measure error,test will restart!" );
array_init();
}
if (counter==20&&data_effect)
{
counter=0;
sum();
}
else if(counter!=20&&data_effect)
counter++;
else
{
counter=0;
data_effect=1;
}
}
void array_init()
{
for(unsigned char i=0;i!=20;++i)
{
temp[i]=0;
}
temp[20]=millis();
}
// Event handler for the shell connection.
void adbEventHandler(Connection * connection, adb_eventType event, uint16_t length, uint8_t * data){}

 

For more detail: An easy way to send your heartbeat to the Cloud


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

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

Scroll to Top