Shop OBEX P1 Docs P2 Docs Learn Events
QTI sensors with Arduino Mega — Parallax Forums

QTI sensors with Arduino Mega

kllowkllow Posts: 1
edited 2012-02-22 10:33 in Accessories
Hi there,

I have just bought 6 pcs of QTI sensors to be used with Arduino Mega for follow 3M reflective line.

I have tried the code provided by Parallex but unfortunately it does not work. As I am new in programming, I would appreciate if somebody can give me advise on the coding for QTI sensors to be used together with Arduino Mega.

Thank you in advance.

cheers,
kl

Comments

  • FranklinFranklin Posts: 4,747
    edited 2012-02-22 08:52
    code provided by Parallex but unfortunately it does not work
    Could you attach your code and tell us what "does not work"
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2012-02-22 10:33
    Yes, you need to provide more info than "does not work."

    In the meantime, this is demonstration code for testing one QTI. You'd effectively do this six times, on six different Arduino pins, and collect the data in some way to make the sensor comparison meaningful.
    void setup() {
      Serial.begin(9600);
    }
    
    void loop() {
      Serial.println(RCTime(2));        // Connect to pin 2, display results
      delay(250);                // Wait 250ms
    }
    
    long RCTime(int sensorIn){
       long duration = 0;
       pinMode(sensorIn, OUTPUT);     // Make pin OUTPUT
       digitalWrite(sensorIn, HIGH);  // Pin HIGH (discharge capacitor)
       delay(1);                      // Wait 1ms
       pinMode(sensorIn, INPUT);      // Make pin INPUT
       digitalWrite(sensorIn, LOW);   // Turn off internal pullups
       while(digitalRead(sensorIn)){  // Wait for pin to go LOW
          duration++;
       }
       return duration;
    } 
    
    //'W - +5
    //'B - Gnd
    //'R - Signal
    
    //Values are from about 55-1300
    

    -- Gordon
Sign In or Register to comment.