Encoder with QTR-1RC

Hello everyone,
I want to build an encoder that uses QTR-1RC. The problem is, Pololu’s QTR Arduino resource only include sample codes for 3 or more sensor packs. Can you help me to show how to initialize and read the QTR-1RC sensor data using Arduino. Thank you for your help.


Using one sensor isn’t really any different than using three or eight; just use an array of length 1 to hold your sensor pin and a numSensors value of 1:

#define SENSOR_PIN  2  // set this to the digital pin you want to use
PololuQTRSensorsRC qtr((char[]) {SENSOR_PIN}, 1, 2000);
unsigned int sensorValues[1];

void setup() { }
void loop()
  if (sensorValue[0] > 500)
    do something;

Once you have your system built, you should probably use setup() to calibrate your sensor and use the method readCalibrated() instead of read(); see the example sketches provided with the library for sample calibration code. You also might want to change the third constructor argument (the timeout value) to be something shorter than 2000 us because shorter values let you sample the sensor more often. I’m not sure what kind of update rate you’ll need for your encoder, but you can probably get by with 1000 us or maybe even less. You should be able to try it out and see what values work for you.

- Ben

Thany you for information, very appreciated.