hey there,
I have a project to count the people who enter the room and who get out of the room,
my code is reading the signal very good but the thing is that I need condition when the first sensor is TRUE the second one should be off, or when the first sensor is TRUE the program should wait till the other sensor also store the signal and then it should add one,
In this way, I can count people who get IN and OUT on the one way.
if (distance_in < calibrate_in && distance_in > 0) { // If closer than wall/calibrated object (person is present) && throw out zero readings
if (prev_inblocked == false) {
count++; // Increase count by one
Serial.print("Count: ");
Serial.println(count);
delay (100);
}
prev_inblocked = true;
} else {
prev_inblocked = false;
}
if (distance_out < calibrate_out && distance_out > 0) {
if (prev_outblocked == false) {
count--; // Decrease count by one
Serial.print("Count: ");
Serial.println(count);
delay (100);
}
prev_outblocked = true;
} else {
prev_outblocked = false;
}
You’ve got four possible sensor states to contend with…
Both sensors open
In sensor closed
Out sensor closed
Both sensors closed
*below
Based on the transition from any state to another, you have to determine what activity is taking place.
Using a simple state-machine acting upon the current and preceding states, you can figure out what’s happening.
I assume that if someone is halfway between the sensors, they are in the ‘middle’, otherwise you may have confusion between two people entering the zone simultaneously.
*That may be a good argument for an additional sensor in-between the two existing…
That would raise your number of ‘states’ to eight, but also give you more awareness of what’s happening.
for now, the code work if there is two way, in different sides, the only thing I want is to have a condition that when the first sensor detects, the sensor should wait till the other sensor detect too
can you explain your sensors, are there separate enter/exit paths each with a distance sensor, or is there a single enter/exit path? don't understand your need to make one dependent on the other.
wouldn't a distance sensor normally report some farthest distance (or timeout), so when someine enter/exits, the distance report changes value from which you can determine a direction and then increment a count when the distance becomes farthest or timeout
it's one path, for IN and OUT, basically, I have to ultrasonic, which read signal in (cm) I put both of the sensors beside together, one sensor for IN and other for OUT, when the first sensor distance go less than 30 cm it adds one+ to count, and when the other sensor also go less than 30 cm it takes on (-1) form the count,
and now when someone enters first it adds one and then when he passed into the other sensor too it takes one,
I can put delay(); when the first sensor detects but I want other ways.
i don't understand why you need 2 "distance" detectors if there is just one path? are the perpendicular to the path or parallel (in line)
a common approach for counting people is to have two optical detectors perpendicular to the path that a person breaks. the detector the becomes active last indicates the direction
can you please explain more about your idea,
because first when I thought about count I said that, if it's one path it's and I put one ultrasonic how I would know that each detection is OUT or IN, so I plan to buy two ultrasonic,
but still it works ^_^, but the problem is with the code
i know you are trying to count the # of people entering and exiting.
you said this already
you said this already
please don't repeat your question .... it wastes time
presumably you are repeatedly making a distance measurement with each sensor and you expect one sensor to detect a person (< 30cm) before the other sensor
and presumably, as I suggested, the sensor the detects a person last indicates the direction.
but the ultrasonic sensors have a 15 deg aperture. this means that it senses something 5cm to its side at 10cm from it and 10 cm to the side at 20 cm
10 \ /
\ /
5 \ /
\ /
o
so wouldn't each sensor detect the person at the same time of they are very close to one another?
it would be better to put the sensors at each end of you enter/exit box so that they are as far apart as possible