1. #include <PulseSensorPlayground.h> // Includes the PulseSensorPlayground Library.
2. 3. // Variables 4. const int PulseWire = 0; // PulseSensor PURPLE WIRE connected to ANALOG PIN 0 5. const int LED = LED_BUILTIN; // The on-board Arduino LED, close to PIN 13. 6. int Threshold = 550; // Determine which Signal to "count as a beat" and which to ignore. 7. // Use the "Gettting Started Project" to fine-tune Threshold Value beyond default setting. 8. // Otherwise leave the default "550" value. 9. 10. PulseSensorPlayground pulseSensor; // Creates an instance of the PulseSensorPlayground object called "pulseSensor" 11. 12. 13. void setup() { 14. 15. Serial.begin(115200); // For Serial Monitor 16. 17. // Configure the PulseSensor object, by assigning our variables to it. 18. pulseSensor.analogInput(PulseWire); 19. pulseSensor.blinkOnPulse(LED); //auto-magically blink Arduino's LED with heartbeat. 20. pulseSensor.setThreshold(Threshold); 21. 22. // Double-check the "pulseSensor" object was created and "began" seeing a signal. 23. if (pulseSensor.begin()) { 24. Serial.println("We created a pulseSensor Object !"); //This prints one time at Arduino power-up, or on Arduino reset. 25. } 26. } 27. 28. 29. 30. void loop() { 31. 32. 33. 34. if (pulseSensor.sawStartOfBeat()) { // Constantly test to see if "a beat happened". 35. int myBPM = pulseSensor.getBeatsPerMinute(); // Calls function on our pulseSensor object that returns BPM as an "int". 36. // "myBPM" hold this BPM value now. 37. Serial.println("♥ A HeartBeat Happened ! "); // If test is "true", print a message "a heartbeat happened". 38. Serial.print("BPM: "); // Print phrase "BPM: " 39. Serial.println(myBPM); // Print the value inside of myBPM. 40. } 41. 42. delay(20); // considered best practice in a simple sketch. 43. 44. } 45.