IR Detectors
Erikgunit
Posts: 4
Hi all. So i am trying to time objects as they pass through a set of IR detectors. Basically i want to keep track of the time it takes from the tripping of the first to the tripping of the last sensor similar to the speed sensors used for bullets and archery. Follow me so far?
So by dividing the distance by time, i will get velocity. cool. I am connecting a the IR emitter from V+ to ground through a 330 resistor and that points to a detector that is connected to V+ through a 20k resistor and is pulled low when the detector detects. it works, at least with one IR pair. And the detector and emitter have to bee within about an inch and i know i should have more distance...
I am using an if then statement to light an led when the beam is broken, and it works pretty well by response time is not that quick and if i move my hand too fast it wont see it. How can i get the precision closer, so that i dont have to worry about speed? If that question makes sense lol. Also I just dont see the IF THen statement to be robust enough to handle three IR pairs. Do i have other options then using IF THEN?
Thanks for your help guys.
So by dividing the distance by time, i will get velocity. cool. I am connecting a the IR emitter from V+ to ground through a 330 resistor and that points to a detector that is connected to V+ through a 20k resistor and is pulled low when the detector detects. it works, at least with one IR pair. And the detector and emitter have to bee within about an inch and i know i should have more distance...
I am using an if then statement to light an led when the beam is broken, and it works pretty well by response time is not that quick and if i move my hand too fast it wont see it. How can i get the precision closer, so that i dont have to worry about speed? If that question makes sense lol. Also I just dont see the IF THen statement to be robust enough to handle three IR pairs. Do i have other options then using IF THEN?
Thanks for your help guys.
Comments
Leon
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM
I think the goal of your project is understandable.
Im not at my workstation currently so i cant get the code there but ill put what i can remember from last night.
Basically we have a simple If then
Label
IF Right_IR = 0 then unbroken
····· Else High 15 *lights the led telling me that the beam is broken*
····· Debug "Beam is broken."
····· pause 50
····· low 15
Goto Label
:unbroken
Debug "The Beam is unbroken"
goto label
This code works fairly well but when i tried to modify to add more IR pairs i ran into an issue of them not getting a chance to even detect. (If that makes sense.)
I added Elseif statements when i tried to add the other pairs but i think that it was something like this:
Label
IF Right_IR = 0 then unbroken
····· High 15 *lights the led telling me that the beam is broken*
····· Debug "Beam is broken."
····· pause 50
····· low 15
elseif Middle_IR = 0 then unbroken
····· Else High·13 *lights the led telling me that the beam is broken*
····· Debug "Beam is broken."
····· pause 50
····· low 13
ELSEIF·Left_IR = 0 then unbroken
····· Else High 11 *lights the led telling me that the beam is broken*
····· Debug "Beam is broken."
····· pause 50
····· low 11
Goto Label
:unbroken
Debug "The Beam is unbroken"
goto label
It is VERY rudimentary code i know. Thrown together in a few minutes based on what i had seen on line. any optimization and help you guys can give would be awesome.
Leon
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM
Now, if you want a little more "time" to show LEDs lit upon a detector change, you could remove the code for updating the LEDs right from the detector inputs, and add a bit of custom code to each state to set LEDs exactly how you want and set the counter to keep them that way for a bit. I will emphasize that using nibbles and bytes for reading inputs and setting outputs is a good way to keep things much shorter (e.g. quicker). The "capturing" of the IR detector pins is so that a change in input pin state in the middle of executing the loop won't throw things off -- ideally such a pin state change would still be "caught" at the top of the loop on the next cycle.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
Another quick question, can the BS2 supply enough current for such a system or would an external supply be better? I am going to assume that it is not but we will see.
well wish me luck, ill be building and testing tonight. Soon!!
Re: current -- if you are talking about the Stamp's on-board regulator -- it's only good for 50ma or so, if memory serves. Not much. So if you are hooking up a bunch of 5v components you may need an external 5v supply (e.g. a beefier regulator and associated circuitry).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
Does this make sense though. i cant even power 4 leds with a high out put on each LEDs pin. The battery seems ok but i think it may be getting old. getting a new one.
Last question(for the night...er morning,.) the piece of code:
Can Allir VAR reference INA. I understand INA is the first 4 inputs but i though VAR had to be bit,nib,byte,word?
That and my IR detectors go low when the beam is broken· but i modded the code to fit. i am just not sure what to do with the LEDs not lighting up, at least all at once...
Thanks for your patience!
OUTD = %0001 ' pin 12 high, 13-15 low
OUTD = %1001 ' pin 12, 15 high, 13 & 14 low
etc. Using "OUTX = " only works if the pins are already outputs.
See the Pbasic manual for details about the input, output and dir registers. In my code example I'm just using AllIr as an "alias" to INA -- so I don't have to use INA or IND or whatever in the code. The reason? Makes it more readable AND if you change pins (where LEDs or detectors are hooked up) you don't have to change INA or OUTD or anything in all the places in main program -- just in once place at the top where the variable aliases are defined.
If your detectors go LOW when the beam is broken, that is unusual -- what detectors are you using?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php