I think to get an accurate count you'll have to take care on how you place the sensors, control the people into a line, and code accordingly.
If you assume the sensor is real time and 'dumb', so it's just high for as long as there is an obstruction in it's range, and if we assume it's one person at a time, and they're not waving their arms around in front of the sensor, so the signal is clean.
If we also assume the sensors are close together, and there is overlap in their signal when someone passes, meaning the second sensor goes high before the first sensor drops to low again, then we can use the same principle for code as reading a rotary encoder. Have a look at example 1 on this page:
http://playground.arduino.cc/Main/RotaryEncoders#Example1
But this might not be very reliable if there are false readings because of breaks in the beam.
In this case you could place them further apart so their signal doesn't overlap, and set flags when they go off and compare these flags and reset them when the event is complete and we have our count update.
So I think something like this would work (pseudo-code),
digitalRead sensorA
digitalRead sensorB
if (sensorA == high) {
sensorAFlaggedHigh=true; // we set a boole flag, so it remains high even when person has passed A
}
if (sensorB == high) {
sensorBFlaggedHigh=true; // we set a boole flag, so it remains high even when person has passed B
}
if (sensorB == high && sensorAFlaggedHigh == true) {
peopleInTheHouse++;
sensorAFlaggedHigh=false; // Resetting sensor A's flag - we captured our event.
}
if (sensorA == high && sensorBFlaggedHigh == true) {
peopleInTheHouse--;
sensorBFlaggedHigh=false; //Resetting sensor B's flag - we captured our event.
}
So I think this would work as long as the sensor triggers don't overlap.
Using a camera overhead and OpenCV would be cool for this, and would be able to track multiple people at the same time, and would be pretty hard to confuse (unless it crashes!)