Help QTR-8RC

I got trouble using this sensor, can i get an example C program ? i’m using my own microcontroller board, and i still confused with this “Measure the time for the capacitor to discharge by waiting for the I/O line to go low”…thx


The program you write will depend completely on the microcontroller you are using, but it will be something like:

int readSensor()
  sensor_pin = OUTPUT;  // make sensor pin an output
  sensor_pin = HIGH;  // drive sensor pin high
  delay_us(10);  // wait for 10 us
  sensor_pin = INPUT;  // make sensor pin a HIGH-IMPEDANCE input
  startTimer();  // start timing (e.g. clear the timer counter)
  while (sensor_pin == HIGH && timerCounter < TIMEOUT)  // loop while sensor pin is high
  return timerCounter;

The above pseudocode reads a single QTR-RC sensor. You will probably want to do something more complicated to read all 8 sensors simultaneously. Take a look at our QTR sensor source code in the Pololu AVR library for C code that works on an AVR. You will need to modify it for your particular microcontroller, but it should give you a good starting point.

- Ben