Pololu QTR-1RC Reflectance Sensor

19 Jun 2011

Hi

Does anybody have an idea of how to use the QTR-1RC Reflectance Sensor from Pololu with mbed ?

http://www.pololu.com/catalog/product/959

I would appreciate any help!

Thanks

08 Dec 2012

Try this code:

#include "mbed.h"

DigitalInOut QTRA(p6); //connected to digital P6
DigitalInOut QTRB(p5); //connected to digital P5

DigitalOut led1(LED1);
DigitalOut led4(LED4);

Timer t;

Serial pc(USBTX, USBRX); // tx, rx

int bw=0,aw=0,k;

int main()
{

    while(1) {

        QTRA.output();
        QTRA.mode(PullUp);
        wait_us(2500);
        QTRA.mode(PullNone);
        QTRA = 1;
        t.start();
        QTRA.input();
        while (QTRA == 1 || t.read_us() < 3000);
        bw = t.read_us();        
        t.stop();
        t.reset();
        
        QTRB.output();
        QTRB.mode(PullUp);
        wait_us(2500);
        QTRB.mode(PullNone);                
        QTRB = 1;
        t.start();
        QTRB.input();
        while (QTRB == 1 || t.read_us() < 3000);
        aw = t.read_us();        
        t.stop();
        t.reset();
        
        pc.printf("%d %d\n",bw,aw); 
        
        if (bw > 3100) { led1 = 1; } else { led1=0; } // Black
        if (aw > 3100) { led4 = 1; } else { led4=0; } // Black
       
       
    }
}