#include<LiquidCrystal.h> // including the lcd library LiquidCrystal lcd(7,6,5,4,3,2);…
- User
#include<LiquidCrystal.h> // including the lcd library
LiquidCrystal lcd(7,6,5,4,3,2); int sensor_pin = A0;
int led_pin = 13;
int Reset=6; int heart_rate=0;volatile int analog_data;
volatile int time_between_beats = 600;
volatile boolean pulse_signal = false;
volatile int beat[10]; //heartbeat values will be sotred in this array
volatile int peak_value = 512;
volatile int trough_value = 512;
volatile int thresh = 525;
volatile int amplitude = 100;
volatile boolean first_heartpulse = true;
volatile boolean second_heartpulse = false;
volatile unsigned long samplecounter = 0; //This counter will tell us the pulse timing
volatile unsigned long lastBeatTime = 0;
void setup()
{
pinMode(led_pin,OUTPUT);
pinMode(Reset, INPUT); Serial.begin(115200);lcd.begin(16,2); // starting the lcd // printing heart beat on the display
lcd.setCursor(0,1); // setting the cursor from start
interruptSetup();
}
void loop()
{
codeSerial.print("BPM: "); lcd.clear(); lcd.print("Heart Rate:"); lcd.print(heart_rate); Serial.println(heart_rate);int rst = digitalRead(Reset); Serial.print(rst); delay(200); // take a break
}
void interruptSetup()
{
TCCR2A = 0x02; // This will disable the PWM on pin 3 and 11
OCR2A = 0X7C; // This will set the top of count to 124 for the 500Hz sample rate
TCCR2B = 0x06; // DON'T FORCE COMPARE, 256 PRESCALER
TIMSK2 = 0x02; // This will enable interrupt on match between OCR2A and Timer
sei(); // This will make sure that the global interrupts are enable
}
ISR(TIMER2_COMPA_vect)
{
cli();
analog_data = analogRead(sensor_pin);
samplecounter += 2;
int N = samplecounter - lastBeatTime;
if(analog_data < thresh && N > (time_between_beats/5)*3)
code{ if (analog_data < trough_value) { trough_value = analog_data; } } - Assistant
- User
pinouts
- Assistant
To connect the components and ensure the code works properly, you'll need the pin configuration for the LiquidCrystal display and the MAX30105 sensor with an Arduino. Here's how to set up the pin connections:
LiquidCrystal Display (LCD):
For the
LiquidCrystallibrary, the constructor indicates the following pin connections between the Arduino and the LCD: