Line following sensor
vla7
Posts: 79
I just bought the the QRB1134, it consists of an infrared emitting diode and a NPN silicon phototransistor mounted side by side.· Has anyone ever used this thing on the boe-bot and if so would you be able to help me write a program to get it to distinguish between a black and white surface?
I've attached the data sheet.
Vla
I've attached the data sheet.
Vla
pdf
48K
Comments
There's a line follower kit for the BotBot that uses a similar sensor that includes some additional parts that you can add to your sensor yourself (www.parallax.com/Store/Robots/RoboticAccessories/tabid/145/CategoryID/3/List/0/SortField/0/Level/a/ProductID/77/Default.aspx).Have a look at the documentation and sample programs. Some of the sample programs don't need all the extra parts. A 470 Ohm current limiting resistor for the LED and a 10K pullup for the phototransistor are the minimum additional parts that you would need.
Post Edited (Mike Green) : 9/29/2008 4:40:06 AM GMT
I was able to wire the sensor and get a reading of 1 or 0 between white and black surfaces. I now want to be able to use the sensor as a counter. For example, to be able to move it across 7 repeating black and white lines and have it return the number 7 as sort of a position holder. I have a basic idea of the concept to get it to work but can you please guide me through the pbasic code.
One more question. How do you calculate that I need a 470 Ohm current limiting resistor for the LED on the sensor?
Here is an LED calculator you can use if you find that suitable:
http://ledcalculator.net/
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When all else fails, try inserting a new battery.
Pin = I/O pin that I use
Duration = lengh of time that I want a count in milliseconds
Variable = where the count will be stored
So if I set duration for 5000 and move my sensor back and forth from a white surface to black back to white 7 times within the 10 seconds, then I should have a value of 7 stored in variable.
This is my test program. I'm using input pin 1
cycles Var Word
COUNT 1, 5000, file
DEBUG CRSRXY, 0, 3,
"Cycles " , DEC cycles
I keep getting a very high number for cycles. For example I'll go through three cycles and get a number like 19.
Help.
The advantages of using multiple Basic statements (like IF/GOTO) and multiple states is that this is slower. Instead of counting pulses as short as a couple of microseconds, the multiple statements take several hundred microseconds on a BS2 to execute avoiding this "false" triggering.
' {$STAMP BS2}
' {$PBASIC 2.5}
cycle VAR Word
DO
checkone:
DEBUG HOME, BIN1 IN1
IF IN1=1 THEN
GOTO checktwo
ELSE
GOTO checkone
checktwo:
DEBUG HOME, BIN1 IN1
IF IN1=0 THEN
GOTO checkthree
ELSE
GOTO checktwo
checkthree:
DEBUG HOME, BIN1 IN1
IF IN1 = 1 THEN
cycle = cycle + 1
ELSE
GOTO checkthree
ENDIF
ENDIF
DEBUG CRSRXY, 3,2, "Cycle is ", DEC cycle
ENDIF
LOOP
DEBUG statements take time to execute. At least 2 or 3 characters have to be sent and they
take about 1ms each to send. Try commenting out or removing the checkone/checktwo/checkthree
DEBUG statements and see what happens.
You can leave out the ELSE statements in checkone/checktwo/checkthree. You can also combine the
IF and GOTO statement that follows it and leave out the ENDIF statements. In checkthree, you can
similarly combine the IF and cycle = cycle + 1. Look in the Basic manual for examples.
do
do while in1 = 0 ' wait until in1 is one
loop
cycle = cycle+1
do while in1=1 ' hold here until in1 goes back to 0 before proceeding
loop
loop ' go back and wait for in1 =1 again
Post Edited (GICU812) : 10/3/2008 3:21:41 PM GMT