User Manual
PololuQTRSensors::~PololuQTRSensors()
The destructor for the PololuQTRSensors class frees up memory allocated for the calibration arrays. This
feature is not available in C.
PololuQTRSensorsRC::PololuQTRSensorsRC()
This constructor performs no initialization. If it is used, the user must call init() before using the methods in
this class.
PololuQTRSensorsRC::PololuQTRSensorsRC(unsigned char* pins, unsigned char numSensors, unsigned
int timeout = 4000, unsigned char emitterPin = 255);
This constructor just calls init(), below.
void PololuQTRSensorsRC::init(unsigned char* pins, unsigned char numSensors , unsigned int timeout =
4000, unsigned char emitterPin = 255)
void qtr_rc_init(unsigned char* pins, unsigned char numSensors, unsigned int timeout, unsigned char
emitterPin)
Initializes a QTR-RC (digital) sensor array.
The array pins should contain the pin numbers for each sensor, defined using the IO_* keywords provided
by the library. For example, if pins is {IO_D3, IO_D6, IO_C1}, sensor 0 is on PD3, sensor 1 is on PD6, and
sensor 2 is on PC1.
For ATmegaxx8-based controllers, the pin numbers are Arduino-compatible so you can define the pins array
using Arduino pin numbers. For example, if pins is {3, 6, 15}, sensor 0 is on digital pin 3 or PD3, sensor 1 is
on digital pin 6 or PD6, and sensor 2 is on digital pin 15 or PC1 (Arduino analog input 1). Digital pins 0 – 7
correpsond to port D pins PD0 – PD7, respectively. Digital pins 8 – 13 correspond to port B pins PB0 – PB5.
Digital pins 14 – 19 correspond to port C pins PC0 – PC5, which are referred to in the Arduino environment
as analog inputs 0 – 5.
numSensors specifies the length of the ‘pins’ array (the number of QTR-RC sensors you are using).
numSensors must be no greater than 16.
timeout specifies the length of time in Timer2 counts beyond which you consider the sensor reading
completely black. That is to say, if the pulse length for a pin exceeds timeout, pulse timing will stop and
the reading for that pin will be considered full black. It is recommended that you set timeout to be between
1000 and 3000 us, depending on factors like the height of your sensors and ambient lighting. This allows
you to shorten the duration of a sensor-reading cycle while maintaining useful measurements of reflectance.
On a 16 MHz microcontroller, you can convert Timer2 counts to microseconds by dividing by 2 (2000 us
= 4000 Timer2 counts = timeout of 4000). On a 20 MHz microcontroller, you can convert Timer2 counts to
microseconds by dividing by 2.5 or multiplying by 0.4 (2000 us = 5000 Timer2 counts = timeout of 5000).
emitterPin is the Arduino digital pin that controls whether the IR LEDs are on or off. This pin is optional and
only exists on the 8A and 8RC QTR sensor arrays. If a valid pin is specified, the emitters will only be turned
on during a reading. If an invalid pin is specified (e.g. 255), the IR emitters will always be on.
PololuQTRSensorsAnalog::PololuQTRSensorsAnalog()
This constructor performs no initialization. If this constructor is used, the user must call init() before using the
methods in this class.
PololuQTRSensorsAnalog::PololuQTRSensorsAnalog(unsigned char* analogPins, unsigned char
numSensors, unsigned char numSamplesPerSensor = 4, unsigned char emitterPin = 255)
Pololu AVR Library Command Reference © 2001–2015 Pololu Corporation
16. QTR Reflectance Sensors Page 56 of 65