0

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 the code I'm using:

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!

EDIT: Here's a schematic. I used Fritzing, and since I am a total beginner at this, it looks like a complete mess. Anyways, here it is:

2

Thank you for your help.

  • 4
    I looked at this, but am not prepared to try and decode your layout diagram. You may have more luck with a circuit diagram. – Milliways Dec 22 '14 at 3:30
  • Hey, sorry about that, here is my schematic. – user3744439 Dec 23 '14 at 1:35
  • "cannot retrieve the data from my homemade ECG" - what do you mean by that? Can your host (PC for this matter) can identify and properly connect to the JY? If so, and it connects but you do not get anything on the PC side, try putting some Serial.print("dummy") in your setup() method to see if the serial terminal is configured properly. – Omer Dec 31 '14 at 17:09
2

Has any part of it ever worked? What have you done to it since? My approach to debugging this would be to - Temorarily replace the Bluetooth with wired serial communication; - Comment out, or stub out(*), anything you aren't utterly and completely confident in. - Get some minimum amount of hardware and software working. - Add back one piece of hardware or one section of code at a time, fixing whatever you have to to get it working again. - Repeat, until everything is back together and playing nicely.

(*) Stubbing is the technique of replacing a function or a section of code with something trivial (and therefore hard to get it wrong!) that lets the rest of the code mostly work.
Suppose you had written a digitalRead() function. (I know it's a library function and we have total confidence in it, but for a moment, just suppose....) You might replace the contents of your digitalRead() with a single statement:

int digitalRead(uint8_t pin){
   // untested code commented out here
   // ...
   return(4);  // any value that means something to the calling code 
}

Now you can work on the code that calls your digitalRead() without having a working digitalRead(). The caller will only ever get the same value every time it calls, but that may be enough get some part of it working until you can come back and fix your digitalRead() function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.