Question: The code below is a code for arduino for a pulse sensor to read someone's heart rate. However, I need the code to calculate beats
The code below is a code for arduino for a pulse sensor to read someone's heart rate. However, I need the code to calculate beats per minute. Apparantly the "key" to calculating beats per minute in the code to check/change the portion of the code with the dT term. Not sure what to change it to or set it equal to. Please help
*/
#include
// variables for the pushbutton const int buttonPin=2; // Push Button volatile int pushValue; // value of button
// constants for the Buzzer const int speakerPin=8;
// constants for RGB LED const int GreenledPin = 5; // Green LED const int RedledPin = 3; // Red LED const int BlueledPin = 6; // Blue LED
// variables for Analog Signals const int Analog2Pin=3; // Thermistor input const int PulsePin=1; // Pulse sensor Input const int PotPin=0; // Potentiometer pin int Vth; // thermistor value
int waittime=1000;
// The setup() method runs once, when the sketch starts void setup() { // initialize the digital pin as an output: pinMode(GreenledPin, OUTPUT); pinMode(RedledPin, OUTPUT); pinMode(BlueledPin, OUTPUT); // tun off RGB LEDs digitalWrite(GreenledPin, HIGH); digitalWrite(RedledPin, HIGH); digitalWrite(BlueledPin, HIGH); // pinMode(buttonPin,INPUT); pinMode(speakerPin,OUTPUT); // Serial Comm Serial.begin(115200); Serial.println("Hello UM !"); }
// the loop() method runs over and over again, // as long as the Arduino has power int pot_reading; // potentiometer's value in ADC units (0:1023) float pot_reading_volts; // potentiometer's value in Volts (0:5) int pulse_value; int state=0; int Threshold=520; // for pulse long int T0=0; long int dT; float HR; void loop() { pulse_value = analogRead(PulsePin); Serial.println(pulse_value); switch (state) { case 0: if (pulse_value>Threshold) { dT=(millis()-T0); T0=T0+dT;
tone(speakerPin,1000,200); digitalWrite(GreenledPin,LOW); digitalWrite(RedledPin,HIGH); state=1; } break; case 1: if (pulse_value<=Threshold) { digitalWrite(GreenledPin,HIGH); digitalWrite(RedledPin,LOW); state=0; } } delay(1); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
