3

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)

1

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!

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
  • 3
    Are you, by any chance, dead, or perhaps a vampire? – Martin James Dec 22 '14 at 00:57
  • 3
    Haha, no, but I am getting a signal that says I am. I just get 'dead' as the output. Appreciate the joke though. – user3744439 Dec 22 '14 at 01:00
  • Well, are you 100% convinced that it's not a hardware issue - scope shows signal on input pin, correct pin wired up etc? – Martin James Dec 22 '14 at 01:02
  • 1
    @user3744439: For future reference you need to learn how to draw electronic schematics. Because a cartoon picture of a breadboard is a terrible way to convey how you intend to wire your circuit. As far as we can tell the problem could be anywhere in the signal chain. – In silico Dec 22 '14 at 01:04
  • Put another way: if you connect a LED+resistor to the controller board input pin, does it flash? – Martin James Dec 22 '14 at 01:06
  • @Insilico I am terribly sorry, as circuitry and schematics are not my field of expertise. I'll make sure to draw a better schematic next time I post a question. – user3744439 Dec 22 '14 at 01:08
  • this would be better on electronics.stackexchange – chris Dec 22 '14 at 01:27
  • Yes, the LED does flash, but I don't know what to do now. I asked EE, but to no avail. What do I do now? – user3744439 Dec 23 '14 at 01:22

1 Answers1

0

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.

UncleO
  • 8,299
  • 21
  • 29
  • Hi UncleO, the LED does work. I don't know what to do know though. I asked EE, but I do not understand their comments. – user3744439 Dec 23 '14 at 01:22