Arduino to Read 4-20ma Analog Sensor Data
Introduction
The MAX30102 is an integrated pulse oximetry and centre-charge per unit monitor biosensor module based on PPG ((PhotoPlethysmoGraphy). It is and so small-scale that you tin just habiliment it on your finger or wrist for data collecting. Internally integrated 18bit ADC, the sensor supports I2C data output, which could be compatible for most controllers.
Annotation:
- Try to fix the sensor on your finger in using to avoid the effect of pressure level change on data output.
- This product is not a professional medical device, and should not be used as an auxiliary accessory in medical diagnosis and treatment.
Features
- Extremely depression standby current
- Loftier sampling rate
- High SNR
Application
- Heart-rate Measurement
- SPO2 Detection
Specification
- Power Supply: three.3V~5V
- Working Current: <5mA
- RED/IR LED Driving Current: 0-50mA
- Communication: I2C
- I2C Address: 0x57
- Operating Temperature: -40℃~85℃
- Dimension: 18×14mm/0.71×0.55"
Board Overview
Num | Label | Description |
---|---|---|
1 | VCC | + |
2 | GND | - |
3 | SCL | I2C Clock line |
4 | SDA | I2C Data line |
five | INT | Interrupt Pivot |
Tutorial
Gear up the sensor(either side is ok) on your finger with a safe band.
Requirements
- Hardware
- DFRduino UNO R3 (or like) x i
- MAX30102 Heart Charge per unit and Oximeter Sensor x1
- Jumper wires
- Software
- Arduino IDE
- Download and install the MAX30102 Library (About how to install the library?)
API Function List
/* Macro definition options in sensor configuration sampleAverage: SAMPLEAVG_1 SAMPLEAVG_2 SAMPLEAVG_4 SAMPLEAVG_8 SAMPLEAVG_16 SAMPLEAVG_32 ledMode: MODE_REDONLY MODE_RED_IR MODE_MULTILED sampleRate: PULSEWIDTH_69 PULSEWIDTH_118 PULSEWIDTH_215 PULSEWIDTH_411 pulseWidth: SAMPLERATE_50 SAMPLERATE_100 SAMPLERATE_200 SAMPLERATE_400 SAMPLERATE_800 SAMPLERATE_1000 SAMPLERATE_1600 SAMPLERATE_3200 adcRange: ADCRANGE_2048 ADCRANGE_4096 ADCRANGE_8192 ADCRANGE_16384 */ /*! *@brief Use macro definition to configure sensor *@param ledBrightness LED effulgence, default value: 0x1F(six.4mA), Range: 0~255(0=Off, 255=50mA) *@param sampleAverage Average multiple samples then draw once, reduce information throughput, default 4 samples average *@param ledMode LED manner, default to use red low-cal and IR at the aforementioned fourth dimension *@param sampleRate Sampling rate, default 400 samples every second *@param pulseWidth Pulse width: the longer the pulse width, the wider the detection range. Default to be Max range *@param adcRange ADC Measurement Range, default 4096 (nA),15.63(pA) per LSB */ void sensorConfiguration(uint8_t ledBrightness = 0x1F, uint8_t sampleAverage = SAMPLEAVG_4, \ uint8_t ledMode = MODE_MULTILED, uint8_t sampleRate = SAMPLERATE_400, \ uint8_t pulseWidth = PULSEWIDTH_411, uint8_t adcRange = ADCRANGE_4096); /*! *@brief get red value *@return Cherry light reading */ uint32_t getRed(void); /*! *@brief Go IR value *@return IR reading */ uint32_t getIR(void); /*! *@brief Summate heart rate and SPO2 *@param *SPO2 [out]Calculated SPO2 *@param *SPO2Valid [out]If the calculated SPO2 is valid, the value is 1 *@param *heartRate [out]Calculated centre-rate *@param *heartRateValid [out]If the calculated heart-rate is valid, the value is one */ void heartrateAndOxygenSaturation(int32_t* SPO2,int8_t* SPO2Valid,int32_t* heartRate,int8_t* heartRateValid);
Connection Diagram
Sample Code 1- Read Raw Data
Read red and IR data that have not been candy by algorithms.
/*! * @file basicRead.ino * @brief Output readings of red light and IR * @due north This library supports mainboards: ESP8266, FireBeetle-M0, UNO, ESP32, Leonardo, Mega2560 * @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) * @licence The MIT License (MIT) * @writer [YeHangYu](hangyu.ye@dfrobot.com) * @version V0.1 * @appointment 2020-05-29 * @url https://github.com/DFRobot/DFRobot_MAX30102 */ #include <DFRobot_MAX30102.h> DFRobot_MAX30102 particleSensor; /* Macro definition opions in sensor configuration sampleAverage: SAMPLEAVG_1 SAMPLEAVG_2 SAMPLEAVG_4 SAMPLEAVG_8 SAMPLEAVG_16 SAMPLEAVG_32 ledMode: MODE_REDONLY MODE_RED_IR MODE_MULTILED sampleRate: PULSEWIDTH_69 PULSEWIDTH_118 PULSEWIDTH_215 PULSEWIDTH_411 pulseWidth: SAMPLERATE_50 SAMPLERATE_100 SAMPLERATE_200 SAMPLERATE_400 SAMPLERATE_800 SAMPLERATE_1000 SAMPLERATE_1600 SAMPLERATE_3200 adcRange: ADCRANGE_2048 ADCRANGE_4096 ADCRANGE_8192 ADCRANGE_16384 */ void setup() { //Init series Serial.brainstorm(115200); /*! *@brief Init sensor *@param pWire IIC bus pointer object and structure device, can both laissez passer or not pass parameters (Wire in default) *@param i2cAddr Flake IIC address (0x57 in default) *@return true or false */ while (!particleSensor.brainstorm()) { Serial.println("MAX30102 was not found"); delay(1000); } /*! *@brief Use macro definition to configure sensor *@param ledBrightness LED brightness, default value: 0x1F(half-dozen.4mA), Range: 0~255(0=Off, 255=50mA) *@param sampleAverage Average multiple samples and then describe once, reduce data throughput, default 4 samples boilerplate *@param ledMode LED way, default to use red low-cal and IR at the same time *@param sampleRate Sampling rate, default 400 samples every 2nd *@param pulseWidth Pulse width: the longer the pulse width, the wider the detection range. Default to be Max range *@param adcRange Measurement Range, default 4096 (nA), xv.63(pA) per LSB */ particleSensor.sensorConfiguration(/*ledBrightness=*/0x1F, /*sampleAverage=*/SAMPLEAVG_4, \ /*ledMode=*/MODE_MULTILED, /*sampleRate=*/SAMPLERATE_400, \ /*pulseWidth=*/PULSEWIDTH_411, /*adcRange=*/ADCRANGE_4096); } void loop() { //Impress effect Series.print("R="); /*! *@cursory Get red value *@render Crimson low-cal reading */ Serial.print(particleSensor.getRed()); Serial.print(" IR="); /*! *@brief Go IR value *@return IR reading */ Serial.print(particleSensor.getIR()); Series.println(); delay(100); }
Effect 1
Sample Code 2- Display Heartbeat Diagram
Display heartbeat diagram on the Arduino serial plotter: click tool->"Serial Plotter".
/*! * @file heartbeatPlotter.ino * @cursory Display heartbeat diagram on the Arduino serial plotter: click tool->"Serial Plotter". The baud rate should be 115200 * @n Attempt to fix the sensor on your finger in using to avoid the effect of force per unit area alter on information output. * @due north This library supports mainboards: ESP8266, FireBeetle-M0, UNO, ESP32, Leonardo, Mega2560 * @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) * @licence The MIT License (MIT) * @author [YeHangYu](hangyu.ye@dfrobot.com) * @version V0.ane * @date 2020-05-29 * @url https://github.com/DFRobot/DFRobot_MAX30102 */ #include <DFRobot_MAX30102.h> DFRobot_MAX30102 particleSensor; /* Macro definition options in sensor configuration sampleAverage: SAMPLEAVG_1 SAMPLEAVG_2 SAMPLEAVG_4 SAMPLEAVG_8 SAMPLEAVG_16 SAMPLEAVG_32 ledMode: MODE_REDONLY MODE_RED_IR MODE_MULTILED sampleRate: PULSEWIDTH_69 PULSEWIDTH_118 PULSEWIDTH_215 PULSEWIDTH_411 pulseWidth: SAMPLERATE_50 SAMPLERATE_100 SAMPLERATE_200 SAMPLERATE_400 SAMPLERATE_800 SAMPLERATE_1000 SAMPLERATE_1600 SAMPLERATE_3200 adcRange: ADCRANGE_2048 ADCRANGE_4096 ADCRANGE_8192 ADCRANGE_16384 */ void setup() { //Init serial Serial.begin(115200); /*! *@brief Init sensor *@param pWire IIC bus pointer object and structure device, can both pass or not pass parameters (Wire in default) *@param i2cAddr Chip IIC address (0x57 in default) *@return truthful or false */ while (!particleSensor.brainstorm()) { Serial.println("MAX30102 was not plant"); delay(1000); } //Set up reasonably to brand sure there is clear sawtooth figure on the serial plotter /*! *@brief Utilize macro definition to configure sensor *@param ledBrightness LED brightness, default value: 0x1F(half-dozen.4mA), Range: 0~255(0=Off, 255=50mA) *@param sampleAverage Boilerplate multiple samples and so draw once, reduce information throughput, default 4 samples average *@param ledMode LED style, default to use red light and IR at the aforementioned time *@param sampleRate Sampling rate, default 400 samples every second *@param pulseWidth Pulse width: the longer the pulse width, the wider the detection range. Default to be Max range *@param adcRange Measurement Range, default 4096 (nA), 15.63(pA) per LSB */ particleSensor.sensorConfiguration(/*ledBrightness=*/lx, /*sampleAverage=*/SAMPLEAVG_8, \ /*ledMode=*/MODE_MULTILED, /*sampleRate=*/SAMPLERATE_400, \ /*pulseWidth=*/PULSEWIDTH_411, /*adcRange=*/ADCRANGE_16384); } void loop() { //Send raw data to serial, open up seril plotter to check /*! *@brief Go IR value *@render IR reading */ Serial.println(particleSensor.getIR()); }
Result 2
Sample Code 3- Heart-rate and SPO2 Measurement
Display the heart rate and SPO2 on Arduino serial monitor. Normal middle rate(adult): 60~100 beats per infinitesimal. Normal SPO2: 95~100.
/*! * @file SPO2.ino * @brief Brandish center-rate and SPO2 on serial in real-fourth dimension, normal SPO2 is within 95~100 * @n Try to ready the sensor on your finger in using to avert the effect of pressure change on data output. * @north This library supports mainboards: ESP8266, FireBeetle-M0, UNO, ESP32, Leonardo, Mega2560 * @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) * @licence The MIT License (MIT) * @author [YeHangYu](hangyu.ye@dfrobot.com) * @version V0.i * @date 2020-05-29 * @url https://github.com/DFRobot/DFRobot_MAX30102 */ #include <DFRobot_MAX30102.h> DFRobot_MAX30102 particleSensor; /* Macro definition options in sensor configuration sampleAverage: SAMPLEAVG_1 SAMPLEAVG_2 SAMPLEAVG_4 SAMPLEAVG_8 SAMPLEAVG_16 SAMPLEAVG_32 ledMode: MODE_REDONLY MODE_RED_IR MODE_MULTILED sampleRate: PULSEWIDTH_69 PULSEWIDTH_118 PULSEWIDTH_215 PULSEWIDTH_411 pulseWidth: SAMPLERATE_50 SAMPLERATE_100 SAMPLERATE_200 SAMPLERATE_400 SAMPLERATE_800 SAMPLERATE_1000 SAMPLERATE_1600 SAMPLERATE_3200 adcRange: ADCRANGE_2048 ADCRANGE_4096 ADCRANGE_8192 ADCRANGE_16384 */ void setup() { //Init serial Series.begin(115200); /*! *@brief Init sensor *@param pWire IIC jitney pointer object and construction device, can both pass or non pass parameters (Wire in default) *@param i2cAddr Chip IIC address (0x57 in default) *@render truthful or simulated */ while (!particleSensor.brainstorm()) { Serial.println("MAX30102 was not found"); delay(1000); } /*! *@cursory Use macro definition to configure sensor *@param ledBrightness LED brightness, default value: 0x1F(6.4mA), Range: 0~255(0=Off, 255=50mA) *@param sampleAverage Average multiple samples then depict one time, reduce data throughput, default four samples average *@param ledMode LED mode, default to use cerise lite and IR at the aforementioned time *@param sampleRate Sampling charge per unit, default 400 samples every 2nd *@param pulseWidth Pulse width: the longer the pulse width, the wider the detection range. Default to be Max range *@param adcRange ADC Measurement Range, default 4096 (nA), xv.63(pA) per LSB */ particleSensor.sensorConfiguration(/*ledBrightness=*/50, /*sampleAverage=*/SAMPLEAVG_4, \ /*ledMode=*/MODE_MULTILED, /*sampleRate=*/SAMPLERATE_100, \ /*pulseWidth=*/PULSEWIDTH_411, /*adcRange=*/ADCRANGE_16384); } int32_t SPO2; //SPO2 int8_t SPO2Valid; //Flag to display if SPO2 calculation is valid int32_t heartRate; //Heart-rate int8_t heartRateValid; //Flag to display if heart-rate calculation is valid void loop() { Serial.println(F("Wait about four seconds")); particleSensor.heartrateAndOxygenSaturation(/**SPO2=*/&SPO2, /**SPO2Valid=*/&SPO2Valid, /**heartRate=*/&heartRate, /**heartRateValid=*/&heartRateValid); //Impress result Serial.print(F("heartRate=")); Serial.print(heartRate, DEC); Serial.impress(F(", heartRateValid=")); Series.print(heartRateValid, DEC); Series.print(F("; SPO2=")); Series.print(SPO2, DEC); Serial.print(F(", SPO2Valid=")); Serial.println(SPO2Valid, December); }
Consequence iii
FAQ
For any questions, advice or cool ideas to share, delight visit the DFRobot Forum.
More than Documents
- Schematics Diagram
- Dimension Diagram
- MAX30102 Datasheet
Become MAX30102 Middle Rate and Oximeter Sensor from DFRobot Store or DFRobot Distributor.
Turn to the Tiptop
Source: https://wiki.dfrobot.com/Heart_Rate_and_Oximeter_Sensor_SKU_SEN0344
0 Response to "Arduino to Read 4-20ma Analog Sensor Data"
Enregistrer un commentaire