I have an infrared emitter and receiver. I want to detect some object and calculate electrical probe changes on serial monitor while passing in front of IR sensor. Each object has a different value when passed, Object doesn't pass continuously but one by one.
I am trying to write a code using following condition.
// If analogRead < 35, Serial Print 0.
// if analogRead > 35 start sum, and < 35 stop sum.
I want to sum the values between "start sum" and "stop sum" and print the total value.
//Else print 0.
I am trying the below code but not getting the total sum
int sum = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
int ifRead = analogRead(A0);
if (ifRead < 35) {
Serial.println("0");
sum = 0; // reset the sum
}
else {
sum += ifRead;
if (sum >= 35) {
Serial.println(sum);
sum = 0; // reset the sum
}
}
delay(100);
}