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.
Thank you.
Rich (BB code):
#include "Wire.h"
#include <LiquidCrystal.h>
#define HRMI_I2C_ADDR 127
#define HRMI_HR_ALG 1 // 1= average sample, 0 = raw sample
#define redLedPin 10
#define speaker 9
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup(){
setupHeartMonitor(HRMI_HR_ALG);
Serial.begin(9600);
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("Heart Rate Test");
lcd.setCursor(0,1);
lcd.print("Check Heart Rate");
pinMode(redLedPin, OUTPUT);
pinMode(speaker, OUTPUT);
digitalWrite(redLedPin, HIGH);
}
void loop(){
int heartRate = getHeartRate();
Serial.println(heartRate);
delay(1000); //just here to slow down the checking to once a second
if(getHeartRate()==0){
digitalWrite(redLedPin, HIGH);
lcd.setCursor(0,0);
lcd.print("Heart Rate Test");
lcd.setCursor(0,1);
lcd.print("Check Heart Rate");
}
else if ((getHeartRate() < 130)&&(getHeartRate() > 41)){
digitalWrite(redLedPin, HIGH);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Regular Heart Rate");
}
else{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Warning! Warning!");
lcd.setCursor(0,1);
lcd.print("Irregular Heart Rate");
digitalWrite(redLedPin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(200); // wait for a second
digitalWrite(redLedPin, LOW); // turn the LED off by making the voltage LOW
delay(200); // wait for a second
analogWrite(speaker,250);
delay(200);
digitalWrite(speaker, LOW);
delay(200);
lcd.clear();
}
}
void setupHeartMonitor(int type){
//setup the heartrate monitor
Wire.begin();
writeRegister(HRMI_I2C_ADDR, 0x53, type); // Configure the HRMI with the requested algorithm mode
}
int getHeartRate(){
//get and return heart rate
//returns 0 if we couldnt get the heart rate
byte i2cRspArray[3]; // I2C response array
i2cRspArray[2] = 0;
writeRegister(HRMI_I2C_ADDR, 0x47, 0x1); // Request a set of heart rate values
if (hrmiGetData(127, 3, i2cRspArray)) {
return i2cRspArray[2];
}
else{
return 0;
}
}
void writeRegister(int deviceAddress, byte address, byte val) {
//I2C command to send data to a specific address on the device
Wire.beginTransmission(deviceAddress); // start transmission to device
Wire.write(address); // send register address
Wire.write(val); // send value to write
Wire.endTransmission(); // end transmission
}
boolean hrmiGetData(byte addr, byte numBytes, byte* dataArray){
//Get data from heart rate monitor and fill dataArray byte with responce
//Returns true if it was able to get it, false if not
Wire.requestFrom(addr, numBytes);
if (Wire.available()) {
for (int i=0; i<numBytes; i++){
dataArray = Wire.read();
}
return true;
}
else{
return false;
}
}