Jay,
I assumed you had a liquid that your were measuring. Your thinking is on the right track.
If you have objects falling through both beams, the code needs to integrate the samples to ignore the objects that are just passing through. Generally, it's not a good idea to use the millis() function in the main loop as it causes the code to stop until the time delay is completed. However, in this case I think it will be OK. Here's a simple implementation.
if(digitalRead(SENSOR1HIGH) == LOW) { // a part is detected in the beam
millis(xxx); // wait enough milliseconds to let the part fall through
if(digitalRead(SENSOR1HIGH) == LOW) { // look again to see if the beam is still broken
digitalWrite(RELAY1, HIGH);
motor1On = false;
}
}
What's going on here: when you detect an object in the beam, wait long enough to let it fall through then look again. If it's still there then turn the motor off. Otherwise ignore it.
Glen
I assumed you had a liquid that your were measuring. Your thinking is on the right track.
If you have objects falling through both beams, the code needs to integrate the samples to ignore the objects that are just passing through. Generally, it's not a good idea to use the millis() function in the main loop as it causes the code to stop until the time delay is completed. However, in this case I think it will be OK. Here's a simple implementation.
if(digitalRead(SENSOR1HIGH) == LOW) { // a part is detected in the beam
millis(xxx); // wait enough milliseconds to let the part fall through
if(digitalRead(SENSOR1HIGH) == LOW) { // look again to see if the beam is still broken
digitalWrite(RELAY1, HIGH);
motor1On = false;
}
}
What's going on here: when you detect an object in the beam, wait long enough to let it fall through then look again. If it's still there then turn the motor off. Otherwise ignore it.
Glen