Introduction

In this article, I will explain how to correctly check the pulse in our body and sense the correct pulse signal in mobile or system. We will perform this using Arduino Mega 2560.
Parts
  • Arduino Mega 2560
  • Pulse sensor
  • Hookup Wires
Pulse sensor
Figure 1: Pulse Sensor
  • Pulse Sensor is a plug-and-play heart-rate sensor for Arduino Mega 2560
  • It can be used to check the pulse in our bodies.
  • It can be used by students, artists, and developers.
Connection
In the pulse sensor, they can have the 3 pins,
  • The first can be a negative pin connected to the Gnd of the Arduino Mega 2560.
  • The second can be a positive pin connected to the 5V of the Arduino Mega 2560.
  • The third can be an input pin connected to the Analog pin A0 of the Arduino Mega 2560.
Programming
  1. int pulsePin = 0; // Pulse Sensor purple wire connected to analog pin 0
  2. int blinkPin = 13; // pin to blink led at each beat
  3. int fadePin = 5; // pin to do fancy classy fading blink at each beat
  4. int fadeRate = 0; // used to fade LED on with PWM on fadePin
  5. // these variables are volatile because they are used during the interrupt service routine!
  6. volatile int BPM; // used to hold the pulse rate
  7. volatile int Signal; // holds the incoming raw data
  8. volatile int IBI = 600; // holds the time between beats, must be seeded!
  9. volatile boolean Pulse = false; // true when pulse wave is high, false when it's low
  10. volatile boolean QS = false; // becomes true when Arduino finds a beat.
  11. void setup()
  12. {
  13. pinMode(blinkPin, OUTPUT); // pin that will blink to your heartbeat!
  14. pinMode(fadePin, OUTPUT); // pin that will fade to your heartbeat!
  15. Serial.begin(115200); // we agree to talk fast!
  16. interruptSetup(); // sets up to read Pulse Sensor signal every 2mS
  17. }
  18. void loop()
  19. {
  20. sendDataToProcessing('S', Signal); // send Processing the raw Pulse Sensor data
  21. if (QS == true)
  22. { // Quantified Self flag is true when arduino finds a heartbeat
  23. fadeRate = 255; // Set 'fadeRate' Variable to 255 to fade LED with pulse
  24. sendDataToProcessing('B', BPM); // send heart rate with a 'B' prefix
  25. sendDataToProcessing('Q', IBI); // send time between beats with a 'Q' prefix
  26. QS = false; // reset the Quantified Self flag for next time
  27. }
  28. ledFadeToBeat();
  29. delay(20); // take a break
  30. }
  31. void ledFadeToBeat()
  32. {
  33. fadeRate -= 15; // set LED fade value
  34. fadeRate = constrain(fadeRate, 0, 255); // keep LED fade value from going into negative numbers!
  35. analogWrite(fadePin, fadeRate); // fade LED
  36. }
  37. void sendDataToProcessing(char symbol, int data)
  38. {
  39. Serial.print(symbol); // symbol prefix tells Processing what type of data is coming
  40. Serial.println(data); // the data to send culminating in a carriage return
  41. }
    Explanation
    • Check the pulse in the monitor / smart mobile.
    • When the pulse is normal the LED blinks.
    • We can monitor the pulse with the correct data and symbols.
    Output
    Figure 2: Output
    Read more articles on Arduino: