Now it is time to test the QTI sensors.
- In your BlocklyProp account, create a new project.
- Build the block of code shown below. It fetches the output state of each sensor with a "QTIs" function, then displays the results in the Terminal.
- Then, build the QTIs function shown below. (This function will also be used for line-following later.)
The white paper will reflect infrared light, while the black line will absorb it. Each QTI sensor emits infrared light, then looks for a reflection. When a QTI sensor is over a black line, it will return a "1" and when it is over a white surface, it will return a "0."
- Position your robot over the black line on your track. The QTI sensors directly over the line should return a 1, and those over a white area should return a 0.
- Move the robot around slightly to test each QTI sensor.
- If the sensors don't see the line, try the following adjustments:
- Double-check all of your wiring connections to make sure the sensors are properly connected to power, ground, and each I/O pin.
- Try replacing the jumper wire connecting to 5 V with a 220 ohm resistor. This makes the QTIs less bright, which might be overwhelming with a shiny line or shiny paper.
- Try removing the Nylon spacers from one of the sensor's posts. If this improves performance, remove it from the rest of the posts.
How the QTIs Function Works
The QTIs function starts by setting the I/O pin states for all four QTI sensors to HIGH, with the direction OUT. This causes each QTI sensor to turn on its infrared LED. The pulse-out PIN 26 pulse length µs 230 block keeps the LEDs on for just a 230 microsecond flash. (We could not use the pause block here, because its shortest duration is 1 millisecond, which is 1000 microseconds).
After that, the I/O pin directions are set to IN (input) for another 230 microseconds. Each QTI sensor is looking for its infrared flash's reflection, and reports I/O pin as a zero if the reflection is seen and a 1 if it is not.
Then, the states of the four I/O pins are saved in the item variable as a four-digit binary number. So, each time through the drive routine's loop, the QTIs function updates the item variable before it gets used for navigation with the switch...case block.