Categories

Arduino and MAX30100 oximetry and heart-rate monitor sensor example

The MAX30100 is an integrated pulse oximetry and heart-rate monitor sensor solution. It combines two LEDs, a photodetector, optimized optics, and low-noise analog signal processing to detect pulse oximetry and heart-rate signals.

The MAX30100 operates from 1.8V and 3.3V power supplies and can be powered down through software with negligible standby current, permitting the power supply to remain connected at all times.

MAX30100-Sensor-Module

MAX30100-Sensor-Module

Key Features

  • Complete Pulse Oximeter and Heart-Rate Sensor Solution Simplifies Design
    • Integrated LEDs, Photo Sensor, and High-Performance Analog Front-End
    • Tiny 5.6mm x 2.8mm x 1.2mm 14-Pin Optically Enhanced System-in-Package
  • Ultra-Low-Power Operation Increases Battery Life for Wearable Devices
    • Programmable Sample Rate and LED Current for Power Savings
    • Ultra-Low Shutdown Current (0.7µA, typ)
  • Advanced Functionality Improves Measurement Performance
    • High SNR Provides Robust Motion Artifact Resilience
    • Integrated Ambient Light Cancellation
    • High Sample Rate Capability
    • Fast Data Output Capability

 

Connection

Arduino Module Pin
5v Vin
Gnd Gnd
SDA SDA
SCL SCL

 

Code

You will need the library from https://github.com/oxullo/Arduino-MAX30100 and import it into the Arduino IDE

This is the minimal example which worked with my module

#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
 
#define REPORTING_PERIOD_MS     1000
 
// PulseOximeter is the higher level interface to the sensor
// it offers:
//  * beat detection reporting
//  * heart rate calculation
//  * SpO2 (oxidation level) calculation
PulseOximeter pox;
 
uint32_t tsLastReport = 0;
 
// Callback (registered below) fired when a pulse is detected
void onBeatDetected()
{
    Serial.println("Beat!");
}
 
void setup()
{
    Serial.begin(115200);
 
    Serial.print("Initializing pulse oximeter..");
 
    // Initialize the PulseOximeter instance
    // Failures are generally due to an improper I2C wiring, missing power supply
    // or wrong target chip
    if (!pox.begin()) {
        Serial.println("FAILED");
        for(;;);
    } else {
        Serial.println("SUCCESS");
    }
 
    // The default current for the IR LED is 50mA and it could be changed
    //   by uncommenting the following line. Check MAX30100_Registers.h for all the
    //   available options.
    // pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
 
    // Register a callback for the beat detection
    pox.setOnBeatDetectedCallback(onBeatDetected);
}
 
void loop()
{
    // Make sure to call update as fast as possible
    pox.update();
 
    // Asynchronously dump heart rate and oxidation levels to the serial
    // For both, a value of 0 means "invalid"
    if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
        Serial.print("Heart rate:");
        Serial.print(pox.getHeartRate());
        Serial.print("bpm / SpO2:");
        Serial.print(pox.getSpO2());
        Serial.println("%");
 
        tsLastReport = millis();
    }
}

 

Output

Open the serial monitor

Heart rate:95.04bpm / SpO2:93%
Beat!
Beat!
Heart rate:79.23bpm / SpO2:94%
Beat!
Heart rate:78.94bpm / SpO2:94%
Beat!
Heart rate:76.35bpm / SpO2:94%
Beat!
Beat!
Heart rate:76.26bpm / SpO2:94%
Beat!

 

Links

 

Share

Arduino and BMI160 sensor example

The BMI160 is a small, low power, low noise 16-bit inertial measurement unit designed for use in mobile applications like augmented reality or indoor navigation which require highly accurate, real-time sensor data.

In full operation mode, with both the accelerometer and gyroscope enabled, the current consumption is typically 950 μA, enabling always-on applications in battery driven devices. It is available in a compact 14-pin 2.5 x 3.0 x 0.8 mm³ LGA package.

bmi160 module

bmi160 module

Features

Parameter Technical data
Digital resolution Accelerometer (A): 16 bit
Gyroscope (G): 16bit
Measurement ranges
(programmable)
(A): ± 2 g, ± 4 g, ± 8 g, ± 16 g
(G): ± 125°/s, ± 250°/s, ± 500°/s, ± 1000°/s, ± 2000°/s
Sensitivity (calibrated) (A): ±2g: 16384LSB/g
±4g: 8192LSB/g
±8g: 4096LSB/g
±16g: 2048LSB/g
(G): ±125°/s: 262.4 LSB/°/s
±250°/s: 131.2 LSB/°/s
±500°/s: 65.6 LSB/°/s
±1000°/s: 32.8 LSB/°/s
±2000°/s: 16.4 LSB/°/s
Zero-g offset (typ., over life-time) (A): ±40mg (G): ± 10°/s
Noise density (typ.) (A): 180 μg/√Hz
(G): 0.008 °/s/√Hz
Bandwidths (programmable) 1600 Hz … 25/32 Hz
Digital inputs/outputs SPI, I²C, 4x digital
interrupts
Supply voltage (VDD) 1.71 … 3.6 V
I/0 supply voltage (VDDIO) 1.2 … 3.6 V
Temperature range -40 … +85°C
Current consumption
– full operation
– low-power mode
950 μA
3 μA
FIFO data buffer 1024 byte
LGA package 2.5 × 3.0 × 0.8 mm³
Shock resistance 10,000 g x 200 μs

 

Connection

 

Arduino pin Module Pin
5v Vin
Gnd Gnd
A4 SDA
A5 SCL

 

Code

This example used the following library – https://github.com/hanyazou/BMI160-Arduino

#include <BMI160Gen.h>
 
const int select_pin = 10;
const int i2c_addr = 0x69;
 
void setup() {
  Serial.begin(9600); // initialize Serial communication
  while (!Serial);    // wait for the serial port to open
 
  // initialize device
  //BMI160.begin(BMI160GenClass::SPI_MODE, select_pin);
  BMI160.begin(BMI160GenClass::I2C_MODE, i2c_addr);
}
 
void loop() {
  int gx, gy, gz;         // raw gyro values
 
  // read raw gyro measurements from device
  BMI160.readGyro(gx, gy, gz);
 
  // display tab-separated gyro x/y/z values
  Serial.print("g:\t");
  Serial.print(gx);
  Serial.print("\t");
  Serial.print(gy);
  Serial.print("\t");
  Serial.print(gz);
  Serial.println();
 
  delay(500);
}

 

 

Output

Open the serial monitor

g: 90 86 9
g: 69 69 40
g: 35 97 -9
g: -7370 3961 -1786
g: -31829 -2652 32767
g: -3221 25109 32767
g: 26020 31878 -26125
g: -20332 -21698 -15712
g: -7297 3463 -1723
g: -1137 1521 420
g: -203 305 96
g: 144 -102 54
g: 77 116 35

 

Links

https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BMI160-DS000-07.pdf
CJMCU-160I BMI160 latest inertial measurement sensor attitude module 6DOF

Share

Arduino and TCS34725 Color Sensor

The TCS3472 device provides a digital return of red, green, blue (RGB), and clear light sensing values. An IR blocking filter, integrated on-chip and localized to the color sensing photodiodes, minimizes the IR spectral component of the incoming light and allows color measurements to be made accurately.

The high sensitivity, wide dynamic range, and IR blocking filter make the TCS3472 an ideal color sensor solution for use under varying lighting conditions and through attenuating materials. This data is transferred via an I2C to the host.

Connection and Layout

This example is for a Arduino Uno connected to the module

 

arduino and tcs34725

arduino and tcs34725

 

Code

We will use the adafruit library – https://github.com/adafruit/Adafruit_TCS34725

This is one of the default example

#include <Wire.h>
#include "Adafruit_TCS34725.h"
 
/* Example code for the Adafruit TCS34725 breakout library */
 
/* Connect SCL to analog 5
Connect SDA to analog 4
Connect VDD to 3.3V DC
Connect GROUND to common ground */
 
/* Initialise with default values (int time = 2.4ms, gain = 1x) */
// Adafruit_TCS34725 tcs = Adafruit_TCS34725();
 
/* Initialise with specific int time and gain values */
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);
 
void setup(void) {
Serial.begin(9600);
 
if (tcs.begin()) {
Serial.println("Found sensor");
} else {
Serial.println("No TCS34725 found ... check your connections");
while (1);
}
 
// Now we're ready to get readings!
}
 
void loop(void) {
uint16_t r, g, b, c, colorTemp, lux;
 
tcs.getRawData(&r, &g, &b, &c);
colorTemp = tcs.calculateColorTemperature(r, g, b);
lux = tcs.calculateLux(r, g, b);
 
Serial.print("Color Temp: "); Serial.print(colorTemp, DEC); Serial.print(" K - ");
Serial.print("Lux: "); Serial.print(lux, DEC); Serial.print(" - ");
Serial.print("R: "); Serial.print(r, DEC); Serial.print(" ");
Serial.print("G: "); Serial.print(g, DEC); Serial.print(" ");
Serial.print("B: "); Serial.print(b, DEC); Serial.print(" ");
Serial.print("C: "); Serial.print(c, DEC); Serial.print(" ");
Serial.println(" ");
}

 

Output

Open the serial monitor, this is what you should see

Color Temp: 4554 K – Lux: 379 – R: 1122 G: 831 B: 776 C: 1429
Color Temp: 3173 K – Lux: 181 – R: 475 G: 339 B: 272 C: 707
Color Temp: 3425 K – Lux: 224 – R: 604 G: 435 B: 364 C: 868
Color Temp: 2833 K – Lux: 1497 – R: 2983 G: 2240 B: 1461 C: 5723
Color Temp: 5847 K – Lux: 109 – R: 4109 G: 1327 B: 890 C: 5814
Color Temp: 2767 K – Lux: 460 – R: 4468 G: 1703 B: 1062 C: 6734
Color Temp: 4381 K – Lux: 463 – R: 1379 G: 1012 B: 938 C: 1789
Color Temp: 4276 K – Lux: 588 – R: 1464 G: 1136 B: 997 C: 2153
Color Temp: 3952 K – Lux: 646 – R: 1424 G: 1135 B: 933 C: 2350
Color Temp: 3528 K – Lux: 835 – R: 1713 G: 1362 B: 1036 C: 3101

 

Links

TCS34725 RGB Light Color Sensor Recognition Module

Share

MCP9808 temperature readings on a Digit Shield Example

In this example we want to display temperature readings from an MCP9808 temperature sensor on an Arduino Digit Shield. We have already looked at the shield and sensor in previous articles.

We have covered the digit shield in the following post

Arduino Digit Shield – link here

We have covered the MCP9808 sensor in the following post

MCP9808 temperature sensor – link here

 

Connection

The shield fits onto your Arduino UNO – so thats easy. The MCP9808 is an I2C device so its easy to connect to the shield header

 

Shield MCP9808
3v3 Vin
Gnd Gnd
A4 SDA
A5 SCl

 

Code

Basically you just have to tray and merge two examples together and you end up a working example, here is our code

#include <Wire.h>
#include "Adafruit_MCP9808.h"
#include <DigitShield.h>
 
// Create the MCP9808 temperature sensor object
Adafruit_MCP9808 tempsensor = Adafruit_MCP9808();
 
void setup()
{ 
  // initiliase the DigitShield
  DigitShield.begin();
  // Begin serial connection at 9600 baud for debug
  Serial.begin(9600);
 
  if (!tempsensor.begin()) 
  {
    Serial.println("Couldn't find MCP9808!");
    while (1);
  }
}
 
void loop()
{
  float c = tempsensor.readTempC();
  DigitShield.setPrecision(2);
  DigitShield.setValue(c);
  delay(250);
  // Wait a while
  tempsensor.shutdown_wake(1);
  delay(1000);
  tempsensor.shutdown_wake(0);
}

 

Video

This example and some of the default examples in the library joined together in this video

 

Links

Digit Shield 4 digit tube display module fast 5641 digital tube module

High Accuracy Temperature Sensor MCP9808 I2C Breakout Board Module 2.7V-5V Logic Voltage for Ardunio in Stock

Share