// Include necessary libraries
#include <OneWire.h>
#include <DallasTemperature.h>
#include <PulseSensorPlayground.h>
// Data wire is connected to Arduino pin 2
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire device
OneWire oneWire(ONE_WIRE_BUS);
// Pass oneWire reference to DallasTemperature library
DallasTemperature sensors(&oneWire);
// Pulse Sensor connected to analog pin A0
const int PulseSensorPin = A0;
// Create an instance of the PulseSensorPlayground object
PulseSensorPlayground pulseSensor;
void setup(void) {
// Start serial communication
Serial.begin(9600);
// Start up the library
sensors.begin();
// Initialize the PulseSensor
pulseSensor.analogInput(PulseSensorPin);
pulseSensor.begin();
}
void loop(void) {
// Request temperature from the sensor
sensors.requestTemperatures();
// Fetch the temperature in Celsius
float tempC = sensors.getTempCByIndex(0);
// Read pulse rate
int myBPM = pulseSensor.getBeatsPerMinute();
bool isHeartbeat = pulseSensor.sawStartOfBeat();
// Print the readings to the serial monitor
Serial.print("Body Temperature: ");
Serial.print(tempC);
Serial.println(" °C");
if (isHeartbeat) {
Serial.print("Pulse Rate: ");
Serial.print(myBPM);
Serial.println(" BPM");
}
// Wait a bit before the next loop
delay(1000);
}