I am reading an ECG signal using a single lead heart rate monitor. What I know is that when I use delay(15) it means that I am getting 66.67 readings in a second which corresponds to the sampling frequency. I want to set the sampling frequency to 250. This can be done by introducing delay(4).
What I really need is to set the sampling frequency to 250 Hz without introducing a delay in the code because I am acquiring ECG data in real time. Also, I am sending the data to python for processing and the delay will affect the sampling frequency in the time domain analysis.
any detailed solution or code ??
PS. I am using Arduino UNO
Code:
#define SERIAL_BUFFER_SIZE 8192
#include <SoftwareSerial.h>
unsigned long Time;
void setup() {
// initialize the serial communication:
pinMode(10, INPUT); // Setup for leads off detection LO +
pinMode(11, INPUT); // Setup for leads off detection LO -
Serial.println("CLEARDATA"); //clears up
Serial.println("RESETTIMER"); //resets timer to 0
Serial.begin(115200);
}
void loop() {
if((digitalRead(10) == 1)||(digitalRead(11) == 1)){
Serial.println('!');
// continue;
}
else{
/*
// send the value of analog input 0:
int idata = analogRead(A0);
// float data = (idata*3.3)/1023;
Serial.println(idata);
*/
int sensorValue = analogRead(A0);
float voltage = sensorValue * (3.3/1023.0);
Serial.println(voltage);
}
//Wait for a bit
delay(4);
}