Pololu QTR-8RC vs QTR-8A sensor array

Pololu QTR-8RC vs QTR-8A Sensor Array

Pololu offered, until recently two different eight sensor arrays, the QTR-8RC and the QTR-8A. The RC array uses an RC circuit and capacitor decay time to determine a reflectance amount whereas the A array uses a voltage divider to determine a reflectance amount. Within the past year pololu has released newer QTR-HD and QTR-MD sensors in all ranges of counts and sizes however, this article will not specifically cover these newer arrays. For the most part, the information in this article will hold true for the newer arrays as the general circuit remains the same with the exception of some newer features.

How to identify the two?

Because Pololu was able to design a schematic that would work for both arrays, I assume they print their boards in bulk with the generic name QTR-8 printed on them. It’s not until they actually put the components on them that they determine whether it is an Analog or Digital version. This can make it difficult to identify since you have to look at the components and it’s not easy to remember which components are for which board.

The easiest way to remember is that analog is going to use resistors while digital will use capacitors, the C in RC stands for capacitor. Without going into the nitty gritty, just look at the area identified in blue. Right in the middle of the board, if you see capacitors, you’ve got a digital or RC board and if you’ve got resistors then you’ve got an analog or A board.

In more detail, looking at the schematic you can see the analog removes the resistor from the output and replaces the capacitor with a 47K ohm resistor. When you look at the board there are two components that have been replaced in multiple places throughout the board (eight times… coincidence??), a capacitor and a resistor. The black 0 component is actually a trace, it simply provides a connection from one pad to another with no resistance so this is identifying in the schematic where they’ve removed the resistor from the output on the analog board. The brown component is a capacitor which is replaced with a black 473 component on the analog board. If you haven’t guessed already 473 translates to 47 with 3 zeros or 47,000 which is the 47K ohm resistor.

Again, the simplest way is to remember that capacitors are used in place of resistors on the RC and RC stands for Resistor Capacitor so if you look in the middle and see capacitors, it’s the RC board. Another fairly simple way is, if you see about an equal amount of capacitors as resistors you’ve got an RC board, RC boards have 15 resistors and 12 capacitors while Analog boards have 23 and only 4 capacitors.

qtr8x_schematic_comparison
Source: www.pololu.com
qtr8x_comparison
QTR-8x Comparison

QTR-8A

The analog sensors use a voltage divider fed into an analog to digital converter (ADC). This presents a few limitations as some boards only have a few ADC pins such as the Arduino Uno which only has 6 analog pins or the Arduino Nano which only has 8 analog pins. Another limitation is that your range of data is limited to the bit resolution of your ADC which on most Arduinos is 10 bits. This means you are limited to a range of 0 to 1023. Yet another limitation is that the analog array is read sequentially which means as your sensor count increases, so does the time to read them.

Notes

  • Requires an analog pin for each sensor
  • Resolution corresponds with the resolution of the analog to digital converter
  • Time to compute increases by a factor of 1 for each additional (1ms/sensor with 8 sensors == 8ms to compute)

QTR-8RC

The digital sensors work differently in that they have a capacitor which is charged by driving the pin high for 10 microseconds (µs) and then the amount of time it takes to discharge is translated into the reflectance. This means your range is theoretically as high as your TIMEOUT value. The TIMEOUT value is defaulted to 2500 so in theory, your range is 0 to 2500 which is over twice that of a 10 bit ADC. The digital array can read sensors in parallel, if you look at the code, what happens is it loops through the collection of sensors checking to see if each one has completely discharged. The beauty of this is that whether you have 4 sensors or 15 sensors, it should only ever take as long as TIMEOUT in microseconds. There are other factors involved here but for the most part this will remain true. However, the ugly of this is that it will always take at least TIMEOUT microseconds to read your sensors regardless of how many. So, if you have a timeout of 2500µs then it will take at least 2500µs to read your sensors which is a pretty significant difference over analog sensors as we’ll see in the “Real world comparison”.

Notes

  • Requires a digital pin for each sensor (digital pins are usually more common)
  • Resolution corresponds with the time for capacitor to decay or TIMEOUT, which one specifically will depend on your TIMEOUT time, sensor position, and/or the amount of ambient light.
  • Time to compute theoretically stays the same regardless of sensor count (TIMEOUT which is defaulted to 2500µs will be the min compute time). With a large number of sensors and/or a slower microcontroller, digital will outperform analog.

Real world comparison

I whipped up a program and a circuit that would run through a series of runs, taking 1000 readings in each situation and averaging them to determine the time to compute. I compared a Teensy 3.2 and Arduino Nano with both analog and digital sensors. To be clear, when running these tests, the digital TIMEOUT was set to the default of 2500µs and the Analog NUM_SAMPLES_PER_SENSOR was set to the default of 4, this means four readings were averaged for the analog sensor.

Data Table

If you prefer to look at raw data, here you go. As you can see, there isn’t much of a difference in the time to compute digital sensors between the two microcontrollers. The main difference we see here is the time to compute analog vs digital and the fact that analog is much faster on the Teensy 3.2 than it is on the Arduino Nano

Charts

If you prefer a graphical representation, check out these charts. It’s obvious that in most cases the analog is faster. The particular case when digital outperforms analog is with a slow microcontroller and a large number of sensors. The Arduino Nano benefits from the digital sensors if there are six or more sensors. The Teensy never even comes close, the trendline equation comes out to 28.9x+411 which means each sensor adds 28.9µs so to hit 3000µs you would need over 100 analog sensors.

Optimization Ideas

You might be asking yourself… why is zero sensors almost the same amount of time to compute as one sensor? I was asking the same thing so I dug into the code and it turns out that when you call read(), the library turns the emitters on (or off) before taking the reading and then turns them off after the reading. Each time the sensors are turned on or off adds an additional 202µs, this is why the trendline had an intercept of 411, this is the base time it would take to compute with zero sensors and 400 of that 411 is the total delay while turning emitters on and off.

I personally don’t ever use the emitter pin, I always send that pin straight to 5V to keep the emitters on at all times. If you don’t use an emitter pin, when you define your QTR array object, be sure to use QTR_NO_EMITTER_PIN (or 255) as the emitter pin argument. By stating that you aren’t using an emitter pin, the library will not execute the emittersOn() or emittersOff() functions thus saving you 400µs each time you read the sensors. This doesn’t affect the overall results of the two since both digital and analog go through this same code. However, this could bring your analog read from 436µs on the Teensy 3.2 down to roughly 30µs, that is quite the savings! Even on the digital you’re saving 400µs out of 2900µs so it’s still a significant portion at a 14% reduction in time.

One other optimization is to lower your TIMEOUT value, I sometimes lower mine all the way to 1000µs which lowers the range of values but if you know you can get accurate readings with a TIMEOUT of 1000, then you can save a lot of time. Changing the NUM_SAMPLES_PER_SENSOR doesn’t have much of an affect as it’s only going to save you about 5µs for each sample.

Conclusion

If you’re short on analog pins, opt for the digital and try dropping the TIMEOUT to 1000µs if you want to take a little less time to compute. Make sure you test this though as your environment plays a role in how low of a TIMEOUT you can go before seeing diminishing returns.

If you have a slow microcontroller like an Arduino Uno or Nano then you’ll probably want to use digital, especially if you drop the TIMEOUT, you can read all eight sensors in about 1000µs on a Nano which is the same time it takes to read two analog.

If you’ve got plenty of analog pins AND you are using a faster microcontroller (50MHz or more) then definitely opt for the analog sensors.

 

6 Comments

    1. Thanks for the feedback. I will definitely add that to my list. I’ve been interested in checking out the new sensors but at first glance I really don’t see much benefit.

      It seems they just added the benefit of better resolution (closer sensors with the HD versions) and the ability to control individual sensors.

      Anyway, before I go writing an article in this comment, thanks again for the feedback, I’ll be sure to get around to comparing the new sensors soon.

    1. Sure, if you use the “Contact Me” link on the right sidebar with your email and I can help you out over email.

      Aside from that though, my troubleshooting process would be as follows.

      1. Verify power to QTR board
      2. Verify LEDs are emitting
      3. Verify correct pin mapping
      4. Verify correct code setup
    1. Hey Riki, I do not have a program for checking the sensor but that’s because I just use the example from the library. There are four examples, two for digital (RC) and two for analog (A). One shows the raw values and the other shows calibrated values so you can test out calibration.

      If you’re just testing the sensor I’d say just go with the raw values example since it will avoid the possibility of an error occurring because of the calibration.

      I do have this article which includes a video showing you how to use a camera to check if they’re powered on. This one uses QTR-8A sensors so you won’t be able to use the code from the example http://robotresearchlab.com/2019/03/18/how-to-hookup-and-program-a-qtr-8-sensor-array/
      Let me know if you still need help, thanks for checking out my article.

Leave a Reply

Your email address will not be published. Required fields are marked *