Newbie needs help with QTR-8RC

Hi!

I’m about to make a line-following robot, but I can’t get my QTR-8RC sensor to work. I’ve read the datasheet but still don’t understand how it works.

So the sequence for reading the senors would be something like

  1. In/out line -output/high
  2. Wait a cpl of us
  3. I/0- input
  4. Measure time for the capacitor to discharge waiting for the I/O line to go low.

I do understand the first three steps, but the 4 gives me troubles…

I supose that the measured time depends on the surface the sensors is reading, and therefore the time it takes for the capacitor to discharge would indicate if the robot is in the correct position or not. But then what should I compare the time with the calibrated value or what?

Any help is appreciated.

Hello.

If you are writing the line-sensing code yourself, then yes, I’d recommend that you first run your robot through a calibration phase where you learn what the discharge time is for a white surface (ideally the floor of the actual line course) and what it is for a black surface (ideally the line itself). You can then use these two calibration points to “normalize” an arbitrary reading to a value between, for example, 0 and 1000, where 0 is the highest reflectance you expect to receive on that particular course and 1000 is the lowest reflectance you expect to see on that particular course. When your sensor is only partially over the line, you’ll get normalized values between 0 and 1000. Does this make sense?

If you’re using one of our Orangutan robot controllers, you can use the QTR portion of the Pololu AVR library instead of implementing the above algorithm yourself. It even has a function to convert the readings of all eight sensors into a single “line position” value on which can be used in a PID loop to keep your bot on the line. If you are using an AVR or some other microcontroller that can be programmed in C, you can use the source code from the library as a starting point for your own code.

- Ben

I’m writing the code and i’ve thought about the calibration part but at this point i have not any code for it.

And what you write makes senses. Might try someting similiar. At this point the robot is able to detect the line and so on but it’s a bit slow(at determine black/white), but hopefully some kind of calibration will do the trick. So I’ll try that, thanks alot for the tip.

One thing to note is that low reflectance will result in a slow capacitor discharge rate, which means that if you time how long it takes for the sensor output to go low while over a dark surface, your main loop will run slowly. A trick you can use is to stop waiting for the sensor output to go low and just classify the output as “black” after a certain amount of time has elapsed. Calibrating the sensors ahead of time can give you a good idea of what to set this timeout value to so that your main loop can run quickly while still letting you differentiate well between white and black.

- Ben

By the way, have you seen the QTR sensor app note that’s linked from the product page?

pololu.com/docs/0J13/1

- Ben

Oh I did notice that, while the sensors were over a plain white paper the discharge rate was just a cpl of us while a black surface was over 255us. And the trick you mention, it sounds good, will definitively try that out. Im using a atmega644 btw…

About the sensor app, I can’t even find it on that link? :stuck_out_tongue:

Well, if you’re using an AVR, you really might consider using the source code from the Pololu AVR library as a starting point for your own code.

The link I provided was the link to the app note (short for application note, not a PC application). It shows what the sensor output voltage looked like over time for a series of tests we performed.

- Ben

Ah okey:)

I’ve actually tried the source code but it did not work :confused: Suppose I did something strange that messed it up…Used this example https://www.pololu.com/docs/0J20/6.i but might try it again then.

Thanks!

The library code is written for the mega48/168/328, so you might need to make a few alterations before it works on the 644. It’s also mainly intended for processors running at 20 MHz, so you might need to make some changes if your MCU runs at a different frequency.

- Ben