Hi. I need some help, i have 2 pulse sensors i want to use with my arduino , i am basically reading 2 analog values and comparing if they have reached a certain threshold ( 510 in my case). Now , after it detects this value, the code should simply just print out 500 for the first sensor, and 300 for the second sensor ( indicating it has detected a pulse). Now, the code does that perfectly, however instead of just printing 300 and 500 once, it prints them couple of times during the duration of the pulse. How can i make it so they are printed just once ? Here's the code. Also, in anyone knows how can i detect if the pulse lasted atleast 20 ms, or something like that, i would be really grateful .
int sensorPin1 = A0;
int sensorPin2 = A3;
int sensorValue1 = 0;
int sensorValue2 = 0;
int border = 510;
void setup() {
Serial.begin(9600);
}
void loop() {
bool G1 = false;
bool G2 = false;
//int flag=1;
sensorValue1 = analogRead(sensorPin1);
//delay(1);
sensorValue2 = analogRead(sensorPin2);
// delay(2);
if(sensorValue1 >= border)
{
G1=true;
//Serial.println(500);
//flag=0;
}
if(G1)
{
Serial.println(300);
G1=false;
}
if(sensorValue2 >= border)
{
G2=true;
// Serial.println(300);
//flag=0;
}
if(G2)
{
Serial.println(500);
G2=false;
}
Serial.println(0);
}