PDA

View Full Version : IR Counting



Austin S.
01-25-2010, 08:56 AM
Hello,

I have a BS2 and I am using IR sensors. My project requires me to count how many times an IR sensor detects an object. Is there a special command I can use for this?

Any advice or comments would be appreciated!

Thanks!

Post Edited (Austin S.) : 1/25/2010 1:18:45 AM GMT

Franklin
01-25-2010, 09:55 AM
Austin said...
Any advice or comments would be appreciated!
What is your price range? It is not easy(possible) without other parts.
What code do you have and can you explain the whole object of your project?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen

Mike2545
01-25-2010, 10:16 AM
How fast do you need to be able to detect the "object" ?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mike2545

erco
01-25-2010, 02:12 PM
If you're just counting events, a simple incrementing loop will do the job. Do you know about Do loops or For/Next loops? Work that WAM manual, it's all in there.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"If you build it, they will come."

Campeck
01-25-2010, 06:14 PM
DO

IF (IRLED = 0) THEN
DO WHILE (IRLED = 0)
limitcounter = limitcounter + 1
LOOP

ELSEIF (limitcounter >= limit) THEN
Count = Count + 1
limitcounter = 0

ELSE
limitcounter = 0

ENDIF

DEBUG HOME, DEC3 ? Count

LOOP


this "should" work if your counting is relatively slow.
if object is detected it increments a limitcounter to filter out false readings.
And when the detector doesn't detect it checks the limitcounter against your set limit and if it was a positive reading COUNT increments by one. and the limitcounter is reset
If it wasnt enough to pass the limit test. limitcounter is reset to begin the next check.
limit needs to be set based on speed / experimentation.

Post Edited (Campeck) : 1/25/2010 6:22:03 PM GMT

erco
01-25-2010, 11:28 PM
for b0=1 to 200' start loop counting up to 200 events (adjustable)
a:if in0=0 then a' sensor on pin0, normally low, triggered=high
debug "count=",dec b0, cr' debug output
pause 1000' optional, wait 1 sec to prevent double triggers (adjustable)
next' end loop

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"If you build it, they will come."