User Manual
3. QTRSensors Methods & Usage Notes
QTRSensors Command Reference
Previous versions of this library were named PololuQTRSensors, but we have changed
it to QTRSensors to differentiate it from the QTR sensor library in our Arduino Libraries
for the Orangutan and 3pi Robot [https://www.pololu.com/docs/0J17].
This documentation is for version 3.1.0 of the QTRSensors library. Older versions of the
library do not support the dimmable QTR and QTRX sensors.
This library defines a class for each of the QTR sensor types, and it takes care of the differences
between the analog and RC sensors internally, providing you with a common interface to all types.
For non-dimmable QTR-xA sensors, you will want to instantiate a QTRSensorsAnalog object, and for
non-dimmable QTR-xRC sensors. you will want to instantiate a QTRSensorsRC object. Aside from
the constructors, these two objects provide the same methods for reading sensor values (both classes
are derived from the same abstract base class). The library provides access to the raw sensors values
as well as to high level functions including calibration and line-tracking.
For dimmable QTR-xD-xA and QTRX-xD-xA sensors, you will want to instantiate a
QTRDimmableAnalog object, and for dimmable QTR-xD-xRC and QTRX-xD-xRC sensors. you will
want to instantiate a QTRDimmableRC object. These classes support changing the emitter dimming
levels and controlling the odd and even emitters separately on the dimmable sensors.
Each of these classes must be instantiated before they are used. This allows multiple QTR sensor
arrays to be controlled independently as separate objects.
For calibration, memory is allocated using the malloc() command. This conserves RAM: if eight
sensors are calibrated with the emitters both on an off, a total of 64 bytes would be dedicated to storing
calibration values. However, for an application where only three sensors are used, and the emitters
are always on during reads, only 6 bytes are required.
Internally, this library uses all standard Arduino functions such as micros() for timing and analogRead()
or digitalRead() for getting the sensor values, so it should work on all Arduinos without conflicting with
other libraries.
void read(unsigned int *sensorValues, unsigned char readMode = QTR_EMITTERS_ON)
Reads the raw sensor values into an array. There MUST be space for as many values as there were
sensors specified in the constructor. The values returned are a measure of the reflectance in units
Arduino Library for the Pololu QTR Reflectance Sensors © 2001–2018 Pololu Corporation
3. QTRSensors Methods & Usage Notes Page 6 of 15