You are on page 1of 4

#include <Wire.

h>

#include "MAX30100_PulseOximeter.h"

// 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 tsLastReport2 = 0;

uint32_t tsLastReport3 = 0;

uint32_t tsLastReport4 = 0;

// Callback (registered below) fired when a pulse is detected

void onBeatDetected()

Serial.println("Beat!");

#include <SoftwareSerial.h>

int bluetoothTx = 2;

int bluetoothRx = 3;

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

char cmd[100];

int cmdIndex;

int Saklar=0;

int hitungan1=0;

int a=0;

int bpm;

boolean cmdStartsWith(char *st) {

for(int i=0; ; i++) {


if(st[i]==0) return true;

if(cmd[i]==0) return false;

if(cmd[i]!=st[i]) return false;;

return false;

void exeCmd()

if( cmdStartsWith("ON") ) {Saklar = 1;}

if( cmdStartsWith("mati ") ) {Saklar = 0;}

void setup()

bluetooth.begin(9600); // Bluetooth default baud is 115200

Serial.begin(9600);

cmdIndex = 0;

delay(500); // wait for bluetooth module to start

bluetooth.begin(115200); // Bluetooth default baud is 115200

bluetooth.print("$");

bluetooth.print("$");

bluetooth.print("$"); // enter cmd mode

delay(250);

bluetooth.println("U,9600,N"); // change baud to 9600

bluetooth.begin(9600);

cmdIndex = 0;

Serial.println("Initializing MAX30100");

// Initialize the PulseOximeter instance and register a beat-detected callback

pox.begin();

pox.setOnBeatDetectedCallback(onBeatDetected);
// Initialize the PulseOximeter instance

// Failures are generally due to an improper I2C wiring, missing power supply

// or wrong target chip

// 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

void loop()

pox.update();

// Make sure to call update as fast as possible

while(bluetooth.available()) {

char c = (char)bluetooth.read();

if(c=='\n')

cmd[cmdIndex] = 0;

exeCmd(); // execute the command

cmdIndex = 0; // reset the cmdIndex

else

cmd[cmdIndex] = c;

if(cmdIndex<99) cmdIndex++;

}
// Asynchronously dump heart rate and oxidation levels to the serial

// For both, a value of 0 means "invalid"

bluetooth.print

( (String)"BPM " + pox.getHeartRate()*3000/1023 + "\n" );//print to android

bluetooth.print

( (String)"SPO2 " + pox.getSpO2()*1.041 +"%" + "\n" );//print to android

//Pembacaan sensor

int buttonState = analogRead(A3);

You might also like