Hi StackOverflow community,
For the past couple of weeks, I have not been able to find a solution to my problem. My problem is that I cannot retrieve the data from my homemade ECG that I created from Arduino. I am a total amateur at this, but I'm pretty sure it's a circuitry issue. Here is what my circuit looks like now. (Note: the thing that says 'Dual O' on the far left is the instrumentation amplifier, not an operational amplifier like the one near the middle)
Here is my code:
const int signal = 5; // Pin connected to the filtered signal from the circuit
unsigned long currentBeatTime;
unsigned long previousBeatTime;
unsigned long frequency;
// Internal variables
unsigned long period = 0;
int input = 0;
int lastinput = 0;
void setup() {
pinMode(signal, INPUT);
Serial.begin(9600);
previousBeatTime = millis();
}
void loop() {
delay(500);
input = digitalRead(signal);
if ((input != lastinput) && (input == HIGH)) {
// If the pin state has just changed from low to high (edge detector)
currentBeatTime = millis();
period = currentBeatTime - previousBeatTime; // Compute the time between the previous beat and the one that has just been detected
previousBeatTime = currentBeatTime; // Define the new time reference for the next period computing
}
lastinput = input; // Save the current pin state for comparison at the next loop iteration
// Detect if there is no beat after more than 2 seconds
if ( (millis() - previousBeatTime) > 2000 )
{
Serial.println("dead");
}
else
{
if (period <= 0)
{
frequency = 0;
}
else
{
frequency = 60000/period; // Compute the heart rate in beats per minute (bpm) with the period in milliseconds
}
Serial.print(frequency);
Serial.println(" : alive! ");
}
}
I would appreciate if someone could get back to me as soon as possible. Thank you!
You appear to be reading at pin 5 the voltage after the current has passed through an LED. LEDs produce a voltage drop, so it is possible that the voltage may never be high enough to register as high on a digitalRead() call. Perhaps changed the spot where you sample the voltage, or try an analogRead() instead.
In any case, you need to establish this is a programming related problem to be posting on this board. Perhaps, electronics.stackexchange would provide better help.