User Manual
that depend on the type of sensor being used, with higher values corresponding to lower reflectance
(a black surface or a void). QTR-xA sensors will return a raw value between 0 and 1023. QTR-
xRC sensors will return a raw value between 0 and the timeout argument (in units of microseconds)
provided in the constructor (which defaults to 2500).
The functions that read values from the sensors all take an argument readMode, which specifies the
kind of read that will be performed. Several options are defined: QTR_EMITTERS_OFF specifies
that the reading should be made without turning on the infrared (IR) emitters, in which case the
reading represents ambient light levels near the sensor; QTR_EMITTERS_ON specifies that the
emitters should be turned on for the reading, which results in a measure of reflectance; and
QTR_EMITTERS_ON_AND_OFF specifies that a reading should be made in both the on and off
states. The values returned when the QTR_EMITTERS_ON_AND_OFF option is used are given by
on + max – off, where on is the reading with the emitters on, off is the reading with the emitters off,
and max is the maximum sensor reading. This option can reduce the amount of interference from
uneven ambient lighting. Note that emitter control will only work if you specify a valid emitter pin in
the constructor.
Dimmable QTR sensors with separate CTRL ODD and CTRL EVEN pins also support
QTR_EMITTERS_ODD_EVEN, where first the odd sensors are read with only the odd emitters
on, then the even sensors are read with only the even emitters on, as well as
QTR_EMITTERS_ODD_EVEN_AND_OFF, which works like a combination of ODD_EVEN and
ON_AND_OFF: the odd sensors are read with the odd emitters on, the even sensors are read with
the even emitters off, and all sensors are read with all emitters off. These two modes only work if
you specify separate odd and even emitter control pins in the constructor.
Alternatively, any QTR sensor can be read with QTR_EMITTERS_MANUAL instead. This causes
the read method to leave the emitters in their existing states instead of automatically turning them
on or off before and after each reading.
Example usage:
void emittersOn()
Turn the IR LEDs on. This is mainly for use by the read method, and calling these functions
before or after the reading the sensors will have no effect on the readings unless readMode is
QTR_EMITTERS_MANUAL, but you may wish to use these for testing purposes. This method will
only do something if the emitter pin specified in the constructor is not QTR_NO_EMITTER_PIN.
void emittersOn(unsigned char bank, bool wait = true)
Dimmable only: This version of emittersOn() turns on the emitters for the specified bank, which is
either QTR_BANK_ODD or QTR_BANK_EVEN. It will only work if you have specified separate odd
1
2
unsigned int sensor_values[8];
sensors.read(sensor_values);
?
Arduino Library for the Pololu QTR Reflectance Sensors © 2001–2018 Pololu Corporation
3. QTRSensors Methods & Usage Notes Page 7 of 15