this is our idea for the LED setup. as people walk through the 3 LEDs (number or LEDs is subject to change) we can determine which direction they are heading in, based on which sensors are set off first and the sensors that are set off after. so, if a person sets off the bottom sensor, then the middle sensor, and then the top sensor, we would know they were traveling in the direction of bottom to top.
so far i have this working. the IR LED is in series with a 100 ohm resistor and a 5 volt power supply and the IR receiver is in series with a 1Meg ohm resistor and a 5 volt power supply. the two devices are about 1 inch apart and the voltage is about 400mV when the IR LED is visible, and about 200mV when the IR LED is not visible.
UPDATE: 1.23.09
3 IR LED's and sensors in a row. light up with an interupt as shown on the bottom sensor.
UPDATE: 1.27.09
IR LED/sensor hybrid for more distance:
UPDATE: 2.2.09
one sensor and IR LED hybrid is built. below is the circuit diagram i am using with all values and part IDs.
an actual picture of the sensor built thus far (below):
in order to have a more unique and power friendly tripwire, we have decided to learn about and use pulse-width modulation(PWM).
I have good news since the last time I wrote. We are ordering infrared sensors that operate digitally now instead of analog, so we will be able to use something called a KBI (Key Board Interrupt). When the infrared signal is getting to the sensor with no blockage, it will read a 0. When someone steps in front of it, the sensor will read 1.
Now how the KBI works is, with the correct coding, it can detect a high-edge level rising in ports A 4-7. So I coded 3 pins (4,5,6) to detect the high levels since we are having 3 sensors. When someone steps in front of a transmitter, the interrupt will turn on and run the counting algorithm (the one that counts the people in an area). Only Stop3 mode allowed for use of a KBI to reset the microcontroller. With Stop 2 and 1, The KBI would trigger but all of the peripherals would be turn off and erased, which is not good for our program. When the algorithm reads 0 people in an area, the stop3 function will trigger (Please see the low power mode section).
So now, I have to come up with an algorithm for this counting. Here is the finished product:
if((PTAD_PTAD4 == 1) && (leftPersonRead == 0)) {
//recognition and filtering for left sensor
LEFT++;
leftPersonRead = 1;
waitCount = 1;
} else if(PTAD_PTAD4 == 0){
leftPersonRead = 0;
}
if((PTAD_PTAD5 == 1) && (centerPersonRead == 0)) {
//recognition and filtering for center sensor
CENTER++;
centerPersonRead = 1;
waitCount = 1;
} else if(PTAD_PTAD5 == 0){
centerPersonRead = 0;
}
if((PTAD_PTAD6 == 1) && (rightPersonRead == 0)) {
//recognition and filtering for right sensor
RIGHT++;
rightPersonRead = 1;
waitCount = 1;
} else if(PTAD_PTAD6 == 0){
rightPersonRead = 0;
}
if((LEFT > 0) && (CENTER > 0) && (RIGHTTRIGGER == 0) && (multiplePeople == 0)){
//if person is coming from the left, sets flag saying so
OUT = LEFT;
LEFTTRIGGER = 1;
singlePeople = 1;
}
if((RIGHT > 0) && (CENTER > 0) && (LEFTTRIGGER == 0) && (multiplePeople == 0)){
//if person is coming from the right, sets flag saying so
IN = RIGHT;
RIGHTTRIGGER = 1;
singlePeople = 1;
}
if((LEFT != 0) && (RIGHT != 0) && (CENTER < (RIGHT + LEFT)) && (singlePeople == 0)){
//If people are coming in from the left and right sensors at the same time, set flag for it
multiplePeople = 1;
}
if(multiplePeople){
//If people are coming in from both sides, this is how we classify left and right positions
IN = RIGHT;
OUT = LEFT;
if((CENTER == (RIGHT + LEFT))){
//Once everything settles, calculate the amount of people
PEOPLE = ((IN - OUT) + PEOPLE);
if(PEOPLE > 30000)
PEOPLE = 0;
if(PEOPLE == 0)
mode = 1;
LEFT = 0;
RIGHT = 0;
CENTER = 0; //clears all variables
LEFTTRIGGER = 0;
RIGHTTRIGGER = 0;
IN = 0;
OUT = 0;
singlePeople = 0;
multiplePeople = 0;
}
}
if((LEFT == CENTER) && (CENTER == RIGHT) && (CENTER != 0) && (RIGHT != 0) && (LEFT != 0) && (multiplePeople == 0)) {
//once everything settles when one person moves through, calculate people
PEOPLE = ((IN - OUT) + PEOPLE);
if(PEOPLE > 30000)
PEOPLE = 0;
if(PEOPLE == 0)
mode = 1;
LEFT = 0;
RIGHT = 0;
CENTER = 0;
LEFTTRIGGER = 0;
RIGHTTRIGGER = 0; //clears all variables
IN = 0;
OUT = 0;
singlePeople = 0;
multiplePeople = 0;
}
if(waitCount){
waitCount++;
}
if(waitCount == 10){
//if there are hanging values after a second, delete them
LEFT = 0;
RIGHT = 0;
CENTER = 0;
LEFTTRIGGER = 0;
RIGHTTRIGGER = 0;
IN = 0;
OUT = 0;
singlePeople = 0;
multiplePeople = 0;
waitCount = 0;
}
The main problem I was having that when I simulated the sensor so that it should read one person, the code read four people. To fix this, I had to use a “debouncing” kind of thing, by setting a flag when the sensor detected a person, and taking the flag out when the person got out of the way so the interrupt didn't read to quickly. Now, the program almost always reads one person.
The code is ugly, but it works surprisingly well. I recently added an if case that will handle people entering the sensor array from both sides at once. The point of this program is to send information to the router using Rob Haislip's code. When a person trips the sensors, the code will send information to the router containing how many people came through. It needs some tweaking, but right now it pretty much works completely. I am not a great programmer, so the code sucks, but it works and that is what's important.