Arduino Library for the Pololu QTR Reflectance Sensors © 2001–2018 Pololu Corporation Arduino Library for the Pololu QTR Reflectance Sensors 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 2. Library Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 3. QTRSensors Methods & Usage Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 https://www.pololu.
Arduino Library for the Pololu QTR Reflectance Sensors © 2001–2018 Pololu Corporation 1. Introduction QTR sensor size comparison. Top row: QTRX-HD-07, QTR-HD-07; middle row: QTR-3, QTR-1, QTR-L-1; bottom row: QTR-8. The Pololu QTR reflectance sensors carry infrared LED and phototransistor pairs that can provide analog measurements of IR reflectance, which makes them great for close-proximity edge detection and line-following applications.
Arduino Library for the Pololu QTR Reflectance Sensors QTR-L-1A reflectance sensor schematic diagram. © 2001–2018 Pololu Corporation QTR-1A reflectance sensor schematic diagram. QTR-1RC and QTR-L-1RC reflectance sensor schematic diagram. Please see the product pages [https://www.pololu.com/category/123/pololu-qtr-reflectance-sensors] for more information on how these sensors work.
Arduino Library for the Pololu QTR Reflectance Sensors © 2001–2018 Pololu Corporation 2. Library Installation If you are using version 1.6.2 or later of the Arduino software [https://www.arduino.cc/en/Main/Software], you can use the Library Manager to install this library: In the Arduino IDE, open the “Sketch” menu, select “Include Library”, then “Manage Libraries…”. 1. Search for “QTRSensors”. 2. Click the QTRSensors entry in the list. 3. Click “Install”.
Arduino Library for the Pololu QTR Reflectance Sensors © 2001–2018 Pololu Corporation The only other difference you might experience is in the time it takes to read the sensor values. The QTR-xRC sensors can all be read in parallel, but each requires the timing of a pulse that might take as long as 3 ms (you can specify how long the library should time this pulse before timing out and declaring the result full black).
Arduino Library for the Pololu QTR Reflectance Sensors © 2001–2018 Pololu Corporation 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.
Arduino Library for the Pololu QTR Reflectance Sensors © 2001–2018 Pololu Corporation 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. QTRxRC sensors will return a raw value between 0 and the timeout argument (in units of microseconds) provided in the constructor (which defaults to 2500).
Arduino Library for the Pololu QTR Reflectance Sensors © 2001–2018 Pololu Corporation and even emitter pins. If wait is false, the function will return immediately instead of waiting until the emitters actually turn on. void emittersOff() Turn the IR LEDs off. 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 the readMode is QTR_EMITTERS_MANUAL, but you may wish to use these for testing purposes.
Arduino Library for the Pololu QTR Reflectance Sensors © 2001–2018 Pololu Corporation reading that is less than or equal to the minimum value read by calibrate() and 1000 corresponds to a reading that is greater than or equal to the maximum value. Calibration values are stored separately for each sensor, so that differences in the sensors are accounted for automatically.
Arduino Library for the Pololu QTR Reflectance Sensors © 2001–2018 Pololu Corporation The destructor for the QTRSensors class frees up memory allocated for the calibration arrays. Constructor: QTRSensorsRC() This version of the constructor performs no initialization. If it is used, the user must call init() before using the methods in this class.
Arduino Library for the Pololu QTR Reflectance Sensors © 2001–2018 Pololu Corporation The array pins should contain the Arduino analog input pin number for each sensor. For example, if pins is {0, 1, 7}, sensor 1 is on analog input 0, sensor 2 is on analog input 1, and sensor 3 is on analog input 7. numSensors specifies the length of the analogPins array (the number of QTR-A sensors you are using). numSensors must be no greater than 16.
Arduino Library for the Pololu QTR Reflectance Sensors © 2001–2018 Pololu Corporation using the methods in this class. Constructor: QTRDimmableAnalog(unsigned char* digitalPins, unsigned char numSensors, unsigned char numSamplesPerSensor = 4, unsigned char emitterPin = QTR_NO_EMITTER_PIN) This constructor just calls init(), below, with one emitter pin for controlling one bank (or both banks combined).
Arduino Library for the Pololu QTR Reflectance Sensors 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 © 2001–2018 Pololu Corporation ? #include
Arduino Library for the Pololu QTR Reflectance Sensors © 2001–2018 Pololu Corporation A sample routine to obtain the sensor values and perform rudimentary line following would be: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 void loop() { unsigned int sensors[3]; // get calibrated sensor values returned in the sensors array, along with the line // position, which will range from 0 to 2000, with 1000 corresponding to the line // over the middle sensor.
Arduino Library for the Pololu QTR Reflectance Sensors 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 © 2001–2018 Pololu Corporation ? int lastError = 0; void loop() { unsigned int sensors[3]; // get calibrated sensor values returned in the sensors array, along with the line // position, which will range from 0 to 2000, with 1000 corresponding to the line over // the middle sensor int position = qtr.