Heart rate sensor device

In this page I’m going to show the design and creation of and heartbeat sensor for the Privacy Seed project.

Initial research: measuring heartbeat

A short research about Fitness trackers showed that many devices use today an “optical heart-rate” sensor.
See: https://www.digitaltrends.com/wearables/whats-inside-fitness-tracker-anyway/

These sensors measure the heart rate using light. Various LEDs shine a light through the skin and a close optical sensor detects the light bouncing back.
Since oxigenated blood absorbs different light wavelength, measuring fluctuations in the light detected can be translated into heart rate.
This process is called Pulse Oximetry.

Screenshot_3_Oxy_and_Deoxy_Hemoglobin_absorption_spectra Source Adrian Curtin - WikiPedia

Various well documented projects already show how to do this. See for example:

  • Implementing pulse oximeter by Raivis Strogonovs:
    This guide show how to use raw sensor light response data to measure heartbeat.
  • Particle and Pulse Ox Sensor by SparkFun:
    This show how a small board can use an integrated solution for MAX3010x and provides arduino libraries for using it.

A different series of sensor can come with external LED (eg. MAX8614x) or the detect different ranges of lights (eg. MAX30105 for smoke detection too) I decided therefore to build my sensor based on a MAX30101 sensor:

IMG_3_heart_sensor_MAX30101EFD

Heart rate sensor test device (1st try - failure)

A quick look at the MAX30101 datasheet shows that the sensor needs a I2C bus and 1.8VCC logic conversion for SDA/SCL but still needs 5V for the LEDs.

I started building a test board during the week 13 (networking) to test the I2C communication (and add this sensor on a bus with the accelerometer).
Here I document the forst (failed) construction of the heart rate device.

Because of the lack of 1.8V regulators in our lab I tried to implement the VCC reduction with a simple voltage divider.

Screenshot_3_heart_sensor_voltage_divider

For the SDA/SCL I used a similar solution to the ove for the ADXL343(see link) with a voltage level converter on the board from 5V to 1.8V.

Here is the final board schematics and PCB:

Screenshot_3_heart_sensor_schema Screenshot_3_heart_sensor_PCB

And here the board

IMG_3_heart_sensor_stuffed_board

A first test trying to use the AdaFruit libraries and an Arduino board showed that the sensor was not responsing to I2C read requests.
I decided to investigate with an oscilloscope and re-soldering the sensor.

I ended up breaking one of the sensor traces and two of the pins on the sensor… :sob::sob:

IMG_3_heart_sensor_broken_trace

Heart rate sensor test device (2nd try - failure)

I decided to give it a second try leaving the voltage regulator components out of the sensor board and try this time to create a board that could later fit in the heart shape.

Here a voltage digital conversion board: IMG_3.1_heart_sensor_voltage_conversion_board

Here the smaller board and moved the header on the other side of the board.

IMG_3.2_heart_sensor_board_2nd_try IMG_3.3_heart_sensor_board_2nd_try

At this point I failed again soldering of the sensor that started melting under the heat gun… so I run out of sensors and had to order new ones… :sob::sob:

Heart rate sensor test device (3rd try - failure)

(updates 09/06/2018)

While waiting for the sensors to arrive I started working on better looking designs for the PCB that could fit also in the heart shape.

From the last tests at the oscillator before the final meltdown I started doubting also about the voltage divider solution and decided to order some 1.8V regulators as well. So I’ve been waiting for the regulators to be shipped.

Screenshot_3.1_heart_sensor_simplified

IMG_3.3_heart_sensor_board_3nd_try

This simplified heartrate sensor is supposed to be controlled by a new board with a microcontroller that now integrate the digital voltage converters for the I2C bus.
This board below is meant to be integrated inside the heart shape (see documentation) and integrates an RGB LED for visual feedback.

Screenshot_3.4_heart_sensor_master_board_schema

Screenshot_3.4_heart_sensor_master_board_pcb

IMG_3.4_heart_sensor_master_board_stuffed

I spent lot of time to test if these board were working together. In short summary all the trials made:

  1. Initially checking the new microcontroller board to controll this sensor. I noticed that the serial port was not working via the FDTI cable. I later realised that I used the wrong FTDI header pin to send the serial data.
    I started anyway debugging the board via the I2C bus and an Arduino board listening to it. I managed to get the LED on the microcontroller board work correctly but no luck from the sensor getting confusing error messages.

  2. I put aside the new microcontroller board and started testing via Arduino for convenience and faster feedback. By then I had already created a separate mini board with a 1.8V regulatore and the digital voltage converters ony that could be paired with an arduino board to help testing the sensor in simplified conditions.

Screenshot_3.5_voltage_converter_schema

Screenshot_3.5_voltage_converter_pcb

IMG_3.5_voltage_converter

I got the code and libraries to work with more confidence. No response from the heartrate sensor …still no luck.

  1. While checking the signals on the mini regulator board with a meter I noticed that the new 1.8V regulators pinout is different!
    I didn’t check the datasheet (SHAME ON ME!) and just assumend they had the same pinout on the other regulators just because they came in the same packaging (I know, I’m embarassed by assuming this…). So with a little hack I soldered them upside-down: now the measured signals with the meter on the board became correct.
    Now a bit better, but still no luck to make the sensor working…

  2. While digging in the code the failure I also noticed that the Sparkfun sensor library for the MAX30101 had a bug that didn’t return the correct error code during the sensor initialization. I fixed it and made a pull request that got then included in the library. :)
    Better error messages now, but still no luck to make the sensor working…

  3. I tried soldering and unsoldering the sensor chip a couple of times. At least once I thought I had a pretty good and safe soldering… but started fearing I might have burned the chip by putting it on a 5V source pin instead of 1.8V at least once. I tried to replace the sensor as well with a new one. Still no luck…

  4. I tried changing the 10k pullup resitors with some 4.99k and use the EXACT same capacitors sizes as in the Sparkfun reference board board for the MAX30105 sensor. I thought this would make little difference but was an easy thing to try: Still no luck…

  5. At this point I had another revelation… while observing thet the SDA and SCL signals looking very bad on the oscillator… I thought that is maybe not my scarce confidence in using the oscillator and removing noise from the signals, but they might be actually very bad:

IMG_3.6_heart_sensor_I2C_channels_oscilloscope

I started digging in the datasheet of the NMOSFET that we have in the fab inventory.
They are not switching when the gate is driven at 1.8V! :sob: :sob: In fact the recommended “Drive Voltage” range is between 4.5V-10V. The very minimum threshold “Vgs(th)” is 2.5V. For this reason I was lucky enough to use them previously in a 3.3V converter event if they are not ideal for this. But definitley are not going to work with a 1.8V gate source.

This is now a blocking issue until I get the new NMOSFET shipped by digikey.

Heart rate sensor test device (4th try …it works!)

As last try in preparation for the final presentation I fallback to the option of using a SparkFun MAX30105 board.

This worked straight away when testing it with an Arduino!!

IMG_3.7_heart_sensor_sparkfun_board

Initially to access the sensor via an ATtiny84 microcontroller I choose the library SoftwareWire that could allow me to use any pin of the ATtiny for the I2C bus.
While plugging to my heart rate master board I experineced the issue of not being able to get a response from the sensor. :(

I decided to try the TinyWireM and hack my board with a jumper wire to use the dedicated SDA/SCL pins that come with hardware support on the ATtiny. These are respectively the PA6/PA4 pins.

Analising the sensor data

TODO: DOCUMENT SOURCE CODE…

Heart rate sensor test device (5th try …)

TODO: WORK IN PROGRESS…

Final version of the boards and Downloads

I finally made an additional iteration of my boards:

For the sensor board:

  • I reduced the sensor pad depth to help placing the sensor.
  • I added a small non-connected trace to help giving a visual alignment of the sensors
  • I connected together the pads 9-10 that were both connected to VCC (they broke during one of the milling process because too thin)
  • I slightly reduced the board size and made it more simmetric

Screenshot_3.10_heartrate_sensor_board_schema

Screenshot_3.11_heartrate_sensor_board_pcb

Download KiCAD project and GCode for sensor board (.zip archive: KiCAD project, .png and .rml files)

For heart rate microcontroller master board:

  • I removed the 5V regulator to avoid voltage drop when the supply is already exactly 5V (I measured 4.7V on VCC line.
  • I removed the external resonator: 8Mhz internal clock is enough to read the I2C bus at full speed using the dedicated pins.
  • I changed the pins for the I2C bus and as a consequence also for the RGB led

Screenshot_3.12_heartrate_master_board_schema

Screenshot_3.13_heartrate_master_board_pcb

Download KiCAD project and GCode for heart rate master board (.zip archive: KiCAD project, .png and .rml files)

Source code for the heart rate master board (.zip archive: C++ / .ino Arduino sketches - TODO)

Lessons learned

  1. Be careful when de-soldering small components pull them more gently to not break them.
  2. Keep attention to the detail of the circuit design. I should probably learn better ways to simulate these circuits with the parts we have in the inventory.
  3. Remember to review all components datasheet and choices when working in different voltage conditions.
  4. When components are not available in the fablab inventory the feedback loops become very slow: consider this in planning and try local providers for quick small orders.
  5. It is generally more convenient to use the dedicated SDA/SCL pins of ATtiny with I2C hardware support.

Next steps

  • Rebuild a smaller master board without the serial bus (not needed for debugging), without the 5V regulator and with a nicer design to fit in the heart shape.