Shop OBEX P1 Docs P2 Docs Learn Events
IR Counting — Parallax Forums

IR Counting

Austin S.Austin S. Posts: 5
edited 2010-01-25 15:28 in BASIC Stamp
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

Comments

  • FranklinFranklin Posts: 4,747
    edited 2010-01-25 01:55
    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
  • Mike2545Mike2545 Posts: 433
    edited 2010-01-25 02:16
    How fast do you need to be able to detect the "object" ?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Mike2545
  • ercoerco Posts: 20,256
    edited 2010-01-25 06:12
    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."
  • CampeckCampeck Posts: 111
    edited 2010-01-25 10:14
    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
  • ercoerco Posts: 20,256
    edited 2010-01-25 15:28
    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."
Sign In or Register to comment.