Help with Bluetooth Heart Rate Monitor

Discussion in 'The Projects Forum' started by Eim, May 22, 2014.

  1. Eim

    Thread Starter New Member

    Dec 28, 2012
    5
    0
    Hi all. I am building a Bluetooth heart rate monitor using an arduino and a HC-05 Bluetooth module. I need to send the results of the heart rate via Bluetooth to my android. I have the code done for the heart rate monitor with a warning system but cant figure out how to write the code to send the heart rate results through the Bluetooth module. Any hep would be much appreciated. Here is the code I am using so far.
    Code ( (Unknown Language)):
    1.  
    2.  
    3. #include "Wire.h"
    4. #include <LiquidCrystal.h>
    5. #define HRMI_I2C_ADDR      127
    6. #define HRMI_HR_ALG        1   // 1= average sample, 0 = raw sample
    7. #define redLedPin 10
    8. #define speaker 9
    9. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
    10.  void setup(){
    11.   setupHeartMonitor(HRMI_HR_ALG);
    12.   Serial.begin(9600);
    13.  
    14.  lcd.begin(16, 2);
    15.  lcd.setCursor(0,0);
    16.  lcd.print("Heart Rate Test");
    17.  lcd.setCursor(0,1);
    18.  lcd.print("Check Heart Rate");
    19.  pinMode(redLedPin, OUTPUT);  
    20.  pinMode(speaker, OUTPUT);
    21.  digitalWrite(redLedPin, HIGH);
    22.   }
    23.  void loop(){
    24.    int heartRate = getHeartRate();
    25.   Serial.println(heartRate);
    26.    delay(1000); //just here to slow down the checking to once a second
    27.  
    28.  if(getHeartRate()==0){
    29.    digitalWrite(redLedPin, HIGH);  
    30.    lcd.setCursor(0,0);
    31.    lcd.print("Heart Rate Test");
    32.    lcd.setCursor(0,1);
    33.    lcd.print("Check Heart Rate");
    34.  }
    35.  
    36.  
    37.  else if ((getHeartRate() < 130)&&(getHeartRate() > 41)){
    38.    digitalWrite(redLedPin, HIGH);
    39.    lcd.clear();
    40.    lcd.setCursor(0,0);
    41.    lcd.print("Regular Heart Rate");
    42.  }
    43.  
    44.  else{
    45.    lcd.clear();
    46.    lcd.setCursor(0,0);
    47.    lcd.print("Warning! Warning!");
    48.    lcd.setCursor(0,1);
    49.    lcd.print("Irregular Heart Rate");
    50.    digitalWrite(redLedPin, HIGH);   // turn the LED on (HIGH is the voltage level)
    51.    delay(200);               // wait for a second
    52.    digitalWrite(redLedPin, LOW);    // turn the LED off by making the voltage LOW
    53.    delay(200);               // wait for a second
    54.    analogWrite(speaker,250);
    55.    delay(200);
    56.    digitalWrite(speaker, LOW);
    57.    delay(200);
    58.    lcd.clear();
    59. }
    60. }
    61.  
    62. void setupHeartMonitor(int type){
    63.   //setup the heartrate monitor
    64.   Wire.begin();
    65.   writeRegister(HRMI_I2C_ADDR, 0x53, type); // Configure the HRMI with the requested algorithm mode
    66. }
    67.  int getHeartRate(){
    68.   //get and return heart rate
    69.   //returns 0 if we couldnt get the heart rate
    70.   byte i2cRspArray[3]; // I2C response array
    71.   i2cRspArray[2] = 0;
    72.    writeRegister(HRMI_I2C_ADDR,  0x47, 0x1); // Request a set of heart rate values
    73.    if (hrmiGetData(127, 3, i2cRspArray)) {
    74.     return i2cRspArray[2];
    75.   }
    76.   else{
    77.     return 0;
    78.   }
    79. }
    80.  void writeRegister(int deviceAddress, byte address, byte val) {
    81.   //I2C command to send data to a specific address on the device
    82.   Wire.beginTransmission(deviceAddress); // start transmission to device
    83.   Wire.write(address);       // send register address
    84.   Wire.write(val);         // send value to write
    85.   Wire.endTransmission();     // end transmission
    86. }
    87.  boolean hrmiGetData(byte addr, byte numBytes, byte* dataArray){
    88.   //Get data from heart rate monitor and fill dataArray byte with responce
    89.   //Returns true if it was able to get it, false if not
    90.   Wire.requestFrom(addr, numBytes);
    91.   if (Wire.available()) {
    92.      for (int i=0; i<numBytes; i++){
    93.       dataArray[i] = Wire.read();
    94.     }
    95.      return true;
    96.   }
    97.   else{
    98.     return false;
    99.   }
    100. }
    101.  [/i]
    Thank you.
     
  2. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    You communicate with the HC-05 via the UART protocol.

    There's even an instructable on it (not that I normally condone the misinformation regularly given on that site).

    Google has tons of results for "Arduino HC-05".
     
Loading...