Can you help me?

Good day,

We are creating project using AD8232 Heart Pulse Sensor.

We have a problem on the timer if the user does not touch the RA or LA electrode the buzzer will turn on after 5 seconds. But the problem if the user released it in 1 second and touch again the buzzer still ON but the correct would be it will turn OFF.

Digital Read 10 --> LO+
Digital Read 11 --> LO-

This is our code.

if ((digitalRead(10) == 1) && (digitalRead(11) == 1)) {
for (num = 0; num <= 5; num++) {
//num = num + 1;
delay(1000);
Serial.println(num);
if (num == 5)
{
Serial.println("num=5");
digitalWrite(BuzzerPort, HIGH);
}
if ((digitalRead(10) == 0) && (digitalRead(11) == 1)) {
Serial.println("num ==== 0");
num = 5;
//x = false;
//Serial.println(num);
digitalWrite(BuzzerPort, LOW);
break;
}
}
}
else {
digitalWrite(BuzzerPort, LOW);
}

Thank you in advance.

Hello hdepadua,

Welcome to the Arduino fora. I and the other people here want to help you but to do that we need certain bits of information. Without the correct information it is difficult or impossible to give you the help and advice you need. To help us to help you please read General guidance andHow to use this forum and provide the information asked for. Being new here you might think this is asking too much or having rules for the sake of rules, that is not the case. If you don’t follow the guidelines all that happens is there is a long exchange of message while we try to get you to tell us what we need in order to help you, this is frustrating for you and frustrating for us.

Common mistakes for people posting here the first time:
Code problems:
Not posting any code while expecting us to work out what is wrong with your code; we are not telepathic and can only find problems in code we can see.
Posting a snippet of code in the belief that the problem is in the code snippet. It is almost always the case that the problem is not where you think it is but elsewhere in the code, hence we need all the code.
Not correctly formatting code. Before posting code use Tools / auto format at the top of the IDE, or use control T. Once you’ve done that use edit / copy for forum.
Posting code without code tags (</>), these are explained in the instructions linked to above. Using code tags makes the code easier to read. Not using code tags means some of the code gets interpreted as HTML with the result that it is displayed with smiley faces and other stuff that should not be there.
Posting an image of code instead of the code itself, or an image of error messages instead of the error messages themselves.
Not being clear about what is expected from code or what happened instead. Code ALWAYS works, that is the nature of code. Whether it does what you expect is a different thing altogether. We need to know what you expected the code to do and what happened instead.
Asking for complete code; we are not here to write code for you, we are here to help you if you get stuck writing code yourself. If you really want someone to write code for you please click on ‘report to moderator’ and ask them to move this to ‘Gigs and Collaborations’ and indicate how much you are willing to pay.

Schematics:
The language of electronics is a schematic or circuit diagram. Long descriptions of what is connected to what are generally useless. A schematic is a drawing of what connects to what, please make one and photograph it. We don’t mind if it’s hand drawn, scruffy and does not use the correct symbols. We do mind if you don’t at least try to post a schematic. Please read How to post an image

General:
Posting links to other sites where code or photos or schematics are hosted. Most of us will not follow such links, partly because of the risk that they hold malware or other unwanted content, partly to maintain everything on this site for the benefit of future users looking for an answer to a similar question and partly because we feel that if you want our help you should provide everything we need on this site not expect us to go hunting elsewhere for it.

Questions:
Not being clear about what is being asked, for example not asking a question at all or asking a vague question like ‘please help’ or ‘it doesn’t work’ or some such thing.

About us:
Those of us answering questions have a wide variety of backgrounds and electronics knowledge, some though working in electronics, some through electronics as a hobby, some both. Most of us are not trained as teachers so probably miss the finer points of how to teach and explain things effectively. We are not, with the odd exception, employees or representatives of Arduino.
Please also remember we are volunteers doing this for free in our spare time and are more inclined to help people who make it easy for us to provide help by providing the information we ask for.

About you:
We only know about you what you tell us; we need to know your level of experience with electronics or microcontrollers, if we don’t know then we can’t tailor our answer to your level of knowledge. We also don’t know if you have problems with English or language or communications in general unless you tell us. We can be sympathetic about problems we know about, but if you don’t tell us we don’t know.

Thank you.

I see your problem, the code you have posted doesn't compile so it doesn't do anything at all.

And you've given us no hint what "touches the RA or LA electrode" means. There's no mention of them in that code snippet.

Steve

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Please post your full code please.

Thanks.. Tom.. :slight_smile:

        Serial.println("num ==== 0");
        num = 5;

It looks like your message is lying to you.

a computer does always what you have programmed. If the computer does something you didn't expected then you don't (yet) understand your program.

You are checking for

if ((digitalRead(10) == 1) && (digitalRead(11) == 1))

if this condition is true you start a for-loop that does five loops with a delay of 1 second
as long as your arduino is busy with delay your code can not check the other if-conditions
inbetween each 1-second-delay the if-conditions and other commands are running through in less than 1 millisecond
So only if in that 1 millisecond the second condition is true the buzzer will be switched off.

Something like this can be coded with nonblocking timing based on the functionmillis()

Now you have two choices:
Choice 1:

tinkering around trying this or that with a low knowledge-level about programming.
which can take up to weeks until you found out how it works by randomly guessing what to change in the code

Choice 2:
lay your main-project asside for 3 to 4 hours
and work through this tutorial

You will gain knowledge how to code to make your main-project work.

As a general hint: Post your complete sektch as a code-section. In 99% of all cases the error is outside the guessed place.
Give a detailed description of your hardware what is IO-pin 10 what is IO-in 11

define selfexplaining identifiers for numbers

don't code

digitalRead(10)

code

digitalRead(My_Self_Explaining_Name_What_IO_pin_10_is)

just like here

digitalWrite(BuzzerPort, HIGH);

where "BuzzerPort" is the self-explaining name

best regards Stefan