# Heart rate sensor BH1790

**URL:** <https://forum.arduino.cc/t/heart-rate-sensor-bh1790/898291>\
**Category:** Sensors\
**Created:** [August 23, 2021, 9:26am UTC](https://forum.arduino.cc/t/heart-rate-sensor-bh1790/898291 "2021-08-23T09:26:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![loukh](https://avatars.discourse-cdn.com/v4/letter/l/db5fbb/32.png) [@loukh](https://forum.arduino.cc/u/loukh)\
**Post date:** [August 23, 2021, 9:26am UTC](https://forum.arduino.cc/t/heart-rate-sensor-bh1790/898291/1 "2021-08-23T09:26:39Z")

</div>

Hi ,  
i am working on a project and am using a heart rate sensor BH1790 GLC, i used the code given by  
the constructor but i get nothing in the output;  
am using an arduino UNO card with my optical sensor , can anyone help plz;  
Thnx in advance

---

<div class="post-metadata">

**Author:** ![Idahowalker](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/idahowalker/32/238858_2.png) [@Idahowalker](https://forum.arduino.cc/u/Idahowalker)\
**Post date:** [August 23, 2021, 10:52am UTC](https://forum.arduino.cc/t/heart-rate-sensor-bh1790/898291/2 "2021-08-23T10:52:51Z")

</div>

> [@loukh](#):
>
> can anyone help plz;

Do you have code that is written, that you could post, so that others can see what was done, now this could be the best part, someone could look at, quite possibly, and see see the issue you are having, and give suggestions on possible fixes.

Oh, and those things called schematics, could you post one of your project, those fritznuts things are not schematics.

And as a bonus, could you post a few images of your wired project?

> [@loukh](#):
>
> but i get nothing in the output;

And you know that's not a proper way to describe your issue, right?

---

<div class="post-metadata">

**Author:** ![loukh](https://avatars.discourse-cdn.com/v4/letter/l/db5fbb/32.png) [@loukh](https://forum.arduino.cc/u/loukh)\
**Post date:** [August 23, 2021, 12:33pm UTC](https://forum.arduino.cc/t/heart-rate-sensor-bh1790/898291/3 "2021-08-23T12:33:54Z")

</div>

Hi , thank you for response  
the code is the Following ;

#include \<Wire.h\>  
#include \<BH1790GLC.h\>  
#include \<FlexiTimer2.h\>

extern "C" {  
#include \<hr\_bh1790.h\>  
}

#define SAMPLING\_CNT\_32HZ (32)

BH1790GLC bh1790glc;  
volatile bool timer\_flg;  
void timer\_isr(void);

static uint8\_t s\_cnt\_freq = 0;

void setup() {

uint16\_t ret16 = ERROR\_NONE;

timer\_flg = false;  
Serial.begin(115200);  
while (!Serial);

Wire.begin();  
Wire.setClock(400000L);

s\_cnt\_freq = 0;

ret16 = hr\_bh1790\_Init();  
if (ret16 == ERROR\_NONE) {  
Serial.println(F("BPM, wearing"));  
FlexiTimer2::stop();  
FlexiTimer2::set(250, 1.0/8000, timer\_isr); // 32Hz timer  
FlexiTimer2::start();

```
ret16 = hr_bh1790_StartMeasure();
if (ret16 != ERROR_NONE) {
  Serial.println(F("Error: hr_bh1790_StartMeasure function"));
  Serial.print(F("ret16 = "));
  Serial.println(ret16, HEX);      
}

```

} else {  
Serial.println(F("Error: hr\_bh1790\_Init function"));  
Serial.print(F("ret16 = "));  
Serial.println(ret16, HEX);  
}  
}

void loop() {

uint8\_t bpm = 0U;  
uint8\_t wearing = 0U;  
uint16\_t ret16 = ERROR\_NONE;

if (timer\_flg) {  
ret16 = hr\_bh1790\_Calc(s\_cnt\_freq);  
if (ret16 == ERROR\_NONE) {  
s\_cnt\_freq++;  
if (s\_cnt\_freq \>= SAMPLING\_CNT\_32HZ) {  
s\_cnt\_freq = 0;  
hr\_bh1790\_GetData(&bpm, &wearing);  
Serial.print(bpm, DEC);  
Serial.print(F(","));  
Serial.println(wearing, DEC);  
}  
} else {  
Serial.println(F("Error: hr\_bh1790\_Calc function"));  
Serial.print(F("ret16 = "));  
Serial.println(ret16, HEX);  
}  
timer\_flg = false;  
}  
}

void timer\_isr(void) {  
timer\_flg = true;  
}

int8\_t bh1790\_Write(uint8\_t adr, uint8\_t \*data, uint8\_t size)  
{  
byte rc = 0;  
int8\_t ret = 0;

rc = bh1790glc.write(adr, data, size);  
if (rc == 0) {  
ret = BH1790\_RC\_OK;  
} else {  
ret = BH1790\_RC\_I2C\_ERR;  
}

return (ret);  
}

int8\_t bh1790\_Read(uint8\_t adr, uint8\_t \*data, uint8\_t size)  
{  
byte rc = 0;  
int8\_t ret = 0;

rc = bh1790glc.read(adr, data, size);  
if (rc == 0) {  
ret = BH1790\_RC\_OK;  
} else {  
ret = BH1790\_RC\_I2C\_ERR;  
}

return (ret);  
}

 ![Sans titre](https://europe1.discourse-cdn.com/arduino/original/4X/c/4/d/c4d734e290e601ae6f2ad81cf7fccd3c889b1145.png)

---

<div class="post-metadata">

**Author:** ![loukh](https://avatars.discourse-cdn.com/v4/letter/l/db5fbb/32.png) [@loukh](https://forum.arduino.cc/u/loukh)\
**Post date:** [August 23, 2021, 12:36pm UTC](https://forum.arduino.cc/t/heart-rate-sensor-bh1790/898291/4 "2021-08-23T12:36:28Z")

</div>

i have tried also an other code but its gives the same results  
#include \<Wire.h\>  
#include \<BH1790GLC.h\>  
#include \<FlexiTimer2.h\>  
#include \<stdio.h\>

BH1790GLC bh1790glc;  
volatile bool timer\_flg;  
char str[100];

void timer\_isr(void);

void setup() {  
byte rc;

timer\_flg = false;  
Serial.begin(115200);  
while (!Serial);

Wire.begin();  
Wire.setClock(400000L);

rc = bh1790glc.init();  
if (rc != 0) {  
Serial.println("BH1790 initialize failed");  
} else {  
Serial.println("LEDON Data, LEDOFF Data");  
FlexiTimer2::stop();  
FlexiTimer2::set(250, 1.0/8000, timer\_isr); // 32Hz timer  
FlexiTimer2::start();  
}  
}

void loop() {  
byte rc;  
unsigned short val[2];

if (timer\_flg) {  
rc = bh1790glc.get\_val(val);  
if (rc == 0) {  
sprintf(str, "%d, %d\n", val[1], val[0]);  
Serial.print(str);  
}  
timer\_flg = false;  
}

}

void timer\_isr(void) {  
timer\_flg = true;  
}

---

<div class="post-metadata">

**Author:** ![Idahowalker](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/idahowalker/32/238858_2.png) [@Idahowalker](https://forum.arduino.cc/u/Idahowalker)\
**Post date:** [August 23, 2021, 12:54pm UTC](https://forum.arduino.cc/t/heart-rate-sensor-bh1790/898291/5 "2021-08-23T12:54:48Z")

</div>

You skipped the part about posting your code in code tags. Could you edit your posted code and add in code tags?

[Honestly, if you'd read the hints posted on this site, we'd be much further along with troubleshooting your issue. Give it a try read and do some reading by clicky clicky](https://forum.arduino.cc/t/read-this-before-posting-a-programming-question/95349)

What did you set your Monitors serial baud rate at?

---

<div class="post-metadata">

**Author:** ![Idahowalker](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/idahowalker/32/238858_2.png) [@Idahowalker](https://forum.arduino.cc/u/Idahowalker)\
**Post date:** [August 23, 2021, 1:00pm UTC](https://forum.arduino.cc/t/heart-rate-sensor-bh1790/898291/6 "2021-08-23T13:00:32Z")

</div>

> [@loukh](#):
>
> void timer\_isr(void) {  
> timer\_flg = true;  
> }

Put the ISR before the setup().

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [December 21, 2021, 1:01pm UTC](https://forum.arduino.cc/t/heart-rate-sensor-bh1790/898291/7 "2021-12-21T13:01:19Z")

</div>

Closed on December 21, 2021, 1:01pm UTC

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.
