title: Print Oxygen Saturation with Arduino
body: <pre><code>#include &lt;Wire.h&gt;
  #include &quot;MAX30100_PulseOximeter.h&quot;
  
  #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(&quot;Beat!&quot;);
  }
  
  void setup()
  {
      Serial.begin(115200);
  
      Serial.print(&quot;Initializing pulse oximeter..&quot;);
  
      // 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(&quot;FAILED&quot;);
          for(;;);
      } else {
          Serial.println(&quot;SUCCESS&quot;);
      }
  
      // 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 &quot;invalid&quot;
      if (millis() - tsLastReport &gt; REPORTING_PERIOD_MS) {
          Serial.print(&quot;Heart rate:&quot;);
          Serial.print(pox.getHeartRate());
          Serial.print(&quot;bpm / SpO2:&quot;);
          Serial.print(pox.getSpO2());
          Serial.println(&quot;%&quot;);
  
          tsLastReport = millis();
      }
  }
  </code></pre>
  <p>I want to output oxygen saturation with Arduino.
  If you run it and turn on the serial monitor, only the Initializing pulse oximeter works, and no data is transmitted after that.
  I want to output the values ​​of oxygen saturation and pulse received from the sensor once per second on the serial monitor.</p>