/* To calibrate the IR sensor car detection threshold... 1. Run the program without cars and note the 'Overall Minimum' 2. Now cover all finish lines with cars and note the 'Overall Maximum' The difference between the two numbers is the detect/no-detect margin. The detection threshhold can be set half-way between the two numbers. The detect/no-detect margin is determined by ambient IR conditions relative to the 'detectability' of the cars. The latter is determined by sensor-to-car spacing and the reflectivity of the car. If different color cars are being used, use darker ones (i.e. less detectable) in step 2 above. If the detect/no-detect margin is too small the timer will be subject to errors. If the timer fails to catch cars crossing the finish line the threshold must be increased. If the timer has false alarms (detects car that isn't there) the threshold must be reduced. If there's not enough margin to set a threshold that avoids errors, countermeasures include... - Reduce ambient light level and variability (ex: turn off lights, close blinds, create shade) - Increase reflectivity of the car bottom (ex: white/reflective tape/paint) - Raise IR sensor closer to car bottom noting impact with car must be avoided. The 'halfway between' threshold setting described above may be modified to better match a particular environment. If there is a high/variable level of ambient IR, but the cars are all light colored, the threshold could be lowered. If the ambient IR level is low and steady, but the cars are dark or far from the sensor the threshold could be increased. */ #define NUM_LANES 2 #define PIN_OFFSET 5 // 0-based ex: lane 0-2 = pins 5-7 #define NUM_SAMPLES 100 void setup() { Serial.begin(9600); pinMode(2,INPUT_PULLUP); } void loop() { long IR,maxIR,minIR; long maxmaxIR,minminIR; int i,j; maxmaxIR = 0; minminIR = 0xFFFF; for (i=0;i